Repository navigation
feat(regulations): import from the repository in the background #178
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
+95
−27
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,20 @@ | ||
| import { toast } from "sonner" | ||
| import { type ExternalToast, toast } from "sonner" | ||
|
|
||
| /** | ||
| * Toasts with these durations: success/info 4s, warning 6s, error 8s. They go to the one | ||
| * `Toaster` mounted in the root document. Copy follows the toast formula in docs/design.md: "Group deleted.", | ||
| * "Couldn't delete the group." | ||
| * `id` turns an earlier toast (a `loading` one) into this one; `duration: Infinity` keeps it until dismissed, so pair it | ||
| * with `closeButton`: the only dismissal a keyboard can reach. | ||
| */ | ||
| type AppToastOptions = Pick<ExternalToast, "id" | "duration" | "closeButton"> | ||
|
|
||
| /** | ||
| * Toasts with these durations: success/info 4s, warning 6s, error 8s; loading stays until its `id` gets another | ||
| * toast. They go to the one `Toaster` mounted in the root document. Copy follows the toast formula in docs/design.md: | ||
| * "Group deleted.", "Couldn't delete the group." | ||
| */ | ||
| export const appToast = { | ||
| success: (message: string) => toast.success(message, { duration: 4000 }), | ||
| info: (message: string) => toast.info(message, { duration: 4000 }), | ||
| warning: (message: string) => toast.warning(message, { duration: 6000 }), | ||
| error: (message: string) => toast.error(message, { duration: 8000 }), | ||
| success: (message: string, options?: AppToastOptions) => toast.success(message, { duration: 4000, ...options }), | ||
| info: (message: string, options?: AppToastOptions) => toast.info(message, { duration: 4000, ...options }), | ||
| warning: (message: string, options?: AppToastOptions) => toast.warning(message, { duration: 6000, ...options }), | ||
| error: (message: string, options?: AppToastOptions) => toast.error(message, { duration: 8000, ...options }), | ||
| loading: (message: string) => toast.loading(message), | ||
| } |
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,33 @@ | ||
| import { useSyncExternalStore } from "react" | ||
|
|
||
| import type { SyncResult } from "./regulations.contract" | ||
|
|
||
| type DocumentsSync = { running: boolean; result: SyncResult | null } | ||
|
|
||
| const idle: DocumentsSync = { running: false, result: null } | ||
| let state = idle | ||
| const listeners = new Set<() => void>() | ||
|
|
||
| function subscribe(listener: () => void) { | ||
| listeners.add(listener) | ||
| return () => { | ||
| listeners.delete(listener) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The import reads the whole repository and runs in the background: it outlives the Documenti page, so | ||
| * leaving and coming back still shows it running, and then what it left out. | ||
| */ | ||
| export function useDocumentsSync() { | ||
| return useSyncExternalStore( | ||
| subscribe, | ||
| () => state, | ||
| () => idle | ||
| ) | ||
| } | ||
|
|
||
| export function setDocumentsSync(next: Partial<DocumentsSync>) { | ||
| state = { ...state, ...next } | ||
| for (const listener of listeners) listener() | ||
| } |
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
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.