Small UX updates assistants (#872)
Browse filesFiles changed (4)
16 unmodified lines171819202122232439 unmodified lines646566676869707172737475767716 unmodified linesassistants: Array<ObjectId | string>;};export function useSettingsStore() {return getContext<Writable<SettingsStore>>("settings");}export function createSettingsStore(initialValue: Omit<SettingsStore, "recentlySaved">) {39 unmodified lines// debounce server calls by 300ms}}const newStore = {subscribe: baseStore.subscribe,set: setSettings,update: (fn: (s: SettingsStore) => SettingsStore) => {setSettings(fn(get(baseStore)));},} satisfies Writable<SettingsStore>;setContext("settings", newStore);16 unmodified lines17181920212223242526272839 unmodified lines686970717273747576777879808182838485868788899091929394959697989910010110216 unmodified linesassistants: Array<ObjectId | string>;};type SettingsStoreWritable = Writable<SettingsStore> & {instantSet: (settings: Partial<SettingsStore>) => Promise<void>;};export function useSettingsStore() {return getContext<SettingsStoreWritable>("settings");}export function createSettingsStore(initialValue: Omit<SettingsStore, "recentlySaved">) {39 unmodified lines// debounce server calls by 300ms}}async function instantSet(settings: Partial<SettingsStore>) {baseStore.update((s) => ({...s,...settings,}));if (browser) {await fetch(`${base}/settings`, {method: "POST",headers: {"Content-Type": "application/json",},body: JSON.stringify({...get(baseStore),...settings,}),});invalidate(UrlDependency.ConversationList);}}const newStore = {subscribe: baseStore.subscribe,set: setSettings,instantSet,update: (fn: (s: SettingsStore) => SettingsStore) => {setSettings(fn(get(baseStore)));},} satisfies SettingsStoreWritable;setContext("settings", newStore);
115 unmodified lines116117118119120121122115 unmodified linesif ($settings.activeModel === $page.url.searchParams.get("model")) {goto(`${base}/?`);}$settings.activeModel = $page.url.searchParams.get("model") ?? $settings.activeModel;}$: mobileNavTitle = ["/models", "/assistants", "/privacy"].includes($page.route.id ?? "")115 unmodified lines116117118119120121122123124115 unmodified linesif ($settings.activeModel === $page.url.searchParams.get("model")) {goto(`${base}/?`);}settings.instantSet({activeModel: $page.url.searchParams.get("model") ?? $settings.activeModel,});}$: mobileNavTitle = ["/models", "/assistants", "/privacy"].includes($page.route.id ?? "")
7 unmodified lines891011121333 unmodified lines4748495051527 unmodified linesimport { applyAction, enhance } from "$app/forms";import { PUBLIC_APP_NAME, PUBLIC_ORIGIN } from "$env/static/public";import { page } from "$app/stores";export let data: PageData;33 unmodified lines}}class="z-10 flex flex-col content-center items-center gap-x-10 gap-y-3 overflow-hidden rounded-2xl bg-white p-4 pt-6 text-center shadow-2xl outline-none max-sm:w-[85dvw] max-sm:px-6 md:w-96 md:grid-cols-3 md:grid-rows-[auto,1fr] md:p-8">{#if data.assistant.avatar}<imgclass="size-16 flex-none rounded-full object-cover sm:size-24"7 unmodified lines89101112131433 unmodified lines48495051525354555657585960616263646566676869707172737475767778798081827 unmodified linesimport { applyAction, enhance } from "$app/forms";import { PUBLIC_APP_NAME, PUBLIC_ORIGIN } from "$env/static/public";import { page } from "$app/stores";import IconGear from "~icons/bi/gear-fill";export let data: PageData;33 unmodified lines}}class="z-10 flex flex-col content-center items-center gap-x-10 gap-y-3 overflow-hidden rounded-2xl bg-white p-4 pt-6 text-center shadow-2xl outline-none max-sm:w-[85dvw] max-sm:px-6 md:w-96 md:grid-cols-3 md:grid-rows-[auto,1fr] md:p-8"><div class="absolute right-0 top-0 m-6"><formmethod="POST"action="{base}/settings/assistants/{data.assistant._id}?/subscribe"class="w-full"use:enhance={() => {return async ({ result }) => {// `result` is an `ActionResult` objectif (result.type === "success") {$settings.activeModel = data.assistant._id;await goto(`${base}/settings/assistants/${data.assistant._id}`, {invalidateAll: true,});} else {await applyAction(result);}};}}><buttonclass="flex items-center rounded-full border border-gray-200 px-2.5 py-1 text-sm text-gray-900 hover:bg-gray-100"name="Settings"type="submit"><IconGear class="mr-1.5 text-xxs" />Settings</button></form></div>{#if data.assistant.avatar}<imgclass="size-16 flex-none rounded-full object-cover sm:size-24"
16 unmodified lines1718192021227 unmodified lines303132333435107 unmodified lines14314414514614714814915015134 unmodified lines18618718818919019119216 unmodified linesimport Pagination from "$lib/components/Pagination.svelte";import { formatUserCount } from "$lib/utils/formatUserCount";import { getHref } from "$lib/utils/getHref";export let data: PageData;7 unmodified lines});goto(newUrl);};</script><svelte:head>107 unmodified lines<div class="mt-8 grid grid-cols-2 gap-3 sm:gap-5 md:grid-cols-3 lg:grid-cols-4">{#each data.assistants as assistant (assistant._id)}<ahref="{base}/assistant/{assistant._id}"class="relative flex flex-col items-center justify-center overflow-hidden text-balance rounded-xl border bg-gray-50/50 px-4 py-6 text-center shadow hover:bg-gray-50 hover:shadow-inner max-sm:px-4 sm:h-64 sm:pb-4 xl:pt-8 dark:border-gray-800/70 dark:bg-gray-950/20 dark:hover:bg-gray-950/40">{#if assistant.userCount && assistant.userCount > 1}<div34 unmodified lines</a></p>{/if}</a>{:else}No assistants found{/each}16 unmodified lines171819202122237 unmodified lines3132333435363738107 unmodified lines14614714814915015115215315415515615715815916016134 unmodified lines19619719819920020120216 unmodified linesimport Pagination from "$lib/components/Pagination.svelte";import { formatUserCount } from "$lib/utils/formatUserCount";import { getHref } from "$lib/utils/getHref";import { useSettingsStore } from "$lib/stores/settings";export let data: PageData;7 unmodified lines});goto(newUrl);};const settings = useSettingsStore();</script><svelte:head>107 unmodified lines<div class="mt-8 grid grid-cols-2 gap-3 sm:gap-5 md:grid-cols-3 lg:grid-cols-4">{#each data.assistants as assistant (assistant._id)}<buttonclass="relative flex flex-col items-center justify-center overflow-hidden text-balance rounded-xl border bg-gray-50/50 px-4 py-6 text-center shadow hover:bg-gray-50 hover:shadow-inner max-sm:px-4 sm:h-64 sm:pb-4 xl:pt-8 dark:border-gray-800/70 dark:bg-gray-950/20 dark:hover:bg-gray-950/40"on:click={() => {if (data.settings.assistants.includes(assistant._id.toString())) {settings.instantSet({ activeModel: assistant._id.toString() });goto(`${base}` || "/");} else {goto(`${base}/assistant/${assistant._id}`);}}}>{#if assistant.userCount && assistant.userCount > 1}<div34 unmodified lines</a></p>{/if}</button>{:else}No assistants found{/each}
src/lib/stores/settings.ts+27-2
src/routes/+layout.svelte+3-1
src/routes/assistant/[assistantId]/+page.svelte+30
src/routes/assistants/+page.svelte+13-3