Skip to content

Commit

Permalink
Accept context info and log it in console
Browse files Browse the repository at this point in the history
  • Loading branch information
RedwanPlague committed Feb 5, 2024
1 parent 15e0df5 commit 9169a28
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
12 changes: 11 additions & 1 deletion helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export type Config = {
shade?: string;
};

export type Context = {
taskId: string;
contentGuid: string;
};

export type HostMessage =
| { type: "connected" }
| {
Expand All @@ -18,16 +23,21 @@ export type HostMessage =
| {
type: "mode";
data: Mode;
}
| {
type: "field-context";
data: Context;
};

export type ComponentMessage =
| { type: "connect" }
| { type: "get:field-value" }
| { type: "get:field-config" }
| { type: "get:field-context" }
| {
type: "set:field-value";
data: { color: Color } | undefined;
}
| { type: "get:mode" }
| { type: "set:mode"; data: Mode}
| { type: "set:mode"; data: Mode }
| { type: "set:style"; data: { height: string } };
6 changes: 6 additions & 0 deletions pages/component/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function Component() {
case "connected": {
hostChannel.sendMessage({ type: "get:field-value" });
hostChannel.sendMessage({ type: "get:field-config" });
hostChannel.sendMessage({ type: "get:field-context" });
hostChannel.sendMessage({
type: "set:style",
data: {
Expand All @@ -47,6 +48,11 @@ export default function Component() {
console.log("From edit component: The current mode is", message.data);
return;
}
case "field-context": {
const { taskId, contentGuid } = message.data;
console.log(`Task ID ${taskId} & Content GUID ${contentGuid}`);
return;
}
}
},
});
Expand Down
7 changes: 6 additions & 1 deletion pages/component/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const ColorSummary = dynamic(() => import("@/components/ColorSummary"), {
loading: () => <p>Loading...</p>,
});


export default function Component() {
const colorRef = useRef<HTMLDivElement>(null);
const [color, setColor] = useState<Color | undefined>();
Expand All @@ -19,6 +18,7 @@ export default function Component() {
case "connected": {
hostChannel.sendMessage({ type: "get:field-value" });
hostChannel.sendMessage({ type: "get:field-config" });
hostChannel.sendMessage({ type: "get:field-context" });
hostChannel.sendMessage({
type: "set:style",
data: {
Expand All @@ -42,6 +42,11 @@ export default function Component() {
console.log("From view component: The current mode is", message.data);
return;
}
case "field-context": {
const { taskId, contentGuid } = message.data;
console.log(`Task ID ${taskId} & Content GUID ${contentGuid}`);
return;
}
}
},
});
Expand Down

0 comments on commit 9169a28

Please sign in to comment.