@@ -5,7 +5,11 @@ import { UserAccount, Note, Person } from "#shared/schema/user"
55import { co } from "jazz-tools"
66import { useIntl , T } from "#shared/intl/setup"
77import { 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"
913import {
1014 ActiveNoteListItem ,
1115 NoteImageGrid ,
@@ -15,9 +19,25 @@ import { useExpanded } from "#app/hooks/use-expanded"
1519import { NoteImageCarousel } from "../parts/note-image-carousel"
1620import { SwipeableListItem } from "#app/components/swipeable-list-item"
1721import { 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"
1929import { Button } from "#shared/ui/button"
2030import { 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
2242export { 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}
0 commit comments