Skip to content

Commit 8ad887c

Browse files
authored
feat: notify device of viewed routes (#225)
Call `setRouteViewed` athena method with the route ID when opening a route. TODO: - [x] don't try to call methods on devices not owned by the user (shared devices/public routes) - [x] DO call the method if user is a superuser Closes #221
1 parent 8bf745c commit 8ad887c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/api/athena.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export const uploadFilesToUrls = (dongleId: string, files: UploadFile[]) =>
3131
})),
3232
}, Math.floor(Date.now() / 1000) + EXPIRES_IN_SECONDS)
3333

34+
export const setRouteViewed = (dongleId: string, route: string) =>
35+
makeAthenaCall<{ route: string }, void>(dongleId, 'setRouteViewed', { route })
36+
3437
export const makeAthenaCall = async <REQ, RES>(dongleId: string, method: string, params?: REQ, expiry?: number): Promise<AthenaCallResponse<RES>> => {
3538
const res = await fetcher<BackendAthenaCallResponse<RES> | BackendAthenaCallResponseError>(`/${dongleId}`, {
3639
method: 'POST',

src/pages/dashboard/activities/RouteActivity.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import {
2-
createResource,
3-
createSignal,
4-
lazy,
5-
Suspense,
6-
type VoidComponent,
7-
} from 'solid-js'
1+
import { createResource, createSignal, lazy, Suspense, type VoidComponent } from 'solid-js'
82

3+
import { setRouteViewed } from '~/api/athena'
4+
import { getDevice } from '~/api/devices'
5+
import { getProfile } from '~/api/profile'
96
import { getRoute } from '~/api/route'
107
import { dayjs } from '~/utils/format'
118

@@ -38,6 +35,13 @@ const RouteActivity: VoidComponent<RouteActivityProps> = (props) => {
3835
if (video) video.currentTime = newTime
3936
}
4037

38+
const [device] = createResource(() => props.dongleId, getDevice)
39+
const [profile] = createResource(getProfile)
40+
createResource(() => [device(), profile(), props.dateStr] as const, async ([device, profile, dateStr]) => {
41+
if (!device || !profile || (!device.is_owner && !profile.superuser)) return
42+
await setRouteViewed(device.dongle_id, dateStr)
43+
})
44+
4145
return (
4246
<>
4347
<TopAppBar leading={<IconButton class="md:hidden" href={`/${props.dongleId}`}>arrow_back</IconButton>}>

0 commit comments

Comments
 (0)