reactivitey for editability for note editing.

This commit is contained in:
2026-02-27 17:43:02 -06:00
parent bde9cc7047
commit f9de2cfd2b
2 changed files with 15 additions and 7 deletions
+8
View File
@@ -117,6 +117,14 @@ export const TaskEditor: Component<TaskEditorProps> = (props) => {
} }
}); });
// Make editor react to editable changes
createEffect(() => {
const e = editor();
if (e && props.editable !== undefined) {
e.setEditable(props.editable);
}
});
return ( return (
<> <>
<div <div
+7 -7
View File
@@ -18,7 +18,7 @@ export const NotepadView: Component<{
const [isLinking, setIsLinking] = createSignal(false); const [isLinking, setIsLinking] = createSignal(false);
const [linkSearchQuery, setLinkSearchQuery] = createSignal(""); const [linkSearchQuery, setLinkSearchQuery] = createSignal("");
const currentUserId = pb.authStore.model?.id; const currentUserId = () => pb.authStore.model?.id;
// Derived states // Derived states
const activeNote = createMemo(() => { const activeNote = createMemo(() => {
@@ -159,8 +159,8 @@ export const NotepadView: Component<{
</div> </div>
}> }>
{(note) => { {(note) => {
const isOwner = note().user === currentUserId; const isOwner = () => note().user === currentUserId();
const canEdit = isOwner || !note().isPrivate; const canEdit = () => isOwner() || !note().isPrivate;
return ( return (
<> <>
@@ -180,14 +180,14 @@ export const NotepadView: Component<{
class="text-3xl sm:text-4xl font-black tracking-tight bg-transparent border-none outline-none focus:ring-0 flex-1 placeholder:text-muted-foreground/30 px-0 min-w-0" class="text-3xl sm:text-4xl font-black tracking-tight bg-transparent border-none outline-none focus:ring-0 flex-1 placeholder:text-muted-foreground/30 px-0 min-w-0"
value={note().title} value={note().title}
placeholder="Note Title" placeholder="Note Title"
readOnly={!canEdit} readOnly={!canEdit()}
onBlur={(e) => { onBlur={(e) => {
const val = e.currentTarget.value.trim() || 'Untitled'; const val = e.currentTarget.value.trim() || 'Untitled';
if (val !== note().title) handleRenameNote(note().id, note().title, val); if (val !== note().title) handleRenameNote(note().id, note().title, val);
}} }}
/> />
<div class="flex items-center gap-2 shrink-0 pt-1"> <div class="flex items-center gap-2 shrink-0 pt-1">
<Show when={isOwner}> <Show when={isOwner()}>
<Button <Button
variant="ghost" variant="ghost"
size="sm" size="sm"
@@ -200,7 +200,7 @@ export const NotepadView: Component<{
</Button> </Button>
</Show> </Show>
<Show when={isOwner}> <Show when={isOwner()}>
<Button <Button
variant="ghost" variant="ghost"
size="icon" size="icon"
@@ -220,7 +220,7 @@ export const NotepadView: Component<{
<TaskEditor <TaskEditor
content={note().content} content={note().content}
onUpdate={(html) => handleUpdateContent(note().id, html)} onUpdate={(html) => handleUpdateContent(note().id, html)}
editable={canEdit} editable={canEdit()}
/> />
</div> </div>
</div> </div>