diff --git a/src/lib/components/PointEditor.svelte b/src/lib/components/PointEditor.svelte index 02cfb5b..a5d17a4 100644 --- a/src/lib/components/PointEditor.svelte +++ b/src/lib/components/PointEditor.svelte @@ -1,8 +1,197 @@ \ No newline at end of file + $effect(() => { + onChange(); + }); + + // Modal controls + export function openModal() { + isOpen = true; + } + + function closeModal() { + isOpen = false; + onClose(); + } + + function handleDeletePoint(point: SavedPoint) { + deletePoint(point.id) + .then(() => { + $SavedPointsStore = $SavedPointsStore.filter((p) => p.id !== point.id); + SavedPointsStore.set($SavedPointsStore); + resetForm(); + addToast({ + header: "Точка удалена", + body: `Точка "${point.name}" успешно удалена.`, + color: "success", + }); + }) + .catch((error) => { + showAlert(`Ошибка при удалении точки: ${error.message}`); + console.error("Ошибка при удалении точки:", error); + }); + } + + function handleSavePoint() { + updatePoint(selectedPoint) + .then((updatedPoint) => { + $SavedPointsStore = $SavedPointsStore.map((p) => (p.id === updatedPoint.id ? updatedPoint : p)); + SavedPointsStore.set($SavedPointsStore); + resetForm(); + addToast({ + header: "Точка обновлена", + body: `Точка "${updatedPoint.name}" успешно обновлена.`, + color: "success", + }); + }) + .catch((error) => { + showAlert(`Ошибка при обновлении точки: ${error.message}`); + }); + } + + export function showAlert(message: string) { + isAlertVisible = true; + alertText = message; + } + + export function hideAlert() { + isAlertVisible = false; + alertText = ""; + } + + export function resetForm() { + hideAlert(); + closeModal(); + } + + + + + + + + { + isConfirmationVisible = false; + handleDeletePoint(selectedPoint); + }} + oncancel={() => { + isConfirmationVisible = false; + }} +> +

Вы уверены, что хотите удалить эту точку?

+
\ No newline at end of file diff --git a/src/lib/components/PointListModal.svelte b/src/lib/components/PointListModal.svelte index 51e0e34..b47abc9 100644 --- a/src/lib/components/PointListModal.svelte +++ b/src/lib/components/PointListModal.svelte @@ -16,16 +16,24 @@ import { addToast } from "$lib/components/Toast.svelte"; import type { SavedPoint } from "$lib/types"; import { SavedPointsStore } from "$lib/stores"; + import ConfirmationPrompt from "./ConfirmationPrompt.svelte"; import { getSavedPoints, savePoint, updatePoint, deletePoint } from "$lib/api/points"; // Props - let { isOpen = $bindable(false), onClose = () => {}, onChange = () => {} } = $props(); + let { + isOpen = $bindable(false), + onClose = () => {}, + onChange = () => {}, + point = null, + coordinates = { id: 0, name: "", lat: 0, lon: 0, alt: 0 }, + } = $props(); // Runes - let selectedPoint = $state(null); - let newPoint = $state({ id: 0, name: "", lat: 0, lon: 0, alt: 0 }); + let selectedPoint = $state(point); + let newPoint = $state(coordinates as SavedPoint); let isEditing = $state(false); let isAlertVisible = $state(false); + let isConfirmationVisible = $state(false); let alertText = $state(""); // Table handler @@ -59,7 +67,13 @@ isEditing = true; } - function handleDeletePoint(point: SavedPoint) { + function confirmDeletePoint(point: SavedPoint) { + selectedPoint = point; + isConfirmationVisible = true; + } + + function handleDeletePoint(point: SavedPoint | null) { + if (!point) return; deletePoint(point.id) .then(() => { $SavedPointsStore = $SavedPointsStore.filter((p) => p.id !== point.id); @@ -129,7 +143,7 @@ } - + + + { + isConfirmationVisible = false; + handleDeletePoint(selectedPoint); + }} + oncancel={() => { + isConfirmationVisible = false; + }} +> +

Вы уверены, что хотите удалить эту точку?

+
\ No newline at end of file diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte index a48518c..d027858 100644 --- a/src/routes/login/+page.svelte +++ b/src/routes/login/+page.svelte @@ -86,7 +86,7 @@ Войти {/if} - Назад + Назад diff --git a/src/routes/user/account/+page.svelte b/src/routes/user/account/+page.svelte index 7f58e31..7b1f76f 100644 --- a/src/routes/user/account/+page.svelte +++ b/src/routes/user/account/+page.svelte @@ -116,7 +116,7 @@
-
+