Open source CapCut alternative.
TypeScript
fix(site): keep Library notes out of Notes
David Leff025ccbde19
diff --git a/site/src/cut/components/NotesView.tsx b/site/src/cut/components/NotesView.tsxindex aa2ba7d1..2a08f4a1 100644--- a/site/src/cut/components/NotesView.tsx+++ b/site/src/cut/components/NotesView.tsx@@ -5,7 +5,7 @@ import { useSearchParams } from "next/navigation";import { useQueryClient, type QueryClient } from "@tanstack/react-query";import { FolderPlus, Loader2, Plus, StickyNote } from "lucide-react";import { useTabTitle } from "@/cut/hooks/useTabTitle";-import { noteInLibraryFolder, noteRef, type NoteLocation } from "@/cut/lib/noteReference";+import { noteInLibraryFolder, noteInNotesFolder, noteRef, type NoteLocation } from "@/cut/lib/noteReference";import { setRefDragData, clearRefDrag } from "@/cut/lib/assetRef";import type { Residency } from "@/cut/lib/residency";import { Button } from "@/components/ui/button";@@ -216,7 +216,7 @@ export function NotesView({ library, ref }: Props = {}) {const shownFolders = folders.filter((f) => f.parentId === openFolder);const shown = list.filter((n) => library? noteInLibraryFolder(n, library.folderId, library.folderId === null ? undefined : library.residency)- : (n.folderId ?? null) === openFolder);+ : noteInNotesFolder(n, openFolder));// What the composer shows: the buffer while it belongs to the note the URL// names, and the stored note otherwise. A note nobody has typed into has no// buffer, and one still being written has no stored note.@@ -636,7 +636,7 @@ export function NotesView({ library, ref }: Props = {}) {onCreatingChange={setFolderCreating}statOf={(id) => ({count:- list.filter((n) => (n.folderId ?? null) === id).length ++ list.filter((n) => noteInNotesFolder(n, id)).length +folders.filter((f) => f.parentId === id).length,})}onOpen={gotoFolder}diff --git a/site/src/cut/lib/noteReference.test.ts b/site/src/cut/lib/noteReference.test.tsindex 74c3cba3..5db3236d 100644--- a/site/src/cut/lib/noteReference.test.ts+++ b/site/src/cut/lib/noteReference.test.ts@@ -1,6 +1,6 @@import { describe, expect, spyOn, test } from "bun:test";import { collectRefs, normalizeRef, refToken } from "@/cut/lib/assetRef";-import { noteInLibraryFolder, noteRef, parseNoteLink } from "@/cut/lib/noteReference";+import { noteInLibraryFolder, noteInNotesFolder, noteRef, parseNoteLink } from "@/cut/lib/noteReference";import { readNote, writeNoteFromTool, type CutNote } from "@/cut/lib/notes";import * as notes from "@/cut/lib/notes";import { backendFor } from "@/cut/lib/residency";@@ -23,6 +23,13 @@ describe("note references", () => {expect(noteInLibraryFolder(filed, "assets", residency === "cloud" ? "browser" : "cloud")).toBe(false);}});+ test("Library notes stay out of Notes", () => {+ expect(noteInNotesFolder({ folderId: null, libraryLocation: null }, null)).toBe(true);+ expect(noteInNotesFolder({ folderId: "plans" }, "plans")).toBe(true);+ expect(noteInNotesFolder({ folderId: "plans" }, null)).toBe(false);+ expect(noteInNotesFolder({ folderId: null, libraryLocation: { folderId: null, residency: "cloud" } }, null)).toBe(false);+ expect(noteInNotesFolder({ folderId: "plans", libraryLocation: { folderId: "assets", residency: "browser" } }, "plans")).toBe(false);+ });test("saved mentions retain identity through renaming and duplicate titles", () => {const ref = noteRef(note);const restored = normalizeRef(JSON.parse(JSON.stringify(ref)))!;diff --git a/site/src/cut/lib/noteReference.ts b/site/src/cut/lib/noteReference.tsindex c3127b2b..002a02a8 100644--- a/site/src/cut/lib/noteReference.ts+++ b/site/src/cut/lib/noteReference.ts@@ -16,6 +16,13 @@ export function noteInLibraryFolder(note: Pick<CutNote, "libraryLocation">, foldconst location = note.libraryLocation;return !!location && location.folderId === folderId && (!residency || location.residency === residency);}+// A note placed in the Library lives there alone; Notes shows only the rest.+export function noteInNotesFolder(note: Pick<CutNote, "folderId" | "libraryLocation">, folderId: string | null): boolean {+ if (note.libraryLocation) {+ return false;+ }+ return (note.folderId ?? null) === folderId;+}export const noteLibraryFoldersSchema = z.object({ residency: z.enum(["browser", "local", "cloud"]), folderIds: z.array(z.string().min(1).max(128)).max(10000) });export const noteReadSchema = z.object({ id: noteIdSchema.optional(), link: z.string().optional() });export const noteSaveSchema = z.object({