Implement share viewer (task 31)
- Makes actorId nullable in activity_log (migration 0010) with onDelete: set null so audit history survives user deletion; adds logShareActivity for anonymous mutations - Adds resolveShareToken return of householdId for downstream validation - Adds renderSharedView to EntityTypeRegistration; each module implements loadForShare (no-session bare queries) and renderSharedView - Calendar: CalendarSharedView (upcoming 90-day events) and EventSharedView (title/time/location/notes) - Lists: ListSharedView (client component with optimistic toggles via toggleShareListItem server action in lists/server/share-actions.ts) - Notes: NoteSharedView (title + body + updated date) - /app/s/[token]/page.tsx: resolves token, dispatches to loadForShare + renderSharedView, friendly error for invalid/expired tokens, noindex - Middleware /s/* exemption confirmed present (no change needed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
d5deee9a46
commit
39aa5704f9
@@ -0,0 +1,28 @@
|
||||
import { Pin } from "lucide-react";
|
||||
import type { NoteShareData } from "../server/share-queries";
|
||||
|
||||
export function NoteSharedView({ data }: { data: NoteShareData }) {
|
||||
const updatedAt = new Date(data.updatedAt).toLocaleDateString(undefined, {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-xl space-y-4 p-4">
|
||||
<header className="space-y-1">
|
||||
{data.pinned && (
|
||||
<span className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
<Pin className="size-3" />
|
||||
Pinned
|
||||
</span>
|
||||
)}
|
||||
<h1 className="text-2xl font-semibold">{data.title}</h1>
|
||||
<p className="text-xs text-muted-foreground">Updated {updatedAt}</p>
|
||||
</header>
|
||||
{data.body && (
|
||||
<p className="whitespace-pre-wrap text-sm leading-relaxed">{data.body}</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { ModuleManifest, WidgetContext } from "../_core/module";
|
||||
import { z } from "zod";
|
||||
import { listWidgetNotes, searchNotes } from "./server/queries";
|
||||
import { loadNoteForShare, type NoteShareData } from "./server/share-queries";
|
||||
import { NoteSharedView } from "./components/shared-view";
|
||||
|
||||
const notesWidgetConfigSchema = z.object({
|
||||
filter: z.enum(["pinned", "all"]),
|
||||
@@ -45,6 +47,8 @@ const manifest: ModuleManifest = {
|
||||
reminder: { canRemind: true },
|
||||
search: { search: searchNotes },
|
||||
resolveUrl: (id) => `/notes/${id}`,
|
||||
loadForShare: (id) => loadNoteForShare(id),
|
||||
renderSharedView: ({ data }) => <NoteSharedView data={data as NoteShareData} />,
|
||||
renderActivity: (entry) => {
|
||||
const title = entry.payload?.title as string | undefined;
|
||||
if (entry.action === "create") return `Created note${title ? ` "${title}"` : ""}`;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "@/lib/db";
|
||||
import { notes } from "../schema";
|
||||
|
||||
export type NoteShareData = {
|
||||
id: string;
|
||||
title: string;
|
||||
body: string;
|
||||
pinned: boolean;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export async function loadNoteForShare(id: string): Promise<NoteShareData | null> {
|
||||
const [note] = await db
|
||||
.select({
|
||||
id: notes.id,
|
||||
title: notes.title,
|
||||
body: notes.body,
|
||||
pinned: notes.pinned,
|
||||
updatedAt: notes.updatedAt,
|
||||
})
|
||||
.from(notes)
|
||||
.where(eq(notes.id, id))
|
||||
.limit(1);
|
||||
|
||||
if (!note) return null;
|
||||
|
||||
return {
|
||||
id: note.id,
|
||||
title: note.title,
|
||||
body: note.body,
|
||||
pinned: note.pinned,
|
||||
updatedAt: note.updatedAt.toISOString(),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user