Skip to content

Commit

Permalink
Commit
Browse files Browse the repository at this point in the history
Calendar works now
  • Loading branch information
Jodekq committed Feb 15, 2024
1 parent 01bd7fb commit 57c544c
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 46 deletions.
74 changes: 74 additions & 0 deletions src/client/calendar/_src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
function getCurrentWeek(): string {
const today: Date = new Date();
const firstDayOfWeek: Date = new Date(today.getFullYear(), today.getMonth(), today.getDate() - today.getDay() + 1);
const lastDayOfWeek: Date = new Date(firstDayOfWeek);
lastDayOfWeek.setDate(lastDayOfWeek.getDate() + 6);

return `${firstDayOfWeek.toLocaleDateString()} - ${lastDayOfWeek.toLocaleDateString()}`;
}

function updateCalendarOnLoad(): void {
// update weekl
const currentWeekElement: HTMLSpanElement | null = document.getElementById("current-week");
const weekDayElements: NodeListOf<HTMLSpanElement> = document.querySelectorAll(".week-day");

const today: Date = new Date();

if (currentWeekElement) {
currentWeekElement.innerHTML = getCurrentWeek();
}

const weekContainers: NodeListOf<HTMLDivElement> = document.querySelectorAll(".week-container .week");
weekContainers.forEach((week, index) => {
const currentDate: Date = new Date();
currentDate.setDate(currentDate.getDate() - currentDate.getDay() + index + 1);

const dayId: string = currentDate.toLocaleDateString().replace(/\./g, "-");
week.id = dayId;

const weekDaySpan: HTMLSpanElement | null = weekDayElements[index];
if (weekDaySpan) {
weekDaySpan.innerHTML = currentDate.toLocaleDateString();
if (currentDate.toDateString() === today.toDateString()) {
week.classList.add("current-day");
}
}
});

// update month
const currentMonthElement: HTMLSpanElement | null = document.querySelector(".current-month");
const monthContainers: NodeListOf<HTMLDivElement> = document.querySelectorAll(".month-container .month");

const firstDayOfMonth: Date = new Date(today.getFullYear(), today.getMonth(), 1);
const lastDayOfMonth: Date = new Date(today.getFullYear(), today.getMonth() + 1, 0);

if (currentMonthElement) {
const monthName: string = today.toLocaleString('default', { month: 'long' });
currentMonthElement.innerHTML = `${monthName}, ${today.getFullYear()}`;
}

monthContainers.forEach((month, index) => {
const currentDate: Date = new Date(firstDayOfMonth);
currentDate.setDate(currentDate.getDate() + index);

const monthId: string = currentDate.toLocaleDateString().replace(/\./g, "-");
month.id = monthId;

if (index === today.getDate() - 1) {
month.classList.add("current-day");
}

const monthDaySpan: HTMLSpanElement | null = month.querySelector(".month-header .month-day");
if (monthDaySpan) {
monthDaySpan.innerHTML = currentDate.toLocaleDateString();

// day outside month
if (currentDate < firstDayOfMonth || currentDate > lastDayOfMonth) {
monthDaySpan.classList.add("not-month-day");
}
}
});
}

window.onload = updateCalendarOnLoad;

43 changes: 43 additions & 0 deletions src/client/calendar/_styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,22 @@
border-radius: var(--border-radius);
height: 300px;
cursor: pointer;
padding: var(--small-gap);

&:hover {
border: 2px solid var(--dark-2);
}

.week-header {
display: flex;
align-items: center;
flex-direction: column;
color: var(--dark-text);

.week-day {
font-size: 14px;
}
}
}

.current-day {
Expand Down Expand Up @@ -129,10 +141,41 @@
border: 2px solid var(--dark-3);
border-radius: var(--border-radius);
cursor: pointer;
padding: var(--small-gap);

&:hover {
border: 2px solid var(--dark-2);
}

.month-header {
display: flex;
justify-content: center;

.month-day {
color: var(--dark-text);
}

.not-month-day {
color: var(--dark-2);
}
}
}

.current-day {
border: 2px solid var(--secondary);

&:hover {
border: 2px solid var(--primary);
}

.month-header {
display: flex;
justify-content: center;

.month-day {
color: var(--text);
}
}
}
}
}
Expand Down
112 changes: 66 additions & 46 deletions src/client/calendar/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,77 +22,97 @@
<div class="calendar-container">
<div class="calendar-text-header">
<h5>Week</h5>
<span>7.KW</span>
<span>12.02 - 18.02</span>
<span id="current-week"></span>
</div>
<div class="calendar-content">
<div class="week-container">
<div class="week">

<div class="week-header">
<span>Monday</span>
<span class="week-day"></span>
</div>
</div>
<div class="week">

<div class="week-header">
<span>Tuesday</span>
<span class="week-day"></span>
</div>
</div>
<div class="week current-day">

<div class="week">
<div class="week-header">
<span>Wednesday</span>
<span class="week-day"></span>
</div>
</div>
<div class="week">

<div class="week-header">
<span>Thursday</span>
<span class="week-day"></span>
</div>
</div>
<div class="week">

<div class="week-header">
<span>Friday</span>
<span class="week-day"></span>
</div>
</div>
<div class="week">

<div class="week-header">
<span>Saturday</span>
<span class="week-day"></span>
</div>
</div>
<div class="week">

<div class="week-header">
<span>Sunday</span>
<span class="week-day"></span>
</div>
</div>
</div>
</div>
</div>
<div class="calendar-container">
<div class="calendar-text-header">
<h5>Month</h5>
<span>February, 2024</span>
<span class="current-month"></span>
</div>
<div class="calendar-content">
<div class="month-container">
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
<div class="month"><div class="month-header"><span class="month-day"></span></div></div>
</div>
</div>
</div>
Expand Down

0 comments on commit 57c544c

Please sign in to comment.