2024-01-24 11:46:09 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import { pb } from '$lib/pocketbase';
|
|
|
|
|
|
|
|
|
|
type Action = {
|
|
|
|
|
type: string;
|
|
|
|
|
created: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
actions = await fetchAllActions();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function fetchAllActions() {
|
|
|
|
|
// Fetch all actions. Adjust as needed for date range or pagination
|
|
|
|
|
const result = await pb.collection('actions').getList(1, 1000);
|
|
|
|
|
return result.items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let actions: Action[] = [];
|
|
|
|
|
|
|
|
|
|
// Function to get the day of the week from a date string
|
|
|
|
|
const getDayOfWeek = (dateString: string) => {
|
|
|
|
|
return new Date(dateString).getDay();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Function to get the hour of the day from a date string
|
|
|
|
|
const getHourOfDay = (dateString: string) => {
|
|
|
|
|
return new Date(dateString).getHours();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Days of the week for headers
|
|
|
|
|
const daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
|
|
|
|
|
|
|
|
// Generate hours for the grid
|
|
|
|
|
const hours = Array.from({ length: 24 }, (_, i) => i);
|
2024-01-24 16:43:18 +00:00
|
|
|
|
|
|
|
|
// Function to format hour in HH:mm format
|
|
|
|
|
const formatHour = (hour: number) => {
|
|
|
|
|
return `${hour.toString().padStart(2, '0')}:00`;
|
|
|
|
|
};
|
2024-01-24 11:46:09 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.calendar {
|
|
|
|
|
display: grid;
|
2024-01-24 16:43:18 +00:00
|
|
|
grid-template-columns: 60px repeat(7, 1fr); /* Adjusted for hour column */
|
2024-01-24 11:46:09 +00:00
|
|
|
text-align: center;
|
|
|
|
|
}
|
2024-01-24 16:43:18 +00:00
|
|
|
.day-header, .hour-label {
|
2024-01-24 11:46:09 +00:00
|
|
|
font-weight: bold;
|
2024-01-24 16:43:18 +00:00
|
|
|
border: 1px solid #ccc;
|
2024-01-24 11:46:09 +00:00
|
|
|
}
|
|
|
|
|
.hour {
|
|
|
|
|
border: 1px solid #ccc;
|
2024-01-24 16:43:18 +00:00
|
|
|
height: 60px;
|
2024-01-24 11:46:09 +00:00
|
|
|
}
|
|
|
|
|
.event {
|
|
|
|
|
background-color: lightblue;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
padding: 2px;
|
|
|
|
|
text-align: left;
|
|
|
|
|
}
|
2024-01-24 16:43:18 +00:00
|
|
|
|
|
|
|
|
.event--food {
|
|
|
|
|
background-color: lightgreen;
|
|
|
|
|
}
|
|
|
|
|
.event--poop {
|
|
|
|
|
background-color: burlywood;
|
|
|
|
|
}
|
|
|
|
|
.event--asleep {
|
|
|
|
|
background-color: lightblue;
|
|
|
|
|
}
|
|
|
|
|
.event--awake {
|
|
|
|
|
background-color: gold;
|
|
|
|
|
}
|
|
|
|
|
.event--diaper {
|
|
|
|
|
background-color: lightpink;
|
|
|
|
|
}
|
2024-01-24 11:46:09 +00:00
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<div class="calendar">
|
2024-01-24 16:43:18 +00:00
|
|
|
<!-- Empty cell for top-left corner -->
|
|
|
|
|
<div></div>
|
|
|
|
|
|
2024-01-24 11:46:09 +00:00
|
|
|
<!-- Day Headers -->
|
|
|
|
|
{#each daysOfWeek as day}
|
|
|
|
|
<div class="day-header">{day}</div>
|
|
|
|
|
{/each}
|
|
|
|
|
|
2024-01-24 16:43:18 +00:00
|
|
|
<!-- Hour Labels and Calendar Grid -->
|
2024-01-24 11:46:09 +00:00
|
|
|
{#each hours as hour}
|
2024-01-24 16:43:18 +00:00
|
|
|
<div class="hour-label">{formatHour(hour)}</div> <!-- Hour label -->
|
2024-01-24 11:46:09 +00:00
|
|
|
{#each daysOfWeek as _, dayIndex}
|
|
|
|
|
<div class="hour">
|
|
|
|
|
{#each actions as action}
|
|
|
|
|
{#if getDayOfWeek(action.created) === dayIndex && getHourOfDay(action.created) === hour}
|
2024-01-24 16:43:18 +00:00
|
|
|
<div class="event event--{action.type}">{action.type}</div>
|
2024-01-24 11:46:09 +00:00
|
|
|
{/if}
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
|