diff --git a/src/lib/components/shipment-status.svelte b/src/lib/components/shipment-status.svelte index e85fb04..a63f292 100644 --- a/src/lib/components/shipment-status.svelte +++ b/src/lib/components/shipment-status.svelte @@ -2,13 +2,6 @@ export let id: string | undefined = undefined; export let status = ''; - if (id) { - const broadcaster = new BroadcastChannel(`shipment-${id}`); - broadcaster?.addEventListener('message', (event) => { - status = event.data; - }); - } - const inactiveStatuses = ['pending', 'unavailable', 'cancelled', 'failed']; const activeStatuses = ['booked', 'dispatched', 'delivered']; diff --git a/src/routes/shipments/[id]/+page.svelte b/src/routes/shipments/[id]/+page.svelte index 2c980bc..ec3db8c 100644 --- a/src/routes/shipments/[id]/+page.svelte +++ b/src/routes/shipments/[id]/+page.svelte @@ -11,6 +11,18 @@ $: { if (shipment?.id) { broadcaster = new BroadcastChannel(`shipment-${shipment.id}`); + + //note: the customer order page is polling for order status from the workflow + //itself since this courier shipping page is + //not the only source of workflow state changes + + //however to avoid polling on this this courier shipping page + //if multiple browser windows are open to the same shipping page + //we'd like those to be in sync, so will listen for events + //from a different browser window opened to the same shipping page + broadcaster?.addEventListener('message', (event) => { + status = event.data; + }); } }