-
-
Notifications
You must be signed in to change notification settings - Fork 4
Add progress indicator while loading patches and directories #24
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
5 commits
Select commit
Hold shift + click to select a range
2658bb6
Add progress indicator while loading patches and directories
jpenilla b7dfcaf
Refactor patch loading and increase responsiveness while loading/sele…
jpenilla 888cea8
yield patches one at a time
jpenilla ed19db8
Add explicit loading flag
jpenilla ad7c91e
Move await for GitHub content to allow meta return early
jpenilla 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,24 @@ | ||
| <script lang="ts"> | ||
| import { type RestProps } from "$lib/types"; | ||
| import { type Snippet } from "svelte"; | ||
| import { Button, mergeProps } from "bits-ui"; | ||
| import { type DirectoryEntry, pickDirectory } from "$lib/components/files/index.svelte"; | ||
| import { type DirectoryEntry, type DirectoryInputProps, DirectoryInputState } from "$lib/components/files/index.svelte"; | ||
| import { box } from "svelte-toolbelt"; | ||
|
|
||
| type Props = { | ||
| children?: Snippet<[{ directory?: DirectoryEntry }]>; | ||
| directory?: DirectoryEntry; | ||
| } & RestProps; | ||
| let { children, directory = $bindable<DirectoryEntry | undefined>(), loading = $bindable(false), ...restProps }: DirectoryInputProps = $props(); | ||
|
|
||
| let { children, directory = $bindable<DirectoryEntry | undefined>(undefined), ...restProps }: Props = $props(); | ||
| const instance = new DirectoryInputState({ | ||
| directory: box.with( | ||
| () => directory, | ||
| (v) => (directory = v), | ||
| ), | ||
| loading: box.with( | ||
| () => loading, | ||
| (v) => (loading = v), | ||
| ), | ||
| }); | ||
|
|
||
| async function onclick() { | ||
| try { | ||
| directory = await pickDirectory(); | ||
| } catch (e) { | ||
| if (e instanceof Error && e.name === "AbortError") { | ||
| return; | ||
| } else { | ||
| console.error("Failed to pick directory", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const mergedProps = mergeProps({ onclick }, restProps); | ||
| const mergedProps = $derived(mergeProps(instance.props, restProps)); | ||
| </script> | ||
|
|
||
| <Button.Root type="button" {...mergedProps}> | ||
| {@render children?.({ directory })} | ||
| {@render children?.({ directory, loading })} | ||
| </Button.Root> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <script lang="ts"> | ||
| import { mergeProps, Progress } from "bits-ui"; | ||
| import { type ProgressBarProps, useProgressBarState } from "$lib/components/progress-bar/index.svelte"; | ||
| let { state = $bindable(), ...restProps }: ProgressBarProps = $props(); | ||
| state = useProgressBarState(state); | ||
| const mergedProps = $derived( | ||
| mergeProps( | ||
| { | ||
| class: "bg-em-disabled/30 inset-shadow-xs relative overflow-hidden rounded-full", | ||
| }, | ||
| restProps, | ||
| ), | ||
| ); | ||
| </script> | ||
|
|
||
| <Progress.Root value={state.value} max={state.max} {...mergedProps}> | ||
| {@const percent = state.getPercent()} | ||
| {#if percent !== undefined} | ||
| <div | ||
| class="h-full w-full rounded-full bg-primary drop-shadow-sm drop-shadow-primary/50 transition-all duration-250 ease-in-out" | ||
| style={`transform: translateX(-${100 - percent}%)`} | ||
| ></div> | ||
| {:else} | ||
| <div id="spinner" class="h-full w-[20%] rounded-full bg-primary drop-shadow-sm drop-shadow-primary/50"></div> | ||
| {/if} | ||
| </Progress.Root> | ||
|
|
||
| <style> | ||
| #spinner { | ||
| animation: slide 1s linear infinite alternate; | ||
| } | ||
| @keyframes slide { | ||
| 0% { | ||
| transform: translateX(0%); | ||
| } | ||
| 100% { | ||
| transform: translateX(400%); | ||
| } | ||
| } | ||
| </style> | ||
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,47 @@ | ||
| import type { RestProps } from "$lib/types"; | ||
|
|
||
| export interface ProgressBarProps extends RestProps { | ||
| state?: ProgressBarState | undefined; | ||
| } | ||
|
|
||
| export function useProgressBarState(state: ProgressBarState | undefined): ProgressBarState { | ||
| return state === undefined ? new ProgressBarState(0, 100) : state; | ||
| } | ||
|
|
||
| export class ProgressBarState { | ||
| value: number | null = $state(null); | ||
| max: number = $state(100); | ||
|
|
||
| constructor(value: number | null, max: number) { | ||
| this.value = value; | ||
| this.max = max; | ||
| } | ||
|
|
||
| setProgress(value: number, max: number) { | ||
| this.value = value; | ||
| this.max = max; | ||
| } | ||
|
|
||
| setSpinning() { | ||
| this.value = null; | ||
| this.max = 100; | ||
| } | ||
|
|
||
| isSpinning(): boolean { | ||
| return this.value === null; | ||
| } | ||
|
|
||
| isDone(): boolean { | ||
| return this.value !== null && this.value >= this.max; | ||
| } | ||
|
|
||
| getPercent(): number | undefined { | ||
| if (this.value === null) { | ||
| return undefined; | ||
| } | ||
| if (this.max <= 0) { | ||
| return 0; | ||
| } | ||
jpenilla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return (this.value / this.max) * 100; | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.