fix: bugs
Some checks failed
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 41s
CI / build (push) Failing after 11s
Format / formatting (pull_request) Successful in 6s

This commit is contained in:
2025-04-29 00:28:56 +02:00
9 changed files with 104 additions and 80 deletions

View File

@ -95,7 +95,7 @@ const props = defineProps<{
title: number;
titleText: string;
description: string;
isAdmin: number;
isAdmin: boolean;
}>();
const IS_MOCK_MODE = false;
@ -107,18 +107,23 @@ const editedDescriptions = ref<SectionCell[]>([]);
const isEditing = ref<boolean[]>([]);
function getCurrentFormattedDate(): string {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0'); // +1 car janvier = 0
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, "0"); // +1 car janvier = 0
const day = String(now.getDate()).padStart(2, "0");
const hours = String(now.getHours()).padStart(2, "0");
const minutes = String(now.getMinutes()).padStart(2, "0");
return `${year}-${month}-${day} ${hours}:${minutes}`;
return `${year}-${month}-${day} ${hours}:${minutes}`;
}
onMounted(() => {
fetchData(props.projectId, props.title, getCurrentFormattedDate(), IS_MOCK_MODE);
fetchData(
props.projectId,
props.title,
getCurrentFormattedDate(),
IS_MOCK_MODE
);
});
// Fonctions
@ -137,10 +142,14 @@ const saveEdit = (index: number) => {
editedDescriptions.value[index].contentSectionCell;
isEditing.value[index] = false;
if (!IS_MOCK_MODE){
addSectionCell(currentDescriptions.value[index],
if (!IS_MOCK_MODE) {
addSectionCell(
currentDescriptions.value[index],
(response) => {
console.log("Modification enregistrée avec succès :", response.data);
console.log(
"Modification enregistrée avec succès :",
response.data
);
},
(error) => {
console.error("Erreur lors de l'enregistrement :", error);
@ -149,7 +158,6 @@ const saveEdit = (index: number) => {
}
};
const handleClick = () => {
if (expanded.value) {
const editingInProgress = isEditing.value.some((edit) => edit);
@ -165,11 +173,13 @@ const handleClick = () => {
const handleFetchSuccess = (sectionCells: SectionCell[]) => {
currentDescriptions.value = sectionCells;
editedDescriptions.value = sectionCells.map(
(cell) => new SectionCell({
idSectionCell: cell.idSectionCell,
sectionId: cell.sectionId,
contentSectionCell: cell.contentSectionCell,
modificationDate: cell.modificationDate, })
(cell) =>
new SectionCell({
idSectionCell: cell.idSectionCell,
sectionId: cell.sectionId,
contentSectionCell: cell.contentSectionCell,
modificationDate: cell.modificationDate,
})
);
isEditing.value = Array(sectionCells.length).fill(false);
};
@ -178,28 +188,43 @@ const handleFetchError = (error: unknown) => {
console.error("Erreur lors de la récupération des données :", error);
};
const fetchData = async ( projectId: number, title: number, date: string, useMock = false ) => {
const fetchData = async (
projectId: number,
title: number,
date: string,
useMock = false
) => {
try {
if (useMock) {
const responseData = await mockFetch(projectId, title, date);
handleFetchSuccess(responseData);
} else {
await new Promise<void>((resolve, reject) => {
getSectionCellsByDate( projectId, title, date,
getSectionCellsByDate(
projectId,
title,
date,
(response: AxiosResponse) => {
const data = response.data;
if (Array.isArray(data) && data.length > 0) {
const sectionCells = data.map((cellData) => new SectionCell({
idSectionCell: cellData.idSectionCell,
sectionId: cellData.sectionId,
contentSectionCell: cellData.contentSectionCell,
modificationDate:
cellData.modificationDate, })
const sectionCells = data.map(
(cellData) =>
new SectionCell({
idSectionCell: cellData.idSectionCell,
sectionId: cellData.sectionId,
contentSectionCell:
cellData.contentSectionCell,
modificationDate:
cellData.modificationDate,
})
);
handleFetchSuccess(sectionCells);
} else {
console.warn( "Aucune donnée reçue ou format inattendu :", data);
console.warn(
"Aucune donnée reçue ou format inattendu :",
data
);
}
resolve();
@ -216,7 +241,11 @@ const fetchData = async ( projectId: number, title: number, date: string, useMoc
}
};
const mockFetch = async ( projectId: number, title: number, date: string ): Promise<SectionCell[]> => {
const mockFetch = async (
projectId: number,
title: number,
date: string
): Promise<SectionCell[]> => {
console.log(
`Mock fetch pour projectId: ${projectId}, title: ${title}, date: ${date}`
);
@ -272,8 +301,13 @@ const mockFetch = async ( projectId: number, title: number, date: string ): Prom
// On crée des instances de SectionCell
const result = section.map(
(txt, index) => new SectionCell({ idSectionCell: index + 1, sectionId: title,
contentSectionCell: txt, modificationDate: date, })
(txt, index) =>
new SectionCell({
idSectionCell: index + 1,
sectionId: title,
contentSectionCell: txt,
modificationDate: date,
})
);
return new Promise<SectionCell[]>((resolve) => {