Skip to content

Commit

Permalink
Merge pull request #9 from prasek/order-refresh
Browse files Browse the repository at this point in the history
update orders page to show progress
  • Loading branch information
tomwheeler committed Sep 6, 2024
2 parents 80bb343 + 02b55ab commit 2514bc0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/routes/orders/(order)/[id]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { env } from '$env/dynamic/private';

export const load = async ({ params }) => {
export const load = async ({ params, depends }) => {
depends('data:order')
const { id } = params;

const orderResponse = await fetch(`${env.ORDER_API_URL}/orders/${id}`);
Expand Down
19 changes: 19 additions & 0 deletions src/routes/orders/(order)/[id]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
<script lang="ts">
import { page } from '$app/stores';
import { onMount } from 'svelte';
import { invalidate } from '$app/navigation';
import FulfillmentDetails from '$lib/components/fulfillment-details.svelte';
import OrderActions from '$lib/components/order-actions.svelte';
$: ({ order } = $page.data);
onMount(() => {
const finalStatuses = ['completed', 'failed', 'cancelled'];
const interval = setInterval(() => {
const isFinal = finalStatuses.includes(order.status);
if (!isFinal) {
invalidate('data:order');
} else {
clearInterval(interval);
}
}, 500);
return () => {
clearInterval(interval);
};
});
</script>

<section>
Expand Down

0 comments on commit 2514bc0

Please # to comment.