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,16 +1,26 @@
<template>
<div :class="['cell', { expanded }]"
@click="toggleExpand"
:style="{ justifyContent: expanded ? 'flex-start' : 'center' }"> <!-- Looking for finding a way
to make this style in the toggleExpand event -->
<div :class="['cell', { expanded }]" @click="handleClick">
<h3>{{ title }}</h3>
<!-- Mode affichage -->
<template v-if="!isEditing">
<p>{{ currentDescription }}</p>
<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>
<script setup lang="ts">
import { ref, defineProps, onMounted } from "vue";
import { ref, defineProps } from "vue";
import axios from "axios";
const props = defineProps<{
@ -19,28 +29,51 @@ const props = defineProps<{
}>();
const expanded = ref(false);
const isEditing = ref(false);
const currentDescription = ref(props.description);
const editedDescription = ref(props.description);
const fetchData = async () => {
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
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) {
console.error("Erreur lors de la récupération des données :", error);
}
};
const toggleExpand = async () => {
const handleClick = async () => {
if (!expanded.value) {
await fetchData();
} else {
} else if (!isEditing.value) {
currentDescription.value = props.description;
editedDescription.value = props.description;
}
if (!isEditing.value) {
expanded.value = !expanded.value;
}
};
</script>
const startEditing = () => {
isEditing.value = true;
};
const saveEdit = () => {
currentDescription.value = editedDescription.value;
isEditing.value = false;
};
const cancelEdit = () => {
editedDescription.value = currentDescription.value;
isEditing.value = false;
};
</script>
<style scoped>
@import "@/components/canvas/style-project.css";
@ -56,6 +89,10 @@ const toggleExpand = async () => {
box-shadow: 0 4px 5px rgba(0, 0, 0, 0.1);
}
.expanded-content {
justify-content: flex-start !important;
}
.cell:not(.expanded):hover {
transform: scale(1.05);
box-shadow: 0 8px 9px rgba(0, 0, 0, 0.2);
@ -82,7 +119,63 @@ const toggleExpand = async () => {
z-index: 10;
display: flex;
align-items: center;
justify-content: center;
justify-content: flex-start;
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>