Browse Source

extended change week function

liontix 9 months ago
parent
commit
02f6c5ade5
2 changed files with 21 additions and 7 deletions
  1. 5 5
      src/lib/modules/CreatorTimeInputs.svelte
  2. 16 2
      src/routes/user/creator/+page.svelte

+ 5 - 5
src/lib/modules/CreatorTimeInputs.svelte

@@ -3,6 +3,7 @@
 	import CreatorTimeRangeInput from "./CreatorTimeRangeInput.svelte";
 
     export let weekdays: WeekdayAppointment[] = [];
+	export let selectedWeek: number;
 
     $: {
         weekdays = weekdays.map(item => 
@@ -20,10 +21,9 @@
 				<input bind:checked={day.active} type="checkbox" />
 				<span>{day.name}</span>
 			</label>
-            {#if day.active}
-                <CreatorTimeRangeInput bind:timeRanges={day.times} />    
-            {/if}
-			
-		{/each}
+			{#if day.active}
+				<CreatorTimeRangeInput bind:timeRanges={day.times} />    
+			{/if}
+		{/each}	
 	</nav>
 </fieldset>

+ 16 - 2
src/routes/user/creator/+page.svelte

@@ -9,6 +9,7 @@
 	let location: string;
 	let selectedWeek: number = 202502;
 	let duration: number = 15;
+	let renderTimeSelection: boolean = false;
 
 	$: console.log(appointmentList);
 
@@ -29,6 +30,12 @@
 
     function changeWeek() {
         console.log("changed");
+		renderTimeSelection = false;
+
+		const index = appointmentList.findIndex((entry) => entry.week === selectedWeek);
+		if (index !== -1 && selectedWeekAppointments !== undefined) {
+			appointmentList[index].appointments = selectedWeekAppointments;
+		}
 
         const ix = appointmentList.findIndex((entry) => entry.week === selectedWeek);
 		if (ix === -1) {
@@ -46,10 +53,12 @@
             }
             appointmentList = [... appointmentList, tmp];
         }
-
+		
         selectedWeekAppointments = appointmentList.find(
             (entry) => entry.week === selectedWeek
         )?.appointments;
+		renderTimeSelection = true;
+		//setTimeout(() => renderTimeSelection = false, 2000);
     }
 
     let selectedWeekAppointments = appointmentList.find(
@@ -60,6 +69,8 @@
 		const ix = appointmentList.findIndex((entry) => entry.week === selectedWeek);
 		if (ix !== -1 && selectedWeekAppointments !== undefined) {
 			appointmentList[ix].appointments = selectedWeekAppointments;
+			//renderTimeSelection = true;
+			//setTimeout(() => renderTimeSelection = false, 2000);
 		}
 	}
 
@@ -72,8 +83,11 @@
 	<CreatorBaseInputs changeWeek={changeWeek} bind:topic bind:location bind:selectedWeek bind:duration />
 
 	{#if selectedWeekAppointments}
-		<CreatorTimeInputs bind:weekdays={selectedWeekAppointments} />
+		{#key renderTimeSelection}
+			<CreatorTimeInputs bind:weekdays={selectedWeekAppointments} bind:selectedWeek />	
+		{/key}
 	{/if}
+
 </fieldset>
 
 <CreatorInputs bind:creatorInputs />