Skip to content

Commit 0acd3e8

Browse files
committed
add edit note button to note toolbar
1 parent fbfe37b commit 0acd3e8

2 files changed

Lines changed: 74 additions & 4 deletions

File tree

src/app/features/notes/widgets/active-note.tsx

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { UserAccount, Note, Person } from "#shared/schema/user"
55
import { co } from "jazz-tools"
66
import { useIntl, T } from "#shared/intl/setup"
77
import { cn } from "#app/lib/utils"
8-
import { handleDeleteNote, handleTogglePin } from "../lib/note-actions"
8+
import {
9+
handleDeleteNote,
10+
handleEditNote,
11+
handleTogglePin,
12+
} from "../lib/note-actions"
913
import {
1014
ActiveNoteListItem,
1115
NoteImageGrid,
@@ -15,9 +19,25 @@ import { useExpanded } from "#app/hooks/use-expanded"
1519
import { NoteImageCarousel } from "../parts/note-image-carousel"
1620
import { SwipeableListItem } from "#app/components/swipeable-list-item"
1721
import { Collapsible } from "@base-ui/react/collapsible"
18-
import { Trash, PersonFill, Pin, ChevronUp } from "react-bootstrap-icons"
22+
import {
23+
Trash,
24+
PersonFill,
25+
Pin,
26+
ChevronUp,
27+
PencilSquare,
28+
} from "react-bootstrap-icons"
1929
import { Button } from "#shared/ui/button"
2030
import { ButtonGroup } from "#shared/ui/button-group"
31+
import {
32+
Dialog,
33+
DialogContent,
34+
DialogDescription,
35+
DialogHeader,
36+
DialogTitle,
37+
} from "#shared/ui/dialog"
38+
import { NoteForm } from "./inline-note-form"
39+
import { format } from "date-fns"
40+
import type { NoteFormValues } from "../lib/note-form-schema"
2141

2242
export { ActiveNote }
2343

@@ -39,6 +59,7 @@ function ActiveNote({
3959
let navigate = useNavigate()
4060
let [carouselOpen, setCarouselOpen] = useState(false)
4161
let [selectedImageIndex, setSelectedImageIndex] = useState(0)
62+
let [editDialogOpen, setEditDialogOpen] = useState(false)
4263
let { isExpanded, setExpanded } = useExpanded(note.$jazz.id)
4364

4465
function onOpenChange(open: boolean) {
@@ -67,6 +88,12 @@ function ActiveNote({
6788
})
6889
}
6990

91+
async function onEditNote(data: NoteFormValues) {
92+
if (!me.$isLoaded) return
93+
let result = await handleEditNote(me, ref, data, t)
94+
if (result.ok) setEditDialogOpen(false)
95+
}
96+
7097
return (
7198
<>
7299
<Collapsible.Root open={isExpanded} onOpenChange={onOpenChange}>
@@ -88,7 +115,11 @@ function ActiveNote({
88115
onAction: remove,
89116
}}
90117
>
91-
<Collapsible.Trigger nativeButton={false} render={<div />} className="flex-1">
118+
<Collapsible.Trigger
119+
nativeButton={false}
120+
render={<div />}
121+
className="flex-1"
122+
>
92123
<ActiveNoteListItem
93124
note={note}
94125
person={person}
@@ -101,7 +132,10 @@ function ActiveNote({
101132
</Collapsible.Trigger>
102133
</SwipeableListItem>
103134

104-
<Collapsible.Panel keepMounted className="h-(--collapsible-panel-height) overflow-hidden transition-[height] duration-300 ease-out data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none">
135+
<Collapsible.Panel
136+
keepMounted
137+
className="h-(--collapsible-panel-height) overflow-hidden transition-[height] duration-300 ease-out data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none"
138+
>
105139
<div
106140
className={cn(
107141
"flex items-center gap-3 pb-4",
@@ -115,6 +149,12 @@ function ActiveNote({
115149
<T k="note.showLess" />
116150
</span>
117151
</Button>
152+
<Button variant="outline" onClick={() => setEditDialogOpen(true)}>
153+
<PencilSquare />
154+
<span className="max-sm:sr-only">
155+
<T k="note.actions.edit" />
156+
</span>
157+
</Button>
118158
<Button variant="outline" onClick={togglePin}>
119159
<Pin />
120160
<span className="max-sm:sr-only">
@@ -167,6 +207,31 @@ function ActiveNote({
167207
open={carouselOpen}
168208
onClose={() => setCarouselOpen(false)}
169209
/>
210+
211+
<Dialog open={editDialogOpen} onOpenChange={setEditDialogOpen}>
212+
<DialogContent>
213+
<DialogHeader>
214+
<DialogTitle>
215+
<T k="note.edit.title" />
216+
</DialogTitle>
217+
<DialogDescription>
218+
<T k="note.edit.description" />
219+
</DialogDescription>
220+
</DialogHeader>
221+
<NoteForm
222+
note={note}
223+
defaultValues={{
224+
content: note.content,
225+
pinned: note.pinned ?? false,
226+
createdAt: note.createdAt
227+
? format(new Date(note.createdAt), "yyyy-MM-dd")
228+
: "",
229+
}}
230+
onSubmit={onEditNote}
231+
onCancel={() => setEditDialogOpen(false)}
232+
/>
233+
</DialogContent>
234+
</Dialog>
170235
</>
171236
)
172237
}

src/shared/intl/messages.notes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const baseNotesMessages = messages({
3939
"note.add.title": "Add a Note",
4040
"note.add.description":
4141
"Capture a moment, conversation, or experience you shared with {$person}.",
42+
"note.edit.title": "Edit Note",
43+
"note.edit.description": "Update the details of this note.",
4244
"note.actions.title": "Note Actions",
4345
"note.actions.description": "What would you like to do with this note?",
4446
"note.actions.edit": "Edit",
@@ -125,6 +127,9 @@ const deNotesMessages = translate(baseNotesMessages, {
125127
"note.add.title": "Notiz hinzufügen",
126128
"note.add.description":
127129
"Halte einen Moment, ein Gespräch oder eine gemeinsame Erfahrung mit {$person} fest.",
130+
"note.edit.title": "Notiz bearbeiten",
131+
"note.edit.description": "Aktualisiere die Details dieser Notiz.",
132+
128133
"note.actions.title": "Notizaktionen",
129134
"note.actions.description": "Was möchtest du mit dieser Notiz tun?",
130135
"note.actions.edit": "Bearbeiten",

0 commit comments

Comments
 (0)