Made components more re-usable. Added section component

This commit is contained in:
2025-05-23 16:04:35 +01:00
parent 24a7ebf02a
commit 538d9593c2
7 changed files with 65 additions and 99 deletions

View File

@@ -1,38 +1,7 @@
import { ToastType, type Toast } from "$lib/toast";
import { writable, type Writable } from "svelte/store";
import { writable } from "svelte/store";
import type { GitRepo } from "./types";
import { fetchRepos } from "./api/git";
////////////////////////////////////////
// Toast Stores
////////////////////////////////////////
export const toasts: Writable<Toast[]> = writable([]);
export const addToast = (toast: Toast) => {
// Create a unique ID so we can easily find/remove it
// if it is dismissible/has a timeout.
toast.id = Math.floor(Math.random() * 10000);
// Setup some sensible defaults for a toast.
const defaults = {
id: toast.id,
type: ToastType.Info,
dismissible: true,
timeout: 3000,
};
// Push the toast to the top of the list of toasts
toasts.update((all) => [{ ...defaults, ...toast }, ...all]);
// If toast is dismissible, dismiss it after "timeout" amount of time.
if (toast.timeout) setTimeout(() => dismissToast(toast.id), toast.timeout);
};
export const dismissToast = (id: number) => {
toasts.update((all) => all.filter((t) => t.id !== id));
};
////////////////////////////////////////
// Git Repo Stores
////////////////////////////////////////