Add webapp subproject (Vite + TypeScript + Web Components)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
67
webapp/src/api.ts
Normal file
67
webapp/src/api.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
export interface DaySummary {
|
||||
date: string
|
||||
count: number
|
||||
first_ts?: string
|
||||
last_ts?: string
|
||||
}
|
||||
|
||||
export interface Trackpoint {
|
||||
event_id: string
|
||||
device_id: string
|
||||
trip_id: string
|
||||
timestamp: string
|
||||
lat: number
|
||||
lon: number
|
||||
source: 'gps' | 'manual'
|
||||
note?: string
|
||||
}
|
||||
|
||||
export interface Stop {
|
||||
stop_id: string
|
||||
device_id: string
|
||||
trip_id: string
|
||||
start_ts: string
|
||||
end_ts: string
|
||||
center_lat: number
|
||||
center_lon: number
|
||||
duration_s: number
|
||||
place_label?: string
|
||||
}
|
||||
|
||||
export interface Suggestion {
|
||||
suggestion_id: string
|
||||
stop_id: string
|
||||
type: 'highlight' | 'name_place' | 'add_note'
|
||||
title: string
|
||||
text: string
|
||||
created_at: string
|
||||
dismissed_at?: string
|
||||
}
|
||||
|
||||
async function get<T>(path: string): Promise<T> {
|
||||
const res = await fetch(path, { credentials: 'include' })
|
||||
if (res.status === 401) {
|
||||
window.location.href = '/login'
|
||||
throw new Error('unauthenticated')
|
||||
}
|
||||
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
|
||||
return res.json() as Promise<T>
|
||||
}
|
||||
|
||||
export const api = {
|
||||
getDays(from?: string, to?: string): Promise<DaySummary[]> {
|
||||
const params = new URLSearchParams()
|
||||
if (from) params.set('from', from)
|
||||
if (to) params.set('to', to)
|
||||
return get<DaySummary[]>(`/v1/days?${params}`)
|
||||
},
|
||||
getTrackpoints(date: string): Promise<Trackpoint[]> {
|
||||
return get<Trackpoint[]>(`/v1/trackpoints?date=${date}`)
|
||||
},
|
||||
getStops(date: string): Promise<Stop[]> {
|
||||
return get<Stop[]>(`/v1/stops?date=${date}`)
|
||||
},
|
||||
getSuggestions(date: string): Promise<Suggestion[]> {
|
||||
return get<Suggestion[]>(`/v1/suggestions?date=${date}`)
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user