From 88158610af9af53d3dad4e6bf6521f21a7069bf0 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 20 May 2026 11:43:17 +0000 Subject: [PATCH] Add notes fetch --- src/frontend/lib/enums/ApiEndpoints.tsx | 1 + .../src/components/editors/NotesEditor.tsx | 32 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/frontend/lib/enums/ApiEndpoints.tsx b/src/frontend/lib/enums/ApiEndpoints.tsx index addb35378b..a035175bf0 100644 --- a/src/frontend/lib/enums/ApiEndpoints.tsx +++ b/src/frontend/lib/enums/ApiEndpoints.tsx @@ -240,6 +240,7 @@ export enum ApiEndpoints { error_report_list = 'error-report/', project_code_list = 'project-code/', custom_unit_list = 'units/', + note_list = 'note/', notes_image_upload = 'notes-image-upload/', email_list = 'admin/email/', email_test = 'admin/email/test/', diff --git a/src/frontend/src/components/editors/NotesEditor.tsx b/src/frontend/src/components/editors/NotesEditor.tsx index 9658120819..9350da9150 100644 --- a/src/frontend/src/components/editors/NotesEditor.tsx +++ b/src/frontend/src/components/editors/NotesEditor.tsx @@ -31,11 +31,38 @@ export default function NotesEditor({ editable?: boolean; setDirtyCallback?: (dirty: boolean) => void; }>) { + const api = useApi(); const user = useUserState(); + const [selectedNote, setSelectedNote] = useState( + undefined + ); + + // Fetch the available notes for the given model type and ID + const notesQuery = useQuery({ + queryKey: ['notes', modelType, modelId], + queryFn: async () => { + return api + .get(apiUrl(ApiEndpoints.note_list), { + params: { + model_id: modelId, + model_type: modelType + } + }) + .then((response) => response.data ?? []); + }, + staleTime: 0, + refetchOnWindowFocus: false, + refetchOnMount: true, + enabled: !!modelId && !!modelType + }); + const canEdit = useMemo( - () => user.hasChangePermission(modelType), - [user, modelType] + () => + user.hasChangePermission(modelType) && + notesQuery.isFetched && + notesQuery.isSuccess, + [user, modelType, notesQuery] ); const editor = useCreateBlockNote(); @@ -46,6 +73,7 @@ export default function NotesEditor({