feat: edit-mode added, to test it use the fake api in the 'fake_data' folder

This commit is contained in:
ALAMI Adnane 2025-03-19 09:48:04 +01:00
parent f48b570494
commit 6de38a9725

View File

@ -1,88 +1,181 @@
<template> <template>
<div :class="['cell', { expanded }]" <div :class="['cell', { expanded }]" @click="handleClick">
@click="toggleExpand" <h3>{{ title }}</h3>
:style="{ justifyContent: expanded ? 'flex-start' : 'center' }"> <!-- Looking for finding a way
to make this style in the toggleExpand event -->
<h3>{{ title }}</h3> <!-- Mode affichage -->
<template v-if="!isEditing">
<p>{{ currentDescription }}</p> <p>{{ currentDescription }}</p>
</div> <button v-if="expanded" @click.stop="startEditing" class="edit-button">Éditer</button>
</template>
<!-- Mode édition -->
<template v-else>
<textarea v-model="editedDescription" class="edit-input"></textarea>
<div class="button-container">
<button @click.stop="saveEdit" class="save-button">Enregistrer</button>
<button @click.stop="cancelEdit" class="cancel-button">Annuler</button>
</div>
</template>
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, defineProps, onMounted } from "vue"; import { ref, defineProps } from "vue";
import axios from "axios"; import axios from "axios";
const props = defineProps<{ const props = defineProps<{
title: string; title: string;
description: string; description: string;
}>(); }>();
const expanded = ref(false); const expanded = ref(false);
const isEditing = ref(false);
const currentDescription = ref(props.description); const currentDescription = ref(props.description);
const editedDescription = ref(props.description);
const fetchData = async () => { const fetchData = async () => {
try { try {
const response = await axios.get("http://localhost:5000/data"); // Update the URL if needed const response = await axios.get("http://localhost:5000/data"); // Met à jour l'URL
currentDescription.value = response.data[0].canva_data; if (response.data.length > 0) {
currentDescription.value = response.data[0].canva_data;
editedDescription.value = response.data[0].canva_data;
} else {
console.warn("Aucune donnée reçue.");
}
} catch (error) { } catch (error) {
console.error("Erreur lors de la récupération des données :", error); console.error("Erreur lors de la récupération des données :", error);
} }
}; };
const toggleExpand = async () => { const handleClick = async () => {
if (!expanded.value) { if (!expanded.value) {
await fetchData(); await fetchData();
} else { } else if (!isEditing.value) {
currentDescription.value = props.description; currentDescription.value = props.description;
editedDescription.value = props.description;
}
if (!isEditing.value) {
expanded.value = !expanded.value;
} }
expanded.value = !expanded.value;
}; };
const startEditing = () => {
isEditing.value = true;
};
const saveEdit = () => {
currentDescription.value = editedDescription.value;
isEditing.value = false;
};
const cancelEdit = () => {
editedDescription.value = currentDescription.value;
isEditing.value = false;
};
</script> </script>
<style scoped> <style scoped>
@import "@/components/canvas/style-project.css"; @import "@/components/canvas/style-project.css";
.cell { .cell {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
text-align: center; text-align: center;
transition: all 0.3s ease; transition: all 0.3s ease;
cursor: pointer; cursor: pointer;
box-shadow: 0 4px 5px rgba(0, 0, 0, 0.1); box-shadow: 0 4px 5px rgba(0, 0, 0, 0.1);
} }
.expanded-content {
justify-content: flex-start !important;
}
.cell:not(.expanded):hover { .cell:not(.expanded):hover {
transform: scale(1.05); transform: scale(1.05);
box-shadow: 0 8px 9px rgba(0, 0, 0, 0.2); box-shadow: 0 8px 9px rgba(0, 0, 0, 0.2);
} }
.cell h3 { .cell h3 {
font-size: 20px; font-size: 20px;
font-weight: 500; font-weight: 500;
/*margin-bottom: 10px;*/ /*margin-bottom: 10px;*/
} }
.cell p { .cell p {
font-size: 14px; font-size: 14px;
color: #666; color: #666;
} }
.expanded { .expanded {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
background: white; background: white;
z-index: 10; z-index: 10;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: flex-start;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
} }
.edit-input {
width: 80%;
height: 100px;
font-size: 16px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
margin-top: 10px;
}
.button-container {
position: absolute;
bottom: 20px;
right: 20px;
display: flex;
gap: 10px;
}
.edit-button, .save-button, .cancel-button {
padding: 10px 15px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background 0.3s ease;
font-size: 16px;
}
.edit-button {
background-color: #007bff;
color: white;
}
.save-button {
background-color: #28a745;
color: white;
}
.cancel-button {
background-color: #dc3545;
color: white;
}
.edit-button:hover {
background-color: #0056b3;
}
.save-button:hover {
background-color: #218838;
}
.cancel-button:hover {
background-color: #c82333;
}
</style> </style>