Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

update design of previous recordings (#374)

Brendan Allan52b987f10465
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/recordings.tsx b/apps/desktop/src/routes/(window-chrome)/settings/recordings.tsx
index 4e62a3621..709b1798e 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/recordings.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/recordings.tsx
@@ -1,15 +1,26 @@
-import { createMutation, createQuery } from "@tanstack/solid-query";
-import { For, ParentProps, Show, Suspense, createSignal } from "solid-js";
+import {
+ createMutation,
+ createQuery,
+ queryOptions,
+ useQueryClient,
+} from "@tanstack/solid-query";
import { convertFileSrc } from "@tauri-apps/api/core";
-
import {
- commands,
- events,
- RecordingMetaWithType,
- type RecordingMeta,
-} from "~/utils/tauri";
-import { trackEvent } from "~/utils/analytics";
+ createMemo,
+ createSignal,
+ For,
+ JSX,
+ ParentProps,
+ Show,
+} from "solid-js";
import Tooltip from "@corvu/tooltip";
+import { cx } from "cva";
+import { remove } from "@tauri-apps/plugin-fs";
+
+import { trackEvent } from "~/utils/analytics";
+import { commands, events, RecordingMetaWithType } from "~/utils/tauri";
+import { open } from "@tauri-apps/plugin-shell";
+import { ask } from "@tauri-apps/plugin-dialog";
type Recording = {
meta: RecordingMetaWithType;
@@ -19,29 +30,63 @@ type Recording = {
thumbnailPath: string;
};
+const Tabs = [
+ {
+ id: "all",
+ label: "Show all",
+ },
+ {
+ id: "instant",
+ icon: <IconCapInstant class="invert size-3 dark:invert-0" />,
+ label: "Instant",
+ },
+ {
+ id: "studio",
+ icon: <IconCapFilmCut class="invert size-3 dark:invert-0" />,
+ label: "Studio",
+ },
+] satisfies { id: string; label: string; icon?: JSX.Element }[];
+
+const recordingsQuery = queryOptions({
+ queryKey: ["recordings"],
+ queryFn: async () => {
+ const result = await commands.listRecordings().catch(() => [] as const);
+
+ const recordings = await Promise.all(
+ result.map(async (file) => {
+ const [id, path, meta] = file;
+ const thumbnailPath = `${path}/screenshots/display.jpg`;
+
+ return {
+ meta,
+ id,
+ path,
+ prettyName: meta.pretty_name,
+ thumbnailPath,
+ };
+ })
+ );
+ return recordings;
+ },
+});
+
export default function Recordings() {
- const recordings = createQuery(() => ({
- queryKey: ["recordings"],
- queryFn: async () => {
- const result = await commands.listRecordings().catch(() => [] as const);
-
- const recordings = await Promise.all(
- result.map(async (file) => {
- const [id, path, meta] = file;
- const thumbnailPath = `${path}/screenshots/display.jpg`;
-
- return {
- meta,
- id,
- path,
- prettyName: meta.pretty_name,
- thumbnailPath,
- };
- })
- );
- return recordings;
- },
- }));
+ const [activeTab, setActiveTab] = createSignal<(typeof Tabs)[number]["id"]>(
+ Tabs[0].id
+ );
+ const recordings = createQuery(() => recordingsQuery);
+
+ const filteredRecordings = createMemo(() => {
+ if (!recordings.data) {
+ return [];
+ }
+ if (activeTab() === "all") {
+ return recordings.data;
+ }
+ return recordings.data.filter(
+ (recording) => recording.meta.type === activeTab()
+ );
+ });
const handleRecordingClick = (recording: Recording) => {
trackEvent("recording_view_clicked", { recording_id: recording.id });
@@ -53,6 +98,11 @@ export default function Recordings() {
commands.openFilePath(path);
};
+ const handleCopyVideoToClipboard = (path: string) => {
+ trackEvent("recording_copy_clicked", { path });
+ commands.copyVideoToClipboard(path);
+ };
+
const handleOpenEditor = (id: string) => {
const normalizedPath = id.replace(/\\/g, "/");
const fileName = normalizedPath.split("/").pop() || "";
@@ -63,30 +113,51 @@ export default function Recordings() {
};
return (
- <div class="flex flex-col w-full h-full divide-y divide-[--gray-200] pt-1 pb-12">
- <div class="flex-1 overflow-y-auto">
- <ul class="p-[0.625rem] flex flex-col gap-[0.5rem] w-full text-[--text-primary]">
- <Show
- when={recordings.data && recordings.data.length > 0}
- fallback={
- <p class="text-center text-[--text-tertiary]">
- No recordings found
- </p>
- }
- >
- <For each={recordings.data}>
+ <div class="flex flex-col w-full h-full">
+ <Show
+ when={recordings.data && recordings.data.length > 0}
+ fallback={
+ <p class="text-center text-[--text-tertiary]">No recordings found</p>
+ }
+ >
+ <div class="p-4 border-b border-gray-300 border-dashed">
+ <div class="flex gap-3 items-center w-fit">
+ <For each={Tabs}>
+ {(tab) => (
+ <div
+ class={cx(
+ "flex gap-1.5 items-center transition-colors duration-200 p-2 px-3 border rounded-full",
+ activeTab() === tab.id
+ ? "bg-gray-300 cursor-default border-gray-300"
+ : "bg-transparent cursor-pointer hover:bg-gray-200 border-gray-200"
+ )}
+ onClick={() => setActiveTab(tab.id)}
+ >
+ {tab.icon && tab.icon}
+ <p class="text-xs text-gray-500">{tab.label}</p>
+ </div>
+ )}
+ </For>
+ </div>
+ </div>
+ <div class="flex flex-col flex-1 overflow-auto">
+ <ul class="p-4 flex flex-col gap-[0.5rem] w-full text-[--text-primary]">
+ <For each={filteredRecordings()}>
{(recording) => (
<RecordingItem
recording={recording}
onClick={() => handleRecordingClick(recording)}
onOpenFolder={() => handleOpenFolder(recording.path)}
onOpenEditor={() => handleOpenEditor(recording.path)}
+ onCopyVideoToClipboard={() =>
+ handleCopyVideoToClipboard(recording.path)
+ }
/>
)}
</For>
- </Show>
- </ul>
- </div>
+ </ul>
+ </div>
+ </Show>
</div>
);
}
@@ -96,24 +167,39 @@ function RecordingItem(props: {
onClick: () => void;
onOpenFolder: () => void;
onOpenEditor: () => void;
+ onCopyVideoToClipboard: () => void;
}) {
const [imageExists, setImageExists] = createSignal(true);
+ const type = () => props.recording.meta.type;
+ const firstLetterUpperCase = () =>
+ type().charAt(0).toUpperCase() + type().slice(1);
+
+ const queryClient = useQueryClient();
+
+ const deleteButton = () => (
+ <TooltipIconButton
+ tooltipText="Delete"
+ onClick={async () => {
+ if (!(await ask("Are you sure you want to delete this recording?")))
+ return;
+ await remove(props.recording.path, { recursive: true });
- const reupload = createMutation(() => ({
- mutationFn: () => {
- return commands.reuploadInstantVideo(props.recording.id);
- },
- }));
+ queryClient.refetchQueries(recordingsQuery);
+ }}
+ >
+ <IconCapTrash class="size-4" />
+ </TooltipIconButton>
+ );
return (
- <li class="w-full flex flex-row justify-between items-center p-2 hover:bg-gray-100 rounded">
- <div class="flex items-center">
+ <li class="flex flex-row justify-between items-center px-4 py-3 w-full rounded-xl transition-colors duration-200 hover:bg-gray-100">
+ <div class="flex gap-5 items-center">
<Show
when={imageExists()}
- fallback={<div class="w-8 h-8 bg-gray-400 mr-4 rounded" />}
+ fallback={<div class="mr-4 bg-gray-400 rounded size-11" />}
>
<img
- class="w-8 h-8 object-cover mr-4 rounded"
+ class="object-cover rounded size-12"
alt="Recording thumbnail"
src={`${convertFileSrc(
props.recording.thumbnailPath
@@ -121,59 +207,113 @@ function RecordingItem(props: {
onError={() => setImageExists(false)}
/>
</Show>
- <span>{props.recording.prettyName}</span>
+ <div class="flex flex-col gap-2">
+ <span>{props.recording.prettyName}</span>
+ {/** Tag */}
+ <div
+ class={cx(
+ "px-2 py-0.5 flex items-center gap-1.5 font-medium text-[11px] text-gray-500 rounded-full w-fit",
+ type() === "instant" ? "bg-blue-100" : "bg-gray-200"
+ )}
+ >
+ {type() === "instant" ? (
+ <IconCapInstant class="invert size-2.5 dark:invert-0" />
+ ) : (
+ <IconCapFilmCut class="invert size-2.5 dark:invert-0" />
+ )}
+ <p>{firstLetterUpperCase()}</p>
+ </div>
+ </div>
</div>
<div class="flex items-center">
- {import.meta.env.DEV &&
- props.recording.meta.type === "instant" &&
- props.recording.meta.sharing?.id && (
- <button
- onClick={() => {
- reupload.mutate();
- }}
- >
- Reupload
- </button>
- )}
- <TooltipIconButton
- tooltipText="Open project files"
- onClick={() => props.onOpenFolder()}
- >
- <IconLucideFolder class="size-5" />
- </TooltipIconButton>
- <TooltipIconButton
- tooltipText="Open in editor"
- onClick={() => props.onOpenEditor()}
- >
- <IconLucideEdit class="size-5" />
- </TooltipIconButton>
- <TooltipIconButton
- tooltipText="Show in recordings overlay"
- onClick={() => props.onClick()}
- >
- <IconLucideEye class="size-5" />
- </TooltipIconButton>
+ <Show when={type() === "studio"}>
+ <TooltipIconButton
+ tooltipText="Edit"
+ onClick={() => props.onOpenEditor()}
+ >
+ <IconLucideEdit class="size-4" />
+ </TooltipIconButton>
+ <TooltipIconButton
+ tooltipText="Show recordings overlay"
+ onClick={() => props.onClick()}
+ >
+ <IconLucideEye class="size-4" />
+ </TooltipIconButton>
+ <Show when={props.recording.meta.sharing}>
+ {(sharing) => (
+ <TooltipIconButton
+ tooltipText="Open link"
+ onClick={() => open(sharing().link)}
+ >
+ <IconCapLink class="size-4" />
+ </TooltipIconButton>
+ )}
+ </Show>
+ {deleteButton()}
+ </Show>
+ <Show when={type() === "instant"}>
+ {(_) => {
+ const reupload = createMutation(() => ({
+ mutationFn: () => {
+ return commands.reuploadInstantVideo(props.recording.id);
+ },
+ }));
+
+ return (
+ <>
+ <Show when={props.recording.meta.sharing}>
+ {(sharing) => (
+ <>
+ <TooltipIconButton
+ tooltipText="Reupload"
+ onClick={() => reupload.mutate()}
+ >
+ {reupload.isPending ? (
+ <IconLucideLoaderCircle class="animate-spin" />
+ ) : (
+ <IconLucideRotateCcw class="size-4" />
+ )}
+ </TooltipIconButton>
+ <TooltipIconButton
+ tooltipText="Open link"
+ onClick={() => open(sharing().link)}
+ >
+ <IconCapLink class="size-4" />
+ </TooltipIconButton>
+ </>
+ )}
+ </Show>
+ {deleteButton()}
+ </>
+ );
+ }}
+ </Show>
</div>
</li>
);
}
function TooltipIconButton(
- props: ParentProps<{ onClick: () => void; tooltipText: string }>
+ props: ParentProps<{
+ onClick: () => void;
+ tooltipText: string;
+ disabled?: boolean;
+ }>
) {
return (
<Tooltip>
<Tooltip.Trigger
- onClick={(e) => {
+ onClick={(e: MouseEvent) => {
e.stopPropagation();
props.onClick();
}}
- class="p-2 hover:bg-gray-200 rounded-full mr-2"
+ disabled={props.disabled}
+ class="p-2.5 mr-2 opacity-70 will-change-transform hover:opacity-100 rounded-full transition-all duration-200 hover:bg-gray-200 dark:hover:bg-gray-300"
>
{props.children}
</Tooltip.Trigger>
<Tooltip.Portal>
- <Tooltip.Content class="py-1 px-2 font-medium bg-gray-100 text-gray-400 border border-gray-300 text-xs rounded-lg animate-in fade-in slide-in-from-top-0.5">
+ <Tooltip.Content class="py-2 px-3 font-medium bg-gray-100 text-gray-500 border border-gray-200 text-xs rounded-lg animate-in fade-in slide-in-from-top-0.5">
{props.tooltipText}
</Tooltip.Content>
</Tooltip.Portal>
diff --git a/packages/ui-solid/icons/link.svg b/packages/ui-solid/icons/link.svg
new file mode 100644
index 000000000..9d699e586
--- /dev/null
+++ b/packages/ui-solid/icons/link.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
\ No newline at end of file
diff --git a/packages/ui-solid/src/auto-imports.d.ts b/packages/ui-solid/src/auto-imports.d.ts
index 923634066..511b1f959 100644
--- a/packages/ui-solid/src/auto-imports.d.ts
+++ b/packages/ui-solid/src/auto-imports.d.ts
@@ -31,6 +31,7 @@ declare global {
const IconCapInset: typeof import('~icons/cap/inset.jsx')['default']
const IconCapInstant: typeof import('~icons/cap/instant.jsx')['default']
const IconCapLayout: typeof import('~icons/cap/layout.jsx')['default']
+ const IconCapLink: typeof import('~icons/cap/link.jsx')['default']
const IconCapLogo: typeof import('~icons/cap/logo.jsx')['default']
const IconCapLogoFull: typeof import('~icons/cap/logo-full.jsx')['default']
const IconCapLogoFullDark: typeof import('~icons/cap/logo-full-dark.jsx')['default']
diff --git a/packages/ui-solid/tailwind.config.js b/packages/ui-solid/tailwind.config.js
index e36e5bbbe..52039fa0f 100644
--- a/packages/ui-solid/tailwind.config.js
+++ b/packages/ui-solid/tailwind.config.js
@@ -52,22 +52,24 @@ module.exports = {
20: "var(--red-transparent-20)",
},
},
- boxShadow: {
- s: "var(--shadow-s)",
- },
- keyframes: {
- "collapsible-down": {
- from: { height: 0 },
- to: { height: "var(--kb-collapsible-content-height)" },
+ extend: {
+ boxShadow: {
+ s: "var(--shadow-s)",
},
- "collapsible-up": {
- from: { height: "var(--kb-collapsible-content-height)" },
- to: { height: 0 },
+ keyframes: {
+ "collapsible-down": {
+ from: { height: 0 },
+ to: { height: "var(--kb-collapsible-content-height)" },
+ },
+ "collapsible-up": {
+ from: { height: "var(--kb-collapsible-content-height)" },
+ to: { height: 0 },
+ },
+ },
+ animation: {
+ "collapsible-down": "collapsible-down 0.2s ease-out",
+ "collapsible-up": "collapsible-up 0.2s ease-out",
},
- },
- animation: {
- "collapsible-down": "collapsible-down 0.2s ease-out",
- "collapsible-up": "collapsible-up 0.2s ease-out",
},
},
plugins: [