Pages corrections pages missions

This commit is contained in:
alma 2026-01-16 14:09:47 +01:00
parent b230da2a43
commit 2913a4c560

View File

@ -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 () => { const handleNewNote = async () => {
// For Diary and Health folders, check if a note exists for today // For Diary and Health folders, check if a note exists for today
if (selectedFolder === 'Diary' || selectedFolder === 'Health') { if (selectedFolder === 'Diary' || selectedFolder === 'Health') {