From 2913a4c5607eb4b0459bdb0f647dd1eda41d3cf9 Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 16 Jan 2026 14:09:47 +0100 Subject: [PATCH] Pages corrections pages missions --- app/pages/page.tsx | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/app/pages/page.tsx b/app/pages/page.tsx index 68cb67f..9c15caf 100644 --- a/app/pages/page.tsx +++ b/app/pages/page.tsx @@ -697,6 +697,59 @@ export default function CarnetPage() { } }; + const handleMissionSelect = (mission: { id: string; name: string }) => { + setSelectedMission(mission); + setSelectedMissionFile(null); + }; + + const handleMissionFileSelect = async (file: { key: string; name: string; path: string }) => { + if (!selectedMission) return; + + try { + const response = await fetch(`/api/missions/${selectedMission.id}/files`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ key: file.key }) + }); + + if (response.ok) { + const data = await response.json(); + setSelectedMissionFile({ + key: file.key, + content: data.content || '' + }); + } + } catch (error) { + console.error('Error fetching mission file content:', error); + } + }; + + const handleMissionFileSave = async (content: string) => { + if (!selectedMission || !selectedMissionFile) return; + + try { + const response = await fetch(`/api/missions/${selectedMission.id}/files`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + key: selectedMissionFile.key, + content + }) + }); + + if (!response.ok) { + throw new Error('Failed to save file'); + } + } catch (error) { + console.error('Error saving mission file:', error); + throw error; + } + }; + const handleNewNote = async () => { // For Diary and Health folders, check if a note exists for today if (selectedFolder === 'Diary' || selectedFolder === 'Health') {