Skip to content

Commit

Permalink
ui: url state handling
Browse files Browse the repository at this point in the history
  • Loading branch information
traines-source committed Jan 18, 2025
1 parent a97cd0c commit 636154f
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 87 deletions.
46 changes: 11 additions & 35 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"dev": "vite dev --host 0.0.0.0 --port 3000",
"build": "vite build",
"preview": "vite preview",
"test": "npm run test:integration && npm run test:unit",
Expand All @@ -18,7 +18,7 @@
"@hey-api/openapi-ts": "^0.53.11",
"@playwright/test": "^1.28.1",
"@sveltejs/adapter-static": "^3.0.5",
"@sveltejs/kit": "^2.7.2",
"@sveltejs/kit": "^2.12.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.6",
"@types/eslint": "^8.56.0",
"@types/polyline": "^0.1.32",
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@
display: flex;
flex-direction: column;
z-index: 3;
}
}
10 changes: 9 additions & 1 deletion ui/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
// See https://kit.svelte.dev/docs/types#app

import type { Itinerary } from '$lib/openapi';

// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
interface PageState {
selectedItinerary?: Itinerary;
selectedStop?: { name: string; stopId: string; time: Date };
stopArriveBy?: boolean;
tripId?: string;
}
// interface Platform {}
}
}
Expand Down
29 changes: 23 additions & 6 deletions ui/src/lib/ConnectionDetail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
{timestamp}
{scheduledTimestamp}
/>
<Time variant="realtime" class="font-semibold w-16" {isRealtime} {timestamp} {scheduledTimestamp} />
<Time
variant="realtime"
class="font-semibold w-16"
{isRealtime}
{timestamp}
{scheduledTimestamp}
/>
{#if stopId}
<Button
class="text-[length:inherit] leading-none justify-normal text-wrap text-left"
Expand Down Expand Up @@ -144,7 +150,9 @@
({formatDurationSec(l.duration)})
</span>
</summary>
<div class="mb-1 grid gap-y-1 grid-cols-[max-content_max-content_auto] items-center text-sm">
<div
class="mb-1 grid gap-y-1 grid-cols-[max-content_max-content_auto] items-center text-sm"
>
{#each l.intermediateStops! as s}
{@render stopTimes(s.arrival!, s.scheduledArrival!, l.realTime, s.name!, s.stopId)}
{/each}
Expand All @@ -153,7 +161,9 @@
{/if}

{#if !isLast && !(isLastPred && next!.duration === 0)}
<div class="grid gap-y-6 grid-cols-[max-content_max-content_auto] items-center pb-3 text-lg">
<div
class="grid gap-y-6 grid-cols-[max-content_max-content_auto] items-center pb-3 text-lg"
>
{@render stopTimes(
l.endTime!,
l.scheduledEndTime!,
Expand Down Expand Up @@ -183,16 +193,23 @@
</div>
{@render streetLeg(l)}
{#if !isLast}
<div class="grid gap-y-6 grid-cols-[max-content_max-content_auto] items-center pb-4 text-lg">
<div
class="grid gap-y-6 grid-cols-[max-content_max-content_auto] items-center pb-4 text-lg"
>
{@render stopTimes(l.endTime, l.scheduledEndTime, l.realTime, l.to.name, l.to.stopId)}
</div>
{/if}
</div>
{/if}
{/each}
<div class="relative pl-6 left-4">
<div class="absolute left-[-6px] top-[0px] w-[15px] h-[15px] rounded-full" style={routeColor(lastLeg!)}></div>
<div class="relative left-[4px] bottom-[7px] grid gap-y-6 grid-cols-[max-content_max-content_auto] items-center text-lg">
<div
class="absolute left-[-6px] top-[0px] w-[15px] h-[15px] rounded-full"
style={routeColor(lastLeg!)}
></div>
<div
class="relative left-[4px] bottom-[7px] grid gap-y-6 grid-cols-[max-content_max-content_auto] items-center text-lg"
>
{@render stopTimes(
lastLeg!.endTime,
lastLeg!.scheduledEndTime,
Expand Down
8 changes: 4 additions & 4 deletions ui/src/lib/ItineraryList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
routingResponses,
baseResponse,
baseQuery,
selectedItinerary = $bindable()
selectItinerary
}: {
routingResponses: Array<Promise<PlanResponse>>;
baseResponse: Promise<PlanResponse> | undefined;
baseQuery: PlanData | undefined;
selectedItinerary: Itinerary | undefined;
selectItinerary: (it: Itinerary) => void;
} = $props();
const throwOnError = (promise: RequestResult<PlanResponse, PlanError, false>) =>
Expand Down Expand Up @@ -65,7 +65,7 @@
<DirectConnection
{d}
onclick={() => {
selectedItinerary = d;
selectItinerary(d);
}}
/>
{/each}
Expand Down Expand Up @@ -105,7 +105,7 @@
{#each r.itineraries as it}
<button
onclick={() => {
selectedItinerary = it;
selectItinerary(it);
}}
>
<Card class="p-4">
Expand Down
2 changes: 1 addition & 1 deletion ui/src/lib/RailViz.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { Button } from '$lib/components/ui/button';
import Palette from 'lucide-svelte/icons/palette';
import Rss from 'lucide-svelte/icons/rss';
import { browser } from '$app/environment'
import { browser } from '$app/environment';
let {
map,
Expand Down
11 changes: 9 additions & 2 deletions ui/src/lib/StopTimes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
let {
stopId,
time: queryTime,
arriveBy = $bindable(),
stopNameFromResponse = $bindable(),
arriveBy,
setArriveBy,
onClickTrip
}: {
stopId: string;
time: Date;
arriveBy?: boolean;
stopNameFromResponse: string;
setArriveBy: (arriveBy: boolean) => void;
onClickTrip: (tripId: string) => void;
} = $props();
Expand All @@ -33,8 +37,11 @@
console.log(response.error);
throw new Error('HTTP ' + response.response?.status);
}
stopNameFromResponse =
(response.data?.stopTimes.length && response.data?.stopTimes[0].place?.name) || '';
return response.data!;
});
stop;
</script>

<div
Expand All @@ -45,7 +52,7 @@
class="font-bold"
variant="outline"
onclick={() => {
arriveBy = !arriveBy;
setArriveBy(!arriveBy);
}}
>
{#if arriveBy}
Expand Down
Loading

0 comments on commit 636154f

Please sign in to comment.