|
16 | 16 | import Button from '$lib/components/ui/button/button.svelte'; |
17 | 17 | import * as Card from '$lib/components/ui/card'; |
18 | 18 | import { renderComponent } from '$lib/components/ui/data-table'; |
| 19 | + import type { ProblemDetails } from '$lib/errorhandling/ProblemDetails'; |
19 | 20 | import { handleApiError } from '$lib/errorhandling/apiErrorHandling'; |
20 | 21 | import { onMount } from 'svelte'; |
21 | 22 | import { toast } from 'svelte-sonner'; |
22 | 23 | import DataTableActions from './data-table-actions.svelte'; |
23 | 24 |
|
| 25 | + let loading = $state<boolean>(false); |
24 | 26 | let data = $state<LoginSessionResponse[]>([]); |
25 | 27 | let sorting = $state<SortingState>([]); |
26 | 28 |
|
|
43 | 45 | }, |
44 | 46 | ]; |
45 | 47 |
|
46 | | - function fetchSessions() { |
47 | | - sessionsApi |
48 | | - .sessionsListSessions() |
49 | | - .then((res) => (data = res)) |
50 | | - .catch(handleApiError); |
| 48 | + function handleProblem(problem: ProblemDetails): boolean { |
| 49 | + return false; |
| 50 | + } |
| 51 | +
|
| 52 | + async function fetchSessions() { |
| 53 | + loading = true; |
| 54 | + try { |
| 55 | + data = await sessionsApi.sessionsListSessions(); |
| 56 | + } catch (error) { |
| 57 | + await handleApiError(error, handleProblem); |
| 58 | + } finally { |
| 59 | + loading = false; |
| 60 | + } |
| 61 | + } |
| 62 | +
|
| 63 | + async function onRefreshClicked() { |
| 64 | + await fetchSessions(); |
| 65 | + toast.success('Sessions refreshed successfully'); |
51 | 66 | } |
52 | 67 |
|
53 | 68 | onMount(() => { |
|
68 | 83 | <Card.Header class="w-full"> |
69 | 84 | <Card.Title class="flex items-center justify-between space-x-2 text-3xl"> |
70 | 85 | Sessions |
71 | | - <Button |
72 | | - class="text-xl" |
73 | | - onclick={() => { |
74 | | - fetchSessions(); |
75 | | - toast.success('Sessions refreshed successfully'); |
76 | | - }} |
77 | | - > |
| 86 | + <Button class="text-xl" onclick={onRefreshClicked}> |
78 | 87 | <RotateCcw /> |
79 | 88 | <span> Refresh </span> |
80 | 89 | </Button> |
|
0 commit comments