Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(desktop): add account profile to settings sidebar
Richie McIlroy20e6309d1550
diff --git a/apps/desktop/src/routes/(window-chrome)/settings.tsx b/apps/desktop/src/routes/(window-chrome)/settings.tsxindex 0c6109973..ed59b88c4 100644--- a/apps/desktop/src/routes/(window-chrome)/settings.tsx+++ b/apps/desktop/src/routes/(window-chrome)/settings.tsx@@ -1,22 +1,128 @@import { Button } from "@cap/ui-solid";import { A, type RouteSectionProps, useNavigate } from "@solidjs/router";+import { createQuery } from "@tanstack/solid-query";import { getVersion } from "@tauri-apps/api/app";import * as dialog from "@tauri-apps/plugin-dialog";import * as shell from "@tauri-apps/plugin-shell";import { check } from "@tauri-apps/plugin-updater";-import "@total-typescript/ts-reset/filter-boolean";-import { createResource, createSignal, For, Show, Suspense } from "solid-js";+import {+ createMemo,+ createResource,+ createSignal,+ For,+ Show,+ Suspense,+} from "solid-js";import { CapErrorBoundary } from "~/components/CapErrorBoundary";import { SignInButton } from "~/components/SignInButton";import { authStore } from "~/store";import { trackEvent } from "~/utils/analytics";+import { clientEnv } from "~/utils/env";+import { apiClient, protectedHeaders } from "~/utils/web-api";+import IconLucideUserRound from "~icons/lucide/user-round";export default function Settings(props: RouteSectionProps) {const navigate = useNavigate();const auth = authStore.createQuery();const [version] = createResource(() => getVersion());const [isCheckingForUpdates, setIsCheckingForUpdates] = createSignal(false);+ const userProfile = createQuery(() => ({+ queryKey: ["settings-user-profile", auth.data?.user_id],+ enabled: !!auth.data,+ staleTime: 30 * 60 * 1000,+ gcTime: 2 * 60 * 60 * 1000,+ refetchOnMount: false,+ refetchOnWindowFocus: false,+ refetchOnReconnect: false,+ queryFn: async () => {+ const response = await apiClient.desktop.getUserProfile({+ headers: await protectedHeaders(),+ });++ if (response.status !== 200)+ throw new Error("Failed to load account profile");++ return response.body;+ },+ }));+ const settingsItems = [+ {+ href: "general",+ name: "General",+ icon: IconCapSettings,+ },+ {+ href: "hotkeys",+ name: "Shortcuts",+ icon: IconCapHotkeys,+ },+ {+ href: "recordings",+ name: "Recordings",+ icon: IconLucideSquarePlay,+ },+ {+ href: "screenshots",+ name: "Screenshots",+ icon: IconLucideImage,+ },+ {+ href: "transcription",+ name: "Transcription",+ icon: IconCapCaptions,+ },+ {+ href: "integrations",+ name: "Integrations",+ icon: IconLucideUnplug,+ },+ {+ href: "license",+ name: "License",+ icon: IconLucideGift,+ },+ {+ href: "experimental",+ name: "Experimental",+ icon: IconCapSettings,+ },+ {+ href: "feedback",+ name: "Feedback",+ icon: IconLucideMessageSquarePlus,+ },+ {+ href: "changelog",+ name: "Changelog",+ icon: IconLucideBell,+ },+ ];+ const accountName = createMemo(() => {+ if (!auth.data) return "Signed Out";++ const name = userProfile.data?.name?.trim();+ if (name) return name;++ const email = userProfile.data?.email?.trim();+ if (email) return email;++ return "Signed In";+ });+ const accountImageUrl = createMemo(() => {+ const imageUrl = userProfile.data?.imageUrl?.trim();+ return imageUrl || null;+ });+ const accountLoading = createMemo(+ () =>+ auth.isLoading ||+ (!!auth.data && userProfile.isLoading && !userProfile.data),+ );+ const openDashboard = () => {+ void shell.open(+ new URL("/dashboard", clientEnv.VITE_SERVER_URL).toString(),+ );+ };const handleAuth = async () => {if (auth.data) {@@ -60,83 +166,75 @@ export default function Settings(props: RouteSectionProps) {};return (- <div class="flex-1 flex flex-row divide-x divide-gray-3 text-[0.875rem] leading-5 overflow-y-hidden">- <div class="flex flex-col h-full bg-gray-2">- <ul class="min-w-48 h-full p-2.5 space-y-1 text-gray-12">- <For- each={[- {- href: "general",- name: "General",- icon: IconCapSettings,- },- {- href: "hotkeys",- name: "Shortcuts",- icon: IconCapHotkeys,- },- {- href: "recordings",- name: "Recordings",- icon: IconLucideSquarePlay,- },- {- href: "screenshots",- name: "Screenshots",- icon: IconLucideImage,- },- {- href: "transcription",- name: "Transcription",- icon: IconCapCaptions,- },- {- href: "integrations",- name: "Integrations",- icon: IconLucideUnplug,- },- {- href: "license",- name: "License",- icon: IconLucideGift,- },- {- href: "experimental",- name: "Experimental",- icon: IconCapSettings,- },- {- href: "feedback",- name: "Feedback",- icon: IconLucideMessageSquarePlus,- },- {- href: "changelog",- name: "Changelog",- icon: IconLucideBell,- },- ].filter(Boolean)}+ <div class="cap-settings-shell flex-1 flex flex-row divide-x divide-gray-3 text-[0.875rem] leading-5 overflow-y-hidden">+ <div+ class="cap-settings-sidebar flex flex-col h-full bg-gray-2"+ data-tauri-drag-region+ >+ <div class="cap-settings-window-spacer" data-tauri-drag-region />+ <button+ type="button"+ class="cap-settings-profile"+ data-tauri-drag-region="false"+ onClick={openDashboard}+ >+ <Show+ when={!accountLoading()}+ fallback={+ <>+ <div class="cap-settings-profile-icon cap-settings-profile-skeleton cap-settings-profile-skeleton-avatar" />+ <div class="cap-settings-profile-copy">+ <span class="cap-settings-profile-skeleton cap-settings-profile-skeleton-title" />+ <span class="cap-settings-profile-skeleton cap-settings-profile-skeleton-subtitle" />+ </div>+ </>+ }>+ <Show+ when={accountImageUrl()}+ fallback={+ <div class="cap-settings-profile-icon">+ <IconLucideUserRound class="size-4" aria-hidden="true" />+ </div>+ }+ >+ {(imageUrl) => (+ <img+ class="cap-settings-profile-image"+ src={imageUrl()}+ alt=""+ draggable={false}+ />+ )}+ </Show>+ <div class="cap-settings-profile-copy">+ <p class="truncate text-[13px] text-gray-12">{accountName()}</p>+ <p class="truncate text-[11px] text-gray-10">Account</p>+ </div>+ </Show>+ </button>+ <ul class="cap-settings-nav min-w-48 h-full p-2.5 space-y-1 text-gray-12">+ <For each={settingsItems}>{(item) => (<li><Ahref={item.href}activeClass="bg-gray-5 pointer-events-none"- class="rounded-lg h-8 hover:bg-gray-3 text-[13px] px-2 flex flex-row items-center gap-1.5 transition-colors"+ class="cap-settings-nav-item rounded-lg h-8 hover:bg-gray-3 text-[13px] px-2 flex flex-row items-center gap-1.5 transition-colors">- <item.icon class="opacity-60 size-4" />+ <item.icon class="opacity-60 size-4" aria-hidden="true" /><span>{item.name}</span></A></li>)}</For></ul>- <div class="p-2.5 text-left flex flex-col">+ <div class="cap-settings-account p-2.5 text-left flex flex-col"><Show when={version()}>{(v) => (- <div class="mb-2 text-xs text-gray-11 flex flex-col items-start gap-0.5">+ <div class="mb-2 text-xs text-gray-11 flex flex-col items-start gap-1.5"><span>v{v()}</span>- <div class="flex flex-col items-start gap-0.5">+ <div class="flex flex-col items-start gap-1.5"><buttontype="button"class="text-gray-11 hover:text-gray-12 underline transition-colors"@@ -173,7 +271,7 @@ export default function Settings(props: RouteSectionProps) {)}</div></div>- <div class="overflow-y-hidden flex-1 animate-in">+ <div class="cap-settings-content overflow-y-hidden flex-1 animate-in min-w-0"><CapErrorBoundary><Suspense>{props.children}</Suspense></CapErrorBoundary>