|
2 | 2 | import Button from "./Button.svelte"; |
3 | 3 | import ButtonGroup from "./ButtonGroup.svelte"; |
4 | 4 | import SocialLinks from "./SocialLinks.svelte"; |
5 | | - import {canGoForward, canGoBack, nextPage, state} from "../stores/navigation"; |
6 | | - import quit from "../actions/quit"; |
7 | | - import {goto, onNavigate} from "$app/navigation"; |
| 5 | + import {goto} from "$app/navigation"; |
8 | 6 | import {page} from "$app/state"; |
9 | 7 | import {base} from "$app/paths"; |
| 8 | + import app from "$lib/stores/state.svelte"; |
| 9 | + import {NavDirection, type NavigationState} from "$lib/types"; |
10 | 10 |
|
| 11 | + const { |
| 12 | + next, previous, |
| 13 | + nextLabel = "Next", |
| 14 | + previousLabel = "Back", |
| 15 | + canGoNext = true, |
| 16 | + canGoPrevious = true, |
| 17 | + nextAction, previousAction |
| 18 | + }: NavigationState = $derived(app.navigation); |
| 19 | +
|
| 20 | + $effect(() => { |
| 21 | + // eslint-disable-next-line no-console |
| 22 | + console.log({ |
| 23 | + next, |
| 24 | + previous, |
| 25 | + nextLabel, |
| 26 | + previousLabel, |
| 27 | + canGoNext, |
| 28 | + canGoPrevious, |
| 29 | + nextAction, |
| 30 | + previousAction |
| 31 | + }); |
| 32 | + }); |
| 33 | +
|
| 34 | +
|
| 35 | + const nextDisabled: boolean = $derived.by(() => { |
| 36 | + if (!canGoNext) return true; |
| 37 | + if (!nextAction && !next) return true; |
| 38 | + return false; |
| 39 | + }); |
| 40 | +
|
| 41 | + const previousDisabled: boolean = $derived.by(() => { |
| 42 | + if (!canGoPrevious) return true; |
| 43 | + if (!previousAction && !previous) return true; |
| 44 | + return false; |
| 45 | + }); |
11 | 46 |
|
12 | | - let nextButtonContent = "Next"; |
13 | 47 |
|
14 | 48 | async function goToNext() { |
15 | | - state.direction = 1; |
16 | | - if ($nextPage) goto(`${base}${$nextPage}`, page.state); |
17 | | - else await quit(); |
| 49 | + app.navigation.direction = NavDirection.FORWARDS; |
| 50 | + if (typeof nextAction === "function") return nextAction(); |
| 51 | + if (next) goto(`${base}${next}`, page.state); |
18 | 52 | } |
19 | 53 |
|
20 | 54 | function goBack() { |
21 | | - state.direction = -1; |
22 | | - window.history.back(); |
| 55 | + app.navigation.direction = NavDirection.BACKWARDS; |
| 56 | + if (typeof previousAction === "function") return previousAction(); |
| 57 | + if (previous) goto(`${base}${previous}`, page.state); |
23 | 58 | } |
24 | 59 |
|
25 | | - onNavigate(() => { |
26 | | - if (window.location.pathname.startsWith("/actions/setup/")) { |
27 | | - const action = window.location.pathname.slice(15); |
28 | | - const actionText = action[0].toUpperCase() + action.slice(1); |
29 | | - nextButtonContent = actionText; |
30 | | - } |
31 | | - else { |
32 | | - nextButtonContent = "Next"; |
33 | | - } |
34 | | - }); |
35 | | -
|
36 | 60 | function navigatePage(event: KeyboardEvent) { |
37 | | - if ((event.key === "ArrowRight" && event.ctrlKey) && $canGoForward) { |
| 61 | + if ((event.key === "ArrowRight" && event.ctrlKey) && canGoNext) { |
38 | 62 | goToNext(); |
39 | 63 | } |
40 | | - else if ((event.key === "ArrowLeft" && event.ctrlKey) && $canGoBack) { |
| 64 | + else if ((event.key === "ArrowLeft" && event.ctrlKey) && canGoPrevious) { |
41 | 65 | goBack(); |
42 | 66 | } |
43 | 67 | } |
|
49 | 73 | <footer class="install-footer"> |
50 | 74 | <SocialLinks /> |
51 | 75 | <ButtonGroup> |
52 | | - <Button style="secondary" disabled={!$canGoBack} onclick={goBack}>Back</Button> |
53 | | - <Button style="primary" disabled={!$canGoForward} onclick={goToNext}>{#if $nextPage}{nextButtonContent}{:else}Close{/if}</Button> |
| 76 | + <Button style="secondary" disabled={previousDisabled} onclick={goBack}> |
| 77 | + {previousLabel} |
| 78 | + </Button> |
| 79 | + <Button style="primary" disabled={nextDisabled} onclick={goToNext}> |
| 80 | + {nextLabel} |
| 81 | + </Button> |
54 | 82 | </ButtonGroup> |
55 | 83 | </footer> |
56 | 84 |
|
|
0 commit comments