Skip to content

Commit

Permalink
added the feature to change the url onclick, onclose is implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunsinghofficial committed Jul 18, 2024
1 parent 9b284a4 commit 1dfdc5a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/map/GoogleMap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
PUBLIC_OBA_REGION_CENTER_LAT as initialLat,
PUBLIC_OBA_REGION_CENTER_LNG as initialLng
} from '$env/static/public';
import { pushState } from '$app/navigation';
import { createMap, loadGoogleMapsLibrary, nightModeStyles } from '$lib/googleMaps';
import LocationButton from '$lib/LocationButton/LocationButton.svelte';
Expand Down Expand Up @@ -68,6 +69,7 @@
const container = document.createElement('div');
document.body.appendChild(container);
function handleClick() {
pushState(`/stops/${s.id}`);
dispatch('stopSelected', { stop: s });
}
Expand Down Expand Up @@ -156,6 +158,10 @@
}
});
});
function handleStopSelected(stop) {
dispatch('stopSelected', { stop });
}
</script>

<div id="map"></div>
Expand Down
2 changes: 2 additions & 0 deletions src/components/navigation/ModalPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import { faX } from '@fortawesome/free-solid-svg-icons';
import { keybinding } from '$lib/keybinding';
import { createEventDispatcher } from 'svelte';
import { pushState } from '$app/navigation';
const dispatch = createEventDispatcher();
function closePane() {
pushState('/');
dispatch('close');
}
</script>
Expand Down
18 changes: 18 additions & 0 deletions src/routes/api/oba/stop/[stopID]/+server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { error, json } from '@sveltejs/kit';

import { PUBLIC_OBA_SERVER_URL as baseURL } from '$env/static/public';
import { PRIVATE_OBA_API_KEY as apiKey } from '$env/static/private';

/** @type {import('./$types').RequestHandler} */
export async function GET({ params }) {
const stopID = params.stopID;
const apiURL = `${baseURL}/api/where/stop/${stopID}.json?key=${apiKey}`;
const response = await fetch(apiURL);

if (!response.ok) {
return error(500, 'Unable to fetch arrivals-and-departures-for-stop.');
}

const data = await response.json();
return json(data);
}
28 changes: 28 additions & 0 deletions src/routes/stops/[stopID]/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script context="module">
import StopPane from '../../../components/oba/StopPane.svelte';
export async function load({ params }) {
const stopID = params.stopID;
const response = await fetch(`/api/oba/stops/${stopID}`);
if (!response.ok) {
return {
status: response.status,
error: new Error('Failed to fetch stop data')
};
}
const stopData = await response.json();
return {
props: {
stopData
}
};
}
</script>

<script>
export let stopData;
</script>

<StopPane {stopData} />

0 comments on commit 1dfdc5a

Please sign in to comment.