diff --git a/src/components/Dashboard/common/NotesPanel.jsx b/src/components/Dashboard/common/NotesPanel.jsx index 66c7689..2ac574e 100644 --- a/src/components/Dashboard/common/NotesPanel.jsx +++ b/src/components/Dashboard/common/NotesPanel.jsx @@ -25,12 +25,14 @@ const { Text } = Typography const NotesPanel = ({ _id, type }) => { const [newNoteOpen, setNewNoteOpen] = useState(false) const [loading, setLoading] = useState(true) - const [initialized, setInitialized] = useState(false) const [error, setError] = useState(null) const [notes, setNotes] = useState(null) const [expandedNotes, setExpandedNotes] = useState({}) const subscribeToObjectTypeUpdatesRef = useRef(null) + const notesIdRef = useRef(null) + const notesTypeRef = useRef(null) + const { token } = useContext(AuthContext) const { fetchNotes, connected, subscribeToObjectTypeUpdates } = useContext(ApiServerContext) @@ -50,6 +52,7 @@ const NotesPanel = ({ _id, type }) => { const generateNotes = useCallback( async (id) => { + setLoading(true) const notesData = await fetchData(id) setLoading(false) @@ -108,11 +111,16 @@ const NotesPanel = ({ _id, type }) => { }, [_id, subscribeToObjectTypeUpdates, connected, handleReloadData]) useEffect(() => { - if (connected == true && token != null && !initialized) { + if ( + connected == true && + token != null && + (_id != notesIdRef.current || type != notesTypeRef.current) + ) { handleReloadData() - setInitialized(true) + notesIdRef.current = _id + notesTypeRef.current = type } - }, [token, handleReloadData, initialized, connected]) + }, [token, handleReloadData, connected, _id, type]) const actionItems = { items: [