Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My availability tab #20

Merged
merged 28 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6713f05
feat: ✨ create availability page
adi-lux Jan 8, 2024
3ca230b
feat: ✨ represent availability as a class
adi-lux Jan 11, 2024
88c2cd4
feat: ✨ create a store for availability and establish representation
adi-lux Jan 11, 2024
a9eecc4
refactor: ♻️ ✨ fix up the store representation of availability
adi-lux Jan 11, 2024
72f2d07
Merge branch 'main' into my-availability-tab
adi-lux Jan 15, 2024
55f9556
feat: ✨ initially created ZotDate class
adi-lux Jan 17, 2024
0c27264
feat: ✨ added helper functions to ZotDate class
adi-lux Jan 17, 2024
fbc577d
refactor: ♻️ allowed strings and dates in constructor, commented on f…
adi-lux Jan 17, 2024
380626f
feat: ✨ added CalendarDay functions to ZotDate
adi-lux Jan 18, 2024
bbd40ff
refactor: ♻️ corrected inaccurate function name
adi-lux Jan 18, 2024
c0130ee
refactor: ♻️ change calendar component to use ZotDate class
seancfong Jan 18, 2024
8027ca6
Merge branch 'my-availability-tab' of https://github.com/icssc/ZotMee…
seancfong Jan 18, 2024
3be46ba
refactor: ♻️ update method call of generating calendar days to new si…
seancfong Jan 18, 2024
68b3557
fix: 🐛 fixed incorrect constructor implementation
adi-lux Jan 19, 2024
76ea4ad
fix: 🐛 attempted fixing ZotDate availability error
adi-lux Jan 21, 2024
817166f
refactor: ♻️ clean up ZotDate class
seancfong Jan 25, 2024
57720d6
feat: ✨ add personal availability page
seancfong Jan 25, 2024
186252b
feat: ✨ add selection interaction to availability page
seancfong Jan 25, 2024
9108ab5
feat: ✨ add desktop mouse interaction with availability
seancfong Jan 25, 2024
ff8fc33
feat: ✨ add mobile interaction for availability
seancfong Jan 26, 2024
29d4637
fix: 🐛 correct 0AM text to display as 12AM instead
seancfong Jan 26, 2024
1e2463f
refactor: ♻️ add docstrings for new functions and methods
seancfong Jan 26, 2024
56108c9
feat: ✨ add pagination to mobile availability dates
seancfong Jan 26, 2024
2ced7a6
feat: ✨ added availability and related stores
seancfong Jan 28, 2024
df05f61
feat: ✨ sync availability component with store
seancfong Jan 28, 2024
221dc0d
feat: ✨ improve pagination spacing for partially-filled availability …
seancfong Jan 28, 2024
1be117a
refactor: ♻️ add type annotations to availability component states
seancfong Jan 28, 2024
0b0ca5f
chore: 🔧 remove old availability class that was migrated to ZotDate
seancfong Jan 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/lib/components/Calendar/Calendar.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<script lang="ts">
import CalendarBody from "$lib/components/Calendar/CalendarBody.svelte";
import { Day } from "$lib/components/Calendar/CalendarDay";
import { selectedDays } from "$lib/stores/calendarStores";
import { WEEKDAYS, MONTHS } from "$lib/types/chrono";
import { ZotDate } from "$lib/utils/ZotDate";

let today: Date = new Date();
let currentMonth: number = today.getMonth();
let currentYear: number = today.getFullYear();
let calendarDays: Day[][] = Day.generateCalendarDays(currentMonth, currentYear, $selectedDays);
let calendarDays: ZotDate[][] = ZotDate.generateZotDates(
currentMonth,
currentYear,
$selectedDays,
);

$: monthName = MONTHS[currentMonth];

Expand All @@ -32,13 +36,13 @@
};

const updateCalendar = (): void => {
calendarDays = Day.generateCalendarDays(currentMonth, currentYear, $selectedDays);
calendarDays = ZotDate.generateZotDates(currentMonth, currentYear, $selectedDays);
};
</script>

<div class="max-w-xl p-5 mx-auto bg-surface-50">
<p class="text-center h3">{monthName} {currentYear}</p>
<div class="flex items-center justify-between pt-5 overflow-x-auto">
<div class="mx-auto max-w-xl bg-surface-50 p-5">
<p class="h3 text-center">{monthName} {currentYear}</p>
<div class="flex items-center justify-between overflow-x-auto pt-5">
<button on:click={decrementMonth} class="p-3 pl-1">
<span class="text-3xl text-gray-500">&lsaquo;</span>
</button>
Expand All @@ -47,16 +51,16 @@
<tr>
{#each WEEKDAYS as dayOfWeek}
<th>
<div class="flex justify-center w-full">
<p class="text-base font-medium text-center text-gray-800 dark:text-gray-100">
<div class="flex w-full justify-center">
<p class="text-center text-base font-medium text-gray-800 dark:text-gray-100">
{dayOfWeek}
</p>
</div>
</th>
{/each}
</tr>
</thead>
<CalendarBody {calendarDays} {updateCalendar} />
<CalendarBody {calendarDays} {updateCalendar} {currentMonth} />
</table>
<button on:click={incrementMonth} class="p-3 pr-1">
<span class="text-3xl text-gray-500">&rsaquo;</span>
Expand Down
19 changes: 10 additions & 9 deletions src/lib/components/Calendar/CalendarBody.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<script lang="ts">
import CalendarBodyDay from "$lib/components/Calendar/CalendarBodyDay.svelte";
import { Day } from "$lib/components/Calendar/CalendarDay";
import { updateSelectedRange } from "$lib/stores/calendarStores";
import { ZotDate } from "$lib/utils/ZotDate";

export let calendarDays: Day[][];
export let calendarDays: ZotDate[][];
export let updateCalendar: () => void = () => {};
export let currentMonth: number;

let startDaySelection: Day | null = null;
let endDaySelection: Day | null = null;
let startDaySelection: ZotDate | null = null;
let endDaySelection: ZotDate | null = null;

/**
* Updates the current highlight selection whenever a mobile user drags on the calendar
Expand All @@ -24,7 +25,7 @@
const touchingDay = touchingElement.getAttribute("data-day");

if (startDaySelection && touchingDay) {
endDaySelection = Day.extractDayFromElement(touchingElement);
endDaySelection = ZotDate.extractDayFromElement(touchingElement);
}
};

Expand Down Expand Up @@ -59,7 +60,7 @@
}
}}
>
{#if calendarDay.day > 0}
{#if calendarDay.getMonth() === currentMonth}
{@const isHighlighted =
startDaySelection &&
endDaySelection &&
Expand Down Expand Up @@ -90,13 +91,13 @@
handleEndSelection();
}}
tabindex="0"
class="relative flex justify-center w-full cursor-pointer select-none"
class="relative flex w-full cursor-pointer select-none justify-center"
>
<CalendarBodyDay {isHighlighted} {calendarDay} />
</button>
{:else}
<div class="select-none">
<p class="p-2">&nbsp;</p>
<div class="flex w-full select-none justify-center">
<p class="p-2 text-surface-400">{calendarDay.getDay()}</p>
</div>
{/if}
</td>
Expand Down
17 changes: 9 additions & 8 deletions src/lib/components/Calendar/CalendarBodyDay.svelte
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<script lang="ts">
import type { Day } from "$lib/components/Calendar/CalendarDay";
import type { ZotDate } from "$lib/utils/ZotDate";

export let isHighlighted: boolean | null;
export let calendarDay: Day;
export let calendarDay: ZotDate;
</script>

{#if isHighlighted}
<div
class="absolute w-10 h-10 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary-200 top-1/2 left-1/2"
class="absolute left-1/2 top-1/2 h-10 w-10 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary-200"
></div>
{:else if calendarDay.isSelected}
<div
class="absolute w-10 h-10 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary-400 top-1/2 left-1/2"
class="absolute left-1/2 top-1/2 h-10 w-10 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary-400"
></div>
{/if}

<p
class="relative p-2 text-base font-medium text-gray-500"
data-day={calendarDay.day}
data-month={calendarDay.month}
data-year={calendarDay.year}
data-day={calendarDay.getDay()}
data-month={calendarDay.getMonth()}
data-year={calendarDay.getYear()}
data-selected={calendarDay.isSelected}
>
{calendarDay.day}
{calendarDay.getDay()}
</p>
40 changes: 40 additions & 0 deletions src/lib/components/availability/AvailabilityBlock.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script lang="ts">
import type { SelectionStateType } from "$lib/types/availability";

export let isAvailable: boolean;
export let zotDateIndex: number;
export let blockIndex: number;
export let selectionState: SelectionStateType | null;

let backgroundColor: string = "";

/**
* Updates the background color of a single time block cell
* @param selectionState the current boundaries describing the user's selection
*/
const updateBlockColor = (selectionState: SelectionStateType | null): void => {
// Render different background color if user is in middle of making a selection and is in range
if (selectionState) {
const { earlierDateIndex, laterDateIndex, earlierBlockIndex, laterBlockIndex } =
selectionState;
const dateInRange = earlierDateIndex <= zotDateIndex && zotDateIndex <= laterDateIndex;
const timeInRange = earlierBlockIndex <= blockIndex && blockIndex <= laterBlockIndex;

if (dateInRange && timeInRange) {
backgroundColor = "bg-success-200";
return;
}
}
backgroundColor = isAvailable ? "bg-success-400" : "bg-neutral-200";
};

$: {
updateBlockColor(selectionState);
}
</script>

<div
data-date-index={zotDateIndex}
data-block-index={blockIndex}
class={`${backgroundColor} block h-full w-full py-2`}
></div>
Loading
Loading