Skip to content

Commit

Permalink
update orders page to show progress
Browse files Browse the repository at this point in the history
Signed-off-by: Phil Prasek <prasek@gmail.com>
  • Loading branch information
prasek committed Sep 6, 2024
1 parent ecd2832 commit 02b55ab
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 02b55ab

Please # to comment.