Skip to content

Commit

Permalink
expose partOf
Browse files Browse the repository at this point in the history
  • Loading branch information
abrin committed Apr 3, 2024
1 parent 05b9e93 commit be99c73
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/canvas-panel/src/components/AtlasCanvas/AtlasCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,14 @@ export function AtlasCanvas({
})) as any[],
label: (ref as any).label,
};
choiceEventChannel.emit('onChoiceChange', { choice });

choiceEventChannel.emit('onChoiceChange', {
choice,
partOf: {
canvasId: canvas.id,
choiceId: body.id,
manifestId: manifest?.id,
},
});
}
}
// this returns 1 choice
Expand Down
9 changes: 8 additions & 1 deletion packages/canvas-panel/src/helpers/eventbus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ export const choiceEventChannel = eventbus<{
* @param payload - the id and options for the choice
*
*/
onChoiceChange: (payload: { choice?: ChoiceDescription }) => void;
onChoiceChange: (payload: {
choice?: ChoiceDescription;
partOf?: {
choiceId?: string;
canvasId?: string;
manifestId?: string;
};
}) => void;
/**
* When a canvas is changed, or a sequence is changed, this signals that
* the current set of choices should be reset
Expand Down
3 changes: 2 additions & 1 deletion packages/canvas-panel/src/hooks/use-generic-atlas-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function useGenericAtlasProps<T = Record<never, never>>(props: GenericAtl
seenChoices.current = {};
});

const onChoiceChange = (payload: { choice?: ChoiceDescription }) => {
const onChoiceChange = (payload: { choice?: ChoiceDescription, partOf?: any }) => {
const choice = payload.choice;
// sort the choices by ID in order to help with de-duping
if (webComponent?.current && choice && choice.items) {
Expand All @@ -181,6 +181,7 @@ export function useGenericAtlasProps<T = Record<never, never>>(props: GenericAtl
(seenChoices.current as any)[key] = value;
// move this outside the IF if we want to fire on every page

(choice as any).partOf = payload.partOf;
webComponent.current.dispatchEvent(new CustomEvent('choice', { detail: { choice } }));
}
};
Expand Down

0 comments on commit be99c73

Please sign in to comment.