Skip to content
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

Toast tweaks #905

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const PDF_SIZE_LIMIT_READABLE = "500 MB";
export const DOCUMENT_SIZE_LIMIT = 27262976;
export const DOCUMENT_SIZE_LIMIT_READABLE = "25 MB";

export const TOAST_LENGTH = 2500;
export const TOAST_LENGTH = 3000;
export const TOAST_FADE = 800;

export const LEGACY_CUT_OFF = 20000000;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/common/Toast.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
.toast {
padding: 0.5rem 0.5rem;
border-radius: 0.5rem;
box-shadow: var(--shadow-3);
box-shadow: var(--shadow-2);
display: inline-flex;
align-items: flex-start;
width: 100%;
Expand Down
24 changes: 17 additions & 7 deletions src/lib/components/layouts/Toaster.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,28 @@
contents: ToastContents;
}

function addToast(newToast: ToastItem, prev: ToastItem[]) {
const id = Date.now();
return [...prev, { ...newToast, id }];
}

export const toasts = writable<ToastItem[]>([]);

export function toast<P>(
contents: ToastContents,
options: ToastOptions<P> = {},
) {
toasts.update((prev) => addToast({ contents, ...options }, prev));
): number {
const newToast = { id: Date.now(), contents, ...options };
toasts.update((prev) => [...prev, newToast]);
// Return the ID so we can update the toast later
return newToast.id;
}

export function updateToast<P>(
id: number,
contents: ToastContents,
options: ToastOptions<P> = {},
): void {
toasts.update((prev) =>
prev.map((toast) =>
toast.id === id ? { ...toast, contents, ...options } : toast,
),
);
}
</script>

Expand Down