From 8acf7072c0392401f45e97dfc4e47d1e83b134a8 Mon Sep 17 00:00:00 2001 From: Hannah Purcell Date: Thu, 2 Jan 2025 13:02:28 -0500 Subject: [PATCH 1/2] fix: Channel name in broadcast for detours by route --- lib/skate/detours/detours.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/skate/detours/detours.ex b/lib/skate/detours/detours.ex index 7c097f05f..9582c97a1 100644 --- a/lib/skate/detours/detours.ex +++ b/lib/skate/detours/detours.ex @@ -274,7 +274,7 @@ defmodule Skate.Detours.Detours do Phoenix.PubSub.broadcast( Skate.PubSub, - "detours:active" <> route_id, + "detours:active:" <> route_id, {:detour_activated, db_detour_to_detour(detour)} ) @@ -290,7 +290,7 @@ defmodule Skate.Detours.Detours do Phoenix.PubSub.broadcast( Skate.PubSub, - "detours:active" <> route_id, + "detours:active:" <> route_id, {:detour_deactivated, db_detour_to_detour(detour)} ) From 4e9d9556f8da662ef27e9dcfcae498db4eeac238 Mon Sep 17 00:00:00 2001 From: Hannah Purcell Date: Thu, 2 Jan 2025 15:55:34 -0500 Subject: [PATCH 2/2] fix: need to parse backend data to frontend struct --- assets/src/hooks/useDetours.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/assets/src/hooks/useDetours.ts b/assets/src/hooks/useDetours.ts index 5812803d4..5e0f11dff 100644 --- a/assets/src/hooks/useDetours.ts +++ b/assets/src/hooks/useDetours.ts @@ -1,5 +1,5 @@ import { Channel, Socket } from "phoenix" -import { SimpleDetour } from "../models/detoursList" +import { SimpleDetour, SimpleDetourData, simpleDetourFromData } from "../models/detoursList" import { useEffect, useState } from "react" import { reload } from "../models/browser" import { userUuid } from "../util/userUuid" @@ -21,17 +21,17 @@ const subscribe = ( const channel = socket.channel(topic) handleDrafted && - channel.on("drafted", ({ data: data }) => handleDrafted(data)) + channel.on("drafted", ({ data: data }) => handleDrafted(simpleDetourFromData(data))) handleActivated && - channel.on("activated", ({ data: data }) => handleActivated(data)) + channel.on("activated", ({ data: data }) => handleActivated(simpleDetourFromData(data))) handleDeactivated && - channel.on("deactivated", ({ data: data }) => handleDeactivated(data)) + channel.on("deactivated", ({ data: data }) => handleDeactivated(simpleDetourFromData(data))) channel.on("auth_expired", reload) channel .join() - .receive("ok", ({ data: data }: { data: SimpleDetour[] }) => { - const detoursMap = Object.fromEntries(data.map((v) => [v.id, v])) + .receive("ok", ({ data: data }: { data: SimpleDetourData[] }) => { + const detoursMap = Object.fromEntries(data.map((v) => [v.id, simpleDetourFromData(v)])) initializeChannel(detoursMap) }) @@ -182,8 +182,8 @@ const subscribeByRoute = ( channel .join() - .receive("ok", ({ data: data }: { data: SimpleDetour[] }) => { - const detoursMap = Object.fromEntries(data.map((v) => [v.id, v])) + .receive("ok", ({ data: data }: { data: SimpleDetourData[] }) => { + const detoursMap = Object.fromEntries(data.map((v) => [v.id, simpleDetourFromData(v)])) setDetours((detoursByRouteId) => ({ ...detoursByRouteId, [routeId]: detoursMap,