Skip to content

Commit e942d55

Browse files
Merge pull request #197 from iqbalcodes6602/Get-rid-of-the-full-page-loading
fix: ensure loading spinner displays only when a trip is selected
2 parents 9734339 + 4c721b5 commit e942d55

File tree

2 files changed

+40
-50
lines changed

2 files changed

+40
-50
lines changed

src/components/stops/StopPane.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
<p>Loading...</p>
156156
{:else}
157157
<div>
158-
{#if loading && isLoading}
158+
{#if loading && isLoading && tripSelected}
159159
<LoadingSpinner />
160160
{/if}
161161

src/routes/stops/[stopID]/schedule/+page.svelte

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script>
22
import { page } from '$app/stores';
3-
import LoadingSpinner from '$components/LoadingSpinner.svelte';
43
import RouteScheduleTable from '$components/schedule-for-stop/RouteScheduleTable.svelte';
54
import StopPageHeader from '$components/stops/StopPageHeader.svelte';
65
import StandalonePage from '$components/StandalonePage.svelte';
@@ -9,7 +8,6 @@
98
import AccordionItem from '$components/containers/AccordionItem.svelte';
109
import { Datepicker } from 'flowbite-svelte';
1110
import { onMount } from 'svelte';
12-
import { isLoading } from 'svelte-i18n';
1311
import { t } from 'svelte-i18n';
1412
1513
let selectedDate = $state(new Date());
@@ -19,7 +17,6 @@
1917
let stopName = $state('');
2018
let stopId = $state('');
2119
let stopDirection = $state('');
22-
let loading = $state(true);
2320
let accordionComponent = $state();
2421
let allRoutesExpanded = $state(false);
2522
@@ -29,16 +26,13 @@
2926
3027
async function fetchScheduleForStop(stopId, date) {
3128
try {
32-
loading = true;
3329
emptySchedules = false;
3430
const response = await fetch(`/api/oba/schedule-for-stop/${stopId}?date=${date}`);
3531
if (!response.ok) throw new Error('Failed to fetch schedule for stop');
3632
const scheduleForStop = await response.json();
3733
handleScheduleForStopResponse(scheduleForStop.data);
3834
} catch (error) {
3935
console.error('Error fetching schedules:', error);
40-
} finally {
41-
loading = false;
4236
}
4337
}
4438
@@ -140,52 +134,48 @@
140134
</svelte:head>
141135
142136
<StandalonePage>
143-
{#if loading || $isLoading}
144-
<LoadingSpinner />
145-
{:else}
146-
<StopPageHeader {stopName} {stopId} {stopDirection} />
147-
148-
<div class="flex flex-col">
149-
<div class="flex flex-1 flex-col">
150-
<h2 class="mb-4 text-2xl font-bold text-gray-800">
151-
{$t('schedule_for_stop.route_schedules')}
152-
</h2>
153-
154-
<div class="mb-4 flex gap-4">
155-
<div class="z-20 min-w-32 md:w-[30%]">
156-
<Datepicker bind:value={selectedDate} inputClass="w-96" />
157-
</div>
158-
159-
<div class="flex-1 text-right">
160-
<button class="button" onclick={toggleAllRoutes}>
161-
{allRoutesExpanded
162-
? $t('schedule_for_stop.collapse_all_routes')
163-
: $t('schedule_for_stop.show_all_routes')}
164-
</button>
165-
</div>
137+
<StopPageHeader {stopName} {stopId} {stopDirection} />
138+
139+
<div class="flex flex-col">
140+
<div class="flex flex-1 flex-col">
141+
<h2 class="mb-4 text-2xl font-bold text-gray-800">
142+
{$t('schedule_for_stop.route_schedules')}
143+
</h2>
144+
145+
<div class="mb-4 flex gap-4">
146+
<div class="z-20 min-w-32 md:w-[30%]">
147+
<Datepicker bind:value={selectedDate} inputClass="w-96" />
166148
</div>
167149
168-
<div
169-
class="flex-1 rounded-lg border border-gray-200 bg-white p-2 dark:border-gray-700 dark:bg-black"
170-
>
171-
{#if emptySchedules}
172-
<p class="text-center text-gray-700 dark:text-gray-400">
173-
{$t('schedule_for_stop.no_schedules_available')}
174-
</p>
175-
{:else}
176-
<Accordion bind:this={accordionComponent}>
177-
{#each schedules as schedule}
178-
<AccordionItem>
179-
{#snippet header()}
180-
<span>{schedule.tripHeadsign}</span>
181-
{/snippet}
182-
<RouteScheduleTable {schedule} />
183-
</AccordionItem>
184-
{/each}
185-
</Accordion>
186-
{/if}
150+
<div class="flex-1 text-right">
151+
<button class="button" onclick={toggleAllRoutes}>
152+
{allRoutesExpanded
153+
? $t('schedule_for_stop.collapse_all_routes')
154+
: $t('schedule_for_stop.show_all_routes')}
155+
</button>
187156
</div>
188157
</div>
158+
159+
<div
160+
class="flex-1 rounded-lg border border-gray-200 bg-white p-2 dark:border-gray-700 dark:bg-black"
161+
>
162+
{#if emptySchedules}
163+
<p class="text-center text-gray-700 dark:text-gray-400">
164+
{$t('schedule_for_stop.no_schedules_available')}
165+
</p>
166+
{:else}
167+
<Accordion bind:this={accordionComponent}>
168+
{#each schedules as schedule}
169+
<AccordionItem>
170+
{#snippet header()}
171+
<span>{schedule.tripHeadsign}</span>
172+
{/snippet}
173+
<RouteScheduleTable {schedule} />
174+
</AccordionItem>
175+
{/each}
176+
</Accordion>
177+
{/if}
178+
</div>
189179
</div>
190-
{/if}
180+
</div>
191181
</StandalonePage>

0 commit comments

Comments
 (0)