Skip to content

Commit

Permalink
Merge pull request #905 from MuckRock/toast-optim
Browse files Browse the repository at this point in the history
Toast tweaks
  • Loading branch information
allanlasser authored Dec 2, 2024
2 parents ef07264 + 839acfb commit 09edf36
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
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

0 comments on commit 09edf36

Please sign in to comment.