Skip to content

Commit

Permalink
fix: need to parse backend data to frontend struct
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahpurcell committed Jan 2, 2025
1 parent 8acf707 commit 4e9d955
Showing 1 changed file with 8 additions and 8 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

0 comments on commit 4e9d955

Please sign in to comment.