-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/schedule-visualization #127
Merged
+538
−22
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
6097065
feat: add link to view schedule in StopPane component
Ahmedhossamdev a537249
feat: add server-side loading for stop schedule
Ahmedhossamdev 1d4be0b
feat: Add stop-for-schedule api
Ahmedhossamdev 0bbe23d
feat: remove schedule loading for stop
Ahmedhossamdev ae45ba4
feat: add function to convert Unix timestamp to local time
Ahmedhossamdev bfb601d
refactor: Moved the formatTime to formatter.js
Ahmedhossamdev 5e8476f
feat: Initial page for visualizing schedules
Ahmedhossamdev d888168
refactor: remove console log from convertUnixToTime function
Ahmedhossamdev b3fc0b4
feat: update schedule page to use formatTime for arrival times
Ahmedhossamdev 63564ec
refactor: remove console log from groupStopTimesByHour function
Ahmedhossamdev 1113e72
feat: Add fetch new schedules when select new date & improve the ui
Ahmedhossamdev 52ac2d6
feat: Add schedule accordion component for displaying trip schedules
Ahmedhossamdev 1327317
feat: Refactor i18n setup to use async function for locale registration
Ahmedhossamdev 1874754
refactor: changed the file name
Ahmedhossamdev d2d4069
feat: Add StopDetailsHeader component for displaying stop information
Ahmedhossamdev ec7e9b4
feat: Integrate StopDetailsHeader component
Ahmedhossamdev 4f2ffb3
feat: Add conditional rendering for AM/PM schedule availability in sc…
Ahmedhossamdev 94b0965
feat: Update schedule fetching logic to handle date changes and initi…
Ahmedhossamdev 2385cb0
feat: Enhance scheduleAccordionItem with improved table structure and…
Ahmedhossamdev f1ead02
feat: Initialize current date for schedule fetching and update select…
Ahmedhossamdev 34425dc
feat: Update StopPane layout to position 'View Schedule' link at the …
Ahmedhossamdev 3aa23d7
feat: Update StopPane layout to use flexbox for positioning 'View Sch…
Ahmedhossamdev 8d45c2a
feat: Localize 'on time' status message
Ahmedhossamdev a20cc1f
feat: Add localized schedule messages for multiple languages
Ahmedhossamdev bda9446
feat: Remove scheduleAccordionItem component
Ahmedhossamdev c900c0f
refactor: Uppercase the first char (file-name)
Ahmedhossamdev abf5e02
feat: Localize StopDetailsHeader component text
Ahmedhossamdev 1ce8463
feat: Localize 'View Schedule' text in StopPane component
Ahmedhossamdev f837084
feat: Localize schedule-related text
Ahmedhossamdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import { onMount, onDestroy } from 'svelte'; | ||
import { faBus, faPersonWalking } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/svelte-fontawesome'; | ||
import { convertUnixToTime } from '$lib/formatters'; | ||
|
||
export let stop; | ||
export let tripId; | ||
|
@@ -14,13 +15,6 @@ | |
let interval; | ||
let busPosition = 0; | ||
|
||
function formatTime(seconds) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if (!seconds) return ''; | ||
const date = new Date(seconds * 1000); | ||
const utcDate = new Date(date.toUTCString().slice(0, -4)); | ||
return utcDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); | ||
} | ||
|
||
function calculateBusPosition() { | ||
if (tripDetails && tripDetails.status && tripDetails.status.position) { | ||
const { lat, lon } = tripDetails.status.position; | ||
|
@@ -118,7 +112,7 @@ | |
<div class="text-md font-semibold text-[#000000] dark:text-white"> | ||
{stopInfo[tripStop.stopId] ? stopInfo[tripStop.stopId].name : tripStop.stopId} | ||
</div> | ||
<div class="text-sm text-[#86858B]">{formatTime(tripStop.arrivalTime)}</div> | ||
<div class="text-sm text-[#86858B]">{convertUnixToTime(tripStop.arrivalTime)}</div> | ||
</div> | ||
</div> | ||
{/each} | ||
|
114 changes: 114 additions & 0 deletions
114
src/components/schedule-for-stop/ScheduleAccordionItem.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<script> | ||
import { createEventDispatcher } from 'svelte'; | ||
import { AccordionItem } from 'flowbite-svelte'; | ||
import { t } from 'svelte-i18n'; | ||
|
||
export let schedule; | ||
export let expanded; | ||
|
||
const dispatch = createEventDispatcher(); | ||
|
||
function handleToggle() { | ||
dispatch('toggle'); | ||
} | ||
|
||
function formatHour(hour) { | ||
const hourInt = +hour; | ||
if (hourInt === 0) return '12'; | ||
if (hourInt > 12) return hourInt - 12; | ||
return hourInt; | ||
} | ||
|
||
function renderScheduleTable(schedule) { | ||
const stopTimes = Object.entries(schedule.stopTimes); | ||
|
||
const amTimes = stopTimes.filter(([hour]) => +hour < 12); | ||
const pmTimes = stopTimes.filter(([hour]) => +hour >= 12); | ||
|
||
return { | ||
amTimes, | ||
pmTimes | ||
}; | ||
} | ||
|
||
function extractMinutes(arrivalTime) { | ||
return arrivalTime.replace(/[AP]M/, '').split(':')[1]; | ||
} | ||
</script> | ||
|
||
<AccordionItem open={expanded} on:click={handleToggle}> | ||
<span slot="header" class="text-lg font-semibold text-gray-800"> | ||
{schedule.tripHeadsign} | ||
</span> | ||
<div class="overflow-x-auto"> | ||
<table class="mt-4 w-full table-auto rounded-lg border border-gray-200 shadow-lg"> | ||
<thead class="bg-gray-100 text-gray-800"> | ||
<tr> | ||
<th class="cursor-pointer px-6 py-3 text-left">{$t('schedule_for_stop.hour')}</th> | ||
<th class="cursor-pointer px-6 py-3 text-left">{$t('schedule_for_stop.minutes')}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr class="bg-gray-50 hover:bg-gray-100"> | ||
<td colspan="2" class="px-6 py-3 font-semibold text-gray-700">AM</td> | ||
</tr> | ||
{#if renderScheduleTable(schedule).amTimes.length === 0} | ||
<tr> | ||
<td colspan="2" class="border px-6 py-3 text-center text-gray-500"> | ||
{$t('schedule_for_stop.no_am_schedules_available')} | ||
</td> | ||
</tr> | ||
{:else} | ||
{#each renderScheduleTable(schedule).amTimes as [hour, times]} | ||
<tr class="hover:bg-gray-100"> | ||
<td | ||
class="border px-6 py-3 text-center text-lg font-semibold" | ||
title="Full Time: {hour}:{extractMinutes(times[0].arrivalTime)}" | ||
> | ||
{formatHour(hour)} <span class="text-sm text-gray-600">AM</span> | ||
</td> | ||
<td class="border px-6 py-3 text-lg"> | ||
{#each times as stopTime, index (index)} | ||
<span> | ||
{extractMinutes(stopTime.arrivalTime)} | ||
{index < times.length - 1 ? ', ' : ''} | ||
</span> | ||
{/each} | ||
</td> | ||
</tr> | ||
{/each} | ||
{/if} | ||
|
||
<tr class="bg-gray-50 hover:bg-gray-100"> | ||
<td colspan="2" class="px-6 py-3 font-semibold text-gray-700">PM</td> | ||
</tr> | ||
{#if renderScheduleTable(schedule).pmTimes.length === 0} | ||
<tr> | ||
<td colspan="2" class="border px-6 py-3 text-center text-gray-500"> | ||
{$t('schedule_for_stop.no_pm_schedules_available')} | ||
</td> | ||
</tr> | ||
{:else} | ||
{#each renderScheduleTable(schedule).pmTimes as [hour, times]} | ||
<tr class="hover:bg-gray-100"> | ||
<td | ||
class="border px-6 py-3 text-center text-lg font-semibold" | ||
title="Full Time: {hour}:{extractMinutes(times[0].arrivalTime)}" | ||
> | ||
{formatHour(hour)} <span class="text-sm text-gray-600">PM</span> | ||
</td> | ||
<td class="border px-6 py-3 text-lg"> | ||
{#each times as stopTime, index (index)} | ||
<span> | ||
{extractMinutes(stopTime.arrivalTime)} | ||
{index < times.length - 1 ? ', ' : ''} | ||
</span> | ||
{/each} | ||
</td> | ||
</tr> | ||
{/each} | ||
{/if} | ||
</tbody> | ||
</table> | ||
</div> | ||
</AccordionItem> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script> | ||
import { faBus, faMapMarkerAlt, faArrowRight } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/svelte-fontawesome'; | ||
import { t } from 'svelte-i18n'; | ||
export let stopName; | ||
export let stopId; | ||
export let stopDirection; | ||
</script> | ||
|
||
<div class="mb-6 rounded-lg bg-white p-6 text-center shadow-lg"> | ||
<h1 class="flex items-center justify-center gap-2 text-3xl font-bold text-green-700"> | ||
<FontAwesomeIcon icon={faBus} /> | ||
{$t('schedule_for_stop.stop_details')} | ||
</h1> | ||
<p class="mt-2 flex items-center justify-center gap-2 text-lg text-gray-700"> | ||
<FontAwesomeIcon icon={faMapMarkerAlt} /> | ||
<strong>{$t('schedule_for_stop.stop_name')}:</strong> | ||
{stopName} | <strong>{$t('schedule_for_stop.stop_id')}:</strong> | ||
{stopId} | ||
</p> | ||
<p class="mt-2 flex items-center justify-center gap-2 text-lg text-gray-700"> | ||
<FontAwesomeIcon icon={faArrowRight} /> | ||
<strong>{$t('schedule_for_stop.direction')}:</strong> | ||
{stopDirection} | ||
</p> | ||
<div class="mt-4 flex justify-center"> | ||
<a | ||
href={`/stops/${stopId}`} | ||
class="flex items-center justify-center gap-2 rounded-lg bg-green-500 px-3 py-1 text-white shadow hover:bg-green-600" | ||
> | ||
<FontAwesomeIcon icon={faMapMarkerAlt} /> | ||
{$t('schedule_for_stop.click_for_realtime')} | ||
</a> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
import { init, register, getLocaleFromNavigator } from 'svelte-i18n'; | ||
|
||
register('en', () => import('./../locales/en.json')); // English | ||
register('es', () => import('./../locales/es.json')); // Spanish | ||
register('pl', () => import('./../locales/pl.json')); // Polish | ||
register('vi', () => import('./../locales/vi.json')); // Vietnamese | ||
register('tl', () => import('./../locales/tl.json')); // Tagalog | ||
register('so', () => import('./../locales/so.json')); // Somali | ||
register('am', () => import('./../locales/am.json')); // Amharic | ||
register('ar', () => import('./../locales/ar.json')); // Arabic | ||
async function setup() { | ||
register('en', () => import('./../locales/en.json')); // English | ||
register('es', () => import('./../locales/es.json')); // Spanish | ||
register('pl', () => import('./../locales/pl.json')); // Polish | ||
register('vi', () => import('./../locales/vi.json')); // Vietnamese | ||
register('tl', () => import('./../locales/tl.json')); // Tagalog | ||
register('so', () => import('./../locales/so.json')); // Somali | ||
register('am', () => import('./../locales/am.json')); // Amharic | ||
register('ar', () => import('./../locales/ar.json')); // Arabic | ||
|
||
init({ | ||
fallbackLocale: 'en', | ||
initialLocale: getLocaleFromNavigator() | ||
}); | ||
return await Promise.allSettled([ | ||
init({ | ||
fallbackLocale: 'en', | ||
initialLocale: getLocaleFromNavigator() | ||
}) | ||
]); | ||
} | ||
|
||
await setup(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll still merge this, but is there any reason this isn't expressed as:
isn't the outer template string redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right I will update it in the upcoming PR.