Skip to content

Commit

Permalink
feat: ✨ update data on mount
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed May 20, 2024
1 parent a3ccf41 commit 7da6ade
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/lib/components/availability/PersonalAvailability.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
itemsPerPage = columns;
}
const lastPage: number = Math.floor(($availabilityDates.length - 1) / itemsPerPage);
let lastPage: number = Math.floor(($availabilityDates.length - 1) / itemsPerPage);
const numPaddingDates: number =
$availabilityDates.length % itemsPerPage === 0
? 0
Expand All @@ -37,6 +37,7 @@
let currentPage = 0;
console.log(currentPage, lastPage);
let currentPageAvailability: (ZotDate | null)[];
let selectionState: SelectionStateType | null = null;
Expand Down Expand Up @@ -164,6 +165,8 @@
generalAvailability && generalAvailability.length > 0
? generalAvailability
: defaultMeetingDates;
lastPage = Math.floor(($availabilityDates.length - 1) / itemsPerPage);
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/stores/availabilityStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ZotDate } from "$lib/utils/ZotDate";

export const BLOCK_LENGTH: number = 15;

const getTimeFromHourMinuteString = (hourMinuteString: HourMinuteString): number => {
export const getTimeFromHourMinuteString = (hourMinuteString: HourMinuteString): number => {
const [hours, minutes] = hourMinuteString.split(":");

return Number(hours) * TimeConstants.MINUTES_PER_HOUR + Number(minutes);
Expand Down
2 changes: 2 additions & 0 deletions src/routes/availability/[slug]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const load: PageServerLoad = (async ({ locals, params }) => {
availability: user ? await getAvailability(user, params?.slug) : null,
meetingId: params?.slug as string | undefined,
defaultDates: (await getMeetingDates(params?.slug)) ?? [],
startTime: (await getExistingMeeting(params?.slug)).from_time,
endTime: (await getExistingMeeting(params?.slug)).to_time,
};
}) satisfies PageServerLoad;

Expand Down
19 changes: 19 additions & 0 deletions src/routes/availability/[slug]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<script lang="ts">
import { onMount } from "svelte";
import type { PageData } from "./$types";
import { enhance } from "$app/forms";
import { GroupAvailability, PersonalAvailability } from "$lib/components/availability";
import {
availabilityDates,
availabilityTimeBlocks,
generateSampleDates,
generateTimeBlocks,
getTimeFromHourMinuteString,
guestSession,
isEditingAvailability,
isStateUnsaved,
} from "$lib/stores/availabilityStores";
import { endTime, startTime } from "$lib/stores/meetingSetupStores";
import type { HourMinuteString } from "$lib/types/chrono";
import { getGeneralAvailability } from "$lib/utils/availability";
import { cn } from "$lib/utils/utils";
import CancelCircleOutline from "~icons/mdi/cancel-circle-outline";
Expand Down Expand Up @@ -48,6 +55,18 @@
$: mobileView = innerWidth < 768;
let form: HTMLFormElement;
onMount(async () => {
$startTime = data.startTime as HourMinuteString;
$endTime = data.endTime as HourMinuteString;
});
$: availabilityTimeBlocks.set(
generateTimeBlocks(
getTimeFromHourMinuteString($startTime),
getTimeFromHourMinuteString($endTime),
),
);
</script>

<svelte:window bind:innerWidth />
Expand Down

0 comments on commit 7da6ade

Please sign in to comment.