-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/replace dialog manager #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e609eca
replace old dialog manager
LucHeart 1803fd1
switch to svelte states instead of store
LucHeart 3069ca3
Merge branch 'develop' into feature/replace-dialog-manager
LucHeart 46c094e
fix reactivity on ota stuff
LucHeart c3288eb
states in classes are the goat
LucHeart 8cfd1cb
format once more
LucHeart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
src/lib/components/dialog-manager/dialog-alert-content.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <script lang="ts"> | ||
| import { Button } from '$lib/components/ui/button'; | ||
| import * as Dialog from '$lib/components/ui/dialog'; | ||
| import type { AlertProps } from './types'; | ||
|
|
||
| let { title, desc, buttonText = 'OK', resolve }: AlertProps = $props(); | ||
|
|
||
| function handleAcknowledge() { | ||
| resolve(); | ||
| } | ||
| </script> | ||
|
|
||
| <Dialog.Header> | ||
| <Dialog.Title>{title}</Dialog.Title> | ||
| {#if desc} | ||
| <Dialog.Description>{desc}</Dialog.Description> | ||
| {/if} | ||
| </Dialog.Header> | ||
| <Dialog.Footer> | ||
| <Button onclick={handleAcknowledge}>{buttonText}</Button> | ||
| </Dialog.Footer> |
45 changes: 45 additions & 0 deletions
45
src/lib/components/dialog-manager/dialog-confirm-content.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <script lang="ts" generics="T"> | ||
| import { LoaderCircle } from '@lucide/svelte'; | ||
| import { Button } from '$lib/components/ui/button'; | ||
| import * as Dialog from '$lib/components/ui/dialog'; | ||
| import type { ConfirmProps } from './types.ts'; | ||
|
|
||
| let { | ||
| title, | ||
| desc, | ||
| data, | ||
| confirmButtonText = 'Confirm', | ||
| cancelButtonText = 'Cancel', | ||
| descSnippet, | ||
| resolve, | ||
| close, | ||
| }: ConfirmProps<T> = $props(); | ||
|
|
||
| let loading = $state(false); | ||
|
|
||
| function handleConfirm() { | ||
| loading = true; | ||
| resolve({ confirmed: true, data: data as T }); | ||
| } | ||
|
|
||
| function handleCancel() { | ||
| close(); | ||
| } | ||
| </script> | ||
|
|
||
| <Dialog.Header> | ||
| <Dialog.Title>{title}</Dialog.Title> | ||
| <Dialog.Description> | ||
| {desc} | ||
| {#if descSnippet} | ||
| {@render descSnippet(data as T)} | ||
| {/if} | ||
| </Dialog.Description> | ||
| </Dialog.Header> | ||
| <Dialog.Footer> | ||
| <Button variant="outline" onclick={handleCancel}>{cancelButtonText}</Button> | ||
| <Button disabled={loading} variant="destructive" onclick={handleConfirm}> | ||
| {#if loading}<LoaderCircle class="animate-spin" />{/if} | ||
| {confirmButtonText} | ||
| </Button> | ||
| </Dialog.Footer> |
16 changes: 16 additions & 0 deletions
16
src/lib/components/dialog-manager/dialog-custom-content.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <script lang="ts" generics="T, R"> | ||
| import type { CustomProps, DialogRenderProps } from './types.ts'; | ||
|
|
||
| let { data: initialData, contentSnippet, resolve, close }: CustomProps<T, R> = $props(); | ||
|
|
||
| // svelte-ignore state_referenced_locally -- intentionally captures initial value as own reactive copy | ||
| let data: T = $state(initialData as T); | ||
|
|
||
| const renderProps: DialogRenderProps<T, R> = $derived({ | ||
| data, | ||
| resolve, | ||
| close, | ||
| }); | ||
| </script> | ||
|
|
||
| {@render contentSnippet(renderProps)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <script lang="ts"> | ||
| import * as Dialog from '$lib/components/ui/dialog'; | ||
| import { getOldestDialog } from './dialog-store.svelte.ts'; | ||
|
|
||
| let entry = $derived(getOldestDialog()); | ||
| let dialogId = $derived(entry?.[0]); | ||
| let ctx = $derived(entry?.[1]); | ||
|
|
||
| let open = $state(true); | ||
|
|
||
| // Reset open when dialog changes | ||
| $effect(() => { | ||
| if (dialogId) { | ||
| open = true; | ||
| } | ||
| }); | ||
|
|
||
| function handleOpenChange(isOpen: boolean) { | ||
| if (!isOpen && ctx) { | ||
| // Dialog was closed (escape, overlay click, etc.) - call close handler | ||
| (ctx.props as { close?: () => void }).close?.(); | ||
| } | ||
| open = isOpen; | ||
| } | ||
| </script> | ||
|
|
||
| {#if dialogId && ctx} | ||
| {#key dialogId} | ||
| <Dialog.Root bind:open={() => open, handleOpenChange}> | ||
| <Dialog.Content> | ||
| <ctx.content {...ctx.props} /> | ||
| </Dialog.Content> | ||
| </Dialog.Root> | ||
| {/key} | ||
| {/if} | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing
./dialog-store.svelte.tsis inconsistent with the rest of the codebase, which imports.svelte.tsmodules via the.sveltespecifier (e.g.$lib/stores/HubsStore.svelte,$lib/components/dialog-manager/dialog-store.svelte). Consider switching this to./dialog-store.sveltefor consistency and to avoid resolver/tooling edge cases.