import '../scss/styles.scss';
import * as bootstrap from 'bootstrap';
import Sidenav from './Sidenav.svelte';
- import { selectedDate } from '$lib/calendarStore.js';
+ import { selectedDate, cal } from '$lib/calendarStore.js';
import axios from 'axios';
import { dev } from '$app/environment';
import { goto } from '$app/navigation';
const result = await getLog();
if (result) {
lastSelectedDate = $selectedDate;
+ $cal.currentYear = $selectedDate.getFullYear();
+ $cal.currentMonth = $selectedDate.getMonth();
} else {
$selectedDate = lastSelectedDate;
}
let animationDirection = $state(1); // swipe the dates left or right
+ let lastMonth = $cal.currentMonth;
+ let lastYear = $cal.currentYear;
+
$effect(() => {
- if ($cal) {
+ if ($cal && ($cal.currentMonth !== lastMonth || $cal.currentYear !== lastYear)) {
+ // set animation direction
+ animationDirection = $cal.currentMonth > lastMonth ? 1 : -1;
+ if ($cal.currentYear > lastYear) {
+ animationDirection = 1;
+ } else if ($cal.currentYear < lastYear) {
+ animationDirection = -1;
+ }
+
days = updateCalendar();
+ lastMonth = $cal.currentMonth;
+ lastYear = $cal.currentYear;
}
});
const updateCalendar = () => {
- console.log('updateCalendar');
-
const month = $cal.currentMonth;
const year = $cal.currentYear;
const firstDay = new Date(year, month, 1);
};
const changeMonth = (increment) => {
- animationDirection = increment;
$cal.currentMonth += increment;
if ($cal.currentMonth < 0) {
$cal.currentMonth = 11;
$cal.currentMonth = 0;
changeYear(1);
}
- days = updateCalendar();
};
const changeYear = (increment) => {
- animationDirection = increment;
$cal.currentYear += increment;
- days = updateCalendar();
};
const onDateClick = (date) => {
const onMonthSelect = (event) => {
animationDirection = months.indexOf(event.target.value) > $cal.currentMonth ? 1 : -1;
$cal.currentMonth = months.indexOf(event.target.value);
- days = updateCalendar();
};
const onYearInput = (event) => {
const year = parseInt(event.target.value);
if (year && !isNaN(year) && year >= 1) {
$cal.currentYear = year;
- days = updateCalendar();
}
};
</div>
{/key}
</div>
- {$selectedDate}
+
+ <div class="row mb-2">
+ <div class="col-4"></div>
+ <div class="col-4">
+ <button
+ class="btn btn-primary"
+ onclick={() => {
+ $selectedDate = new Date();
+ }}>Heute</button
+ >
+ </div>
+ <div class="col-4">
+ <button class="btn btn-secondary"> Mark </button>
+ </div>
+ </div>
</div>
<style>
.calendar-container {
position: relative;
overflow: hidden;
- min-height: 320px;
+ min-height: 282px;
}
.datepicker-grid {
display: grid;