1- import { memo , useCallback , useContext , useEffect , useState } from "react" ;
1+ import { memo , useCallback , useContext , useEffect , useRef , useState } from "react" ;
22import "./NoteManager.css" ;
33import { Button , Textarea } from "@fluffylabs/shared-ui" ;
44import { twMerge } from "tailwind-merge" ;
55import { validateMath } from "../../utils/validateMath" ;
66import { type ILocationContext , LocationContext } from "../LocationProvider/LocationProvider" ;
77import { type INotesContext , NotesContext } from "../NotesProvider/NotesProvider" ;
88import { LABEL_LOCAL } from "../NotesProvider/consts/labels" ;
9+ import type { IDecoratedNote } from "../NotesProvider/types/DecoratedNote" ;
910import type { IStorageNote } from "../NotesProvider/types/StorageNote" ;
1011import { Selection } from "../Selection/Selection" ;
1112import { type ISelectionContext , SelectionContext } from "../SelectionProvider/SelectionProvider" ;
@@ -27,7 +28,7 @@ const MemoizedNotesList = memo(NotesList);
2728function Notes ( ) {
2829 const [ noteContent , setNoteContent ] = useState ( "" ) ;
2930 const [ noteContentError , setNoteContentError ] = useState ( "" ) ;
30- const { locationParams } = useContext ( LocationContext ) as ILocationContext ;
31+ const { locationParams, setLocationParams } = useContext ( LocationContext ) as ILocationContext ;
3132 const { notesReady, activeNotes, notes, handleAddNote, handleDeleteNote, handleUpdateNote } = useContext (
3233 NotesContext ,
3334 ) as INotesContext ;
@@ -67,6 +68,17 @@ function Notes() {
6768 handleClearSelection ( ) ;
6869 } , [ noteContent , pageNumber , selectedBlocks , handleAddNote , handleClearSelection , locationParams ] ) ;
6970
71+ const locationRef = useRef ( { locationParams, setLocationParams } ) ;
72+ locationRef . current = { locationParams, setLocationParams } ;
73+
74+ const handleSelectNote = useCallback ( ( note : IDecoratedNote ) => {
75+ locationRef . current . setLocationParams ( {
76+ selectionStart : note . current . selectionStart ,
77+ selectionEnd : note . current . selectionEnd ,
78+ version : locationRef . current . locationParams . version ,
79+ } ) ;
80+ } , [ ] ) ;
81+
7082 useEffect ( ( ) => {
7183 if ( selectedBlocks . length === 0 ) {
7284 setNoteContent ( "" ) ;
@@ -97,6 +109,7 @@ function Notes() {
97109 notes = { notes }
98110 onEditNote = { handleUpdateNote }
99111 onDeleteNote = { handleDeleteNote }
112+ onSelectNote = { handleSelectNote }
100113 />
101114 </ div >
102115 ) ;
0 commit comments