Skip to content

Commit

Permalink
Merge branch 'hp/hook-for-loading-single-detour' into hp/detours-in-r…
Browse files Browse the repository at this point in the history
…oute-ladder-dropdown
  • Loading branch information
hannahpurcell committed Jan 3, 2025
2 parents 1fd7f32 + 31b72ae commit a7f7878
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions assets/src/hooks/useDetours.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)
})

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/skate/detours/detours.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
)

Expand All @@ -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)}
)

Expand Down

0 comments on commit a7f7878

Please sign in to comment.