Browse Source

fixed creator appointment time override issue

liontix 9 months ago
parent
commit
dee68c2ec7

+ 1 - 1
src/lib/modules/CreatorBaseInputs.svelte

@@ -21,7 +21,7 @@
 </div>
 
 <div class="field label border">
-    <select on:input={changeWeek} bind:value={selectedWeek} id="week">
+    <select bind:value={selectedWeek} on:input={changeWeek} id="week">
         <option value={202501}>01 KW (01.01.2024 - 05.01.2024)</option>
         <option value={202502}>02 KW (06.01.2024 - 12.01.2024)</option>
         <option value={202503}>03 KW (13.01.2024 - 19.01.2024)</option>

+ 0 - 4
src/lib/modules/CreatorInputs.svelte

@@ -15,10 +15,6 @@
         // creatorInputs.splice(index, 1);
         creatorInputs = creatorInputs.filter((_, index) => index !== indexToRemove);
     }
-
-    onMount(() => {
-        console.log(getTimeSlots("2025-03-02", "07:15", "09:00", 30))
-    })
 </script>
 
 <fieldset>

+ 3 - 0
src/lib/modules/CreatorTimeInputs.svelte

@@ -9,6 +9,9 @@
         weekdays = weekdays.map(item => 
             item.active ? item : { ...item, times: [] }
         );
+
+		console.log("updated weekdays");
+		console.log(weekdays);
     }
 
 </script>

+ 24 - 6
src/routes/user/creator/+page.svelte

@@ -3,11 +3,13 @@
 	import CreatorBaseInputs from '$lib/modules/CreatorBaseInputs.svelte';
 	import CreatorInputs from '$lib/modules/CreatorInputs.svelte';
 	import CreatorTimeInputs from '$lib/modules/CreatorTimeInputs.svelte';
+	import { tick } from 'svelte';
 
 	let creatorInputs: AppointmentInputs[] = [{ name: '', type: 'text' }];
 	let topic: string;
 	let location: string;
 	let selectedWeek: number = 202502;
+	let previousWeek: number = selectedWeek;
 	let duration: number = 15;
 	let renderTimeSelection: boolean = false;
 
@@ -28,14 +30,19 @@
 		}
 	];
 
-    function changeWeek() {
+    async function changeWeek() {
+		await tick();
         console.log("changed");
+		console.log(selectedWeek);
 		renderTimeSelection = false;
 
+		/*
 		const index = appointmentList.findIndex((entry) => entry.week === selectedWeek);
 		if (index !== -1 && selectedWeekAppointments !== undefined) {
 			appointmentList[index].appointments = selectedWeekAppointments;
+			//console.log(appointmentList[index].appointments);
 		}
+		*/
 
         const ix = appointmentList.findIndex((entry) => entry.week === selectedWeek);
 		if (ix === -1) {
@@ -52,12 +59,20 @@
                 ]
             }
             appointmentList = [... appointmentList, tmp];
-        }
+			selectedWeekAppointments = tmp.appointments;
+			console.log("not found");
+        } else {
+			console.log("test");
+			console.log(appointmentList);
+			selectedWeekAppointments = appointmentList.find(
+				(entry) => entry.week === selectedWeek
+			)?.appointments;
+			console.log("found and send entry");
+		}
 		
-        selectedWeekAppointments = appointmentList.find(
-            (entry) => entry.week === selectedWeek
-        )?.appointments;
+        
 		renderTimeSelection = true;
+		previousWeek = selectedWeek;
 		//setTimeout(() => renderTimeSelection = false, 2000);
     }
 
@@ -66,9 +81,12 @@
 	)?.appointments;
 
 	$: {
+		// deactivate when changing weeks to prevent override
 		const ix = appointmentList.findIndex((entry) => entry.week === selectedWeek);
-		if (ix !== -1 && selectedWeekAppointments !== undefined) {
+		if (ix !== -1 && selectedWeekAppointments !== undefined && previousWeek === selectedWeek) {
 			appointmentList[ix].appointments = selectedWeekAppointments;
+			console.log("updated");
+			console.log(appointmentList[ix].appointments);
 			//renderTimeSelection = true;
 			//setTimeout(() => renderTimeSelection = false, 2000);
 		}