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

Calendar page #37

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
112 changes: 112 additions & 0 deletions apps/frontend/src/app/calendarPage/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
'use client';

import React, { useState } from 'react';

import { styles } from '@/components/calendarStyles';

// Segédfüggvények

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is unnecessary

const daysInWeek = ['Hétfő', 'Kedd', 'Szerda', 'Csütörtök', 'Péntek', 'Szombat', 'Vasárnap'];
const monthNames = [
'Január',
'Február',
'Március',
'Április',
'Május',
'Június',
'Július',
'Augusztus',
'Szeptember',
'Október',
'November',
'December',
];

const getDaysInMonth = (month: number, year: number) => {
return new Date(year, month + 1, 0).getDate();
};

const getFirstDayOfMonth = (month: number, year: number) => {
return new Date(year, month, 1).getDay();
};

// Calendar komponens
const Calendar: React.FC = () => {
const [currentMonth, setCurrentMonth] = useState(7); // Augusztus

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be dynamic as well, we don't want to manually update the month and the year every time it changes :D
Consider using something like const currentDate = new date() and please get the month and year from this one

const [currentYear, setCurrentYear] = useState(2024); // 2024

const daysInMonth = getDaysInMonth(currentMonth, currentYear);
const firstDayOfMonth = getFirstDayOfMonth(currentMonth, currentYear);

const handlePrevMonth = () => {
if (currentMonth === 0) {
// Ha január van, lépj vissza decemberre és csökkentsd az évet
setCurrentMonth(11);
setCurrentYear(currentYear - 1);
} else {
setCurrentMonth(currentMonth - 1);
}
};

const handleNextMonth = () => {
if (currentMonth === 11) {
// Ha december van, lépj előre januárra és növeld az évet
setCurrentMonth(0);
setCurrentYear(currentYear + 1);
} else {
setCurrentMonth(currentMonth + 1);
}
};

const renderDays = () => {
const days = [];

// Üres cellák a hónap első napja előtt
for (let i = 1; i < firstDayOfMonth; i++) {
days.push(<div style={styles.emptyDay} key={`empty-${i}`} />);
}

// A hónap napjai
for (let i = 1; i <= daysInMonth; i++) {
days.push(
<div style={styles.day} key={i}>
<div className='text-xs text-gray-700 font-bold'>{i}</div>
</div>
);
}

// Üres cellák a hónap utolsó napja után
const totalDays = days.length;
const remainingDays = (7 - (totalDays % 7)) % 7;
for (let i = 0; i < remainingDays; i++) {
days.push(<div style={styles.emptyDay} key={`empty-end-${i}`} />);
}

return days;
};

return (
<div style={styles.calendarContainer}>
<div style={styles.calendarHeader}>
<button style={styles.button} onClick={handlePrevMonth}>
{'<'}
</button>
<div style={styles.monthLabel}>{monthNames[currentMonth]}</div>
<button style={styles.button} onClick={handleNextMonth}>
{'>'}
</button>
</div>
<div>
<div style={styles.grid}>
{daysInWeek.map((day) => (
<div style={styles.dayName} key={day}>
{day}
</div>
))}
</div>
<div style={styles.grid}>{renderDays()}</div>
</div>
</div>
);
};

export default Calendar;
2 changes: 0 additions & 2 deletions apps/frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import './globals.css';
import type { Metadata } from 'next';

import Navbar from '@/components/navbar';
import NewEvent from '@/pages/newEvent';

export const metadata: Metadata = {
title: 'ProgramSCH',
Expand All @@ -19,7 +18,6 @@ export default function RootLayout({
<html lang='hu'>
<body>
<Navbar />
<NewEvent />
{children}
</body>
</html>
Expand Down
70 changes: 70 additions & 0 deletions apps/frontend/src/components/calendarStyles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
export const styles = {
calendarContainer: {
marginTop: '1.25rem',
width: '91.666667%',
marginLeft: '4rem',
fontFamily: 'sans-serif',
},
calendarHeader: {
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
marginBottom: '0.625rem',
borderRadius: '0.5rem',
width: '12.5rem',
padding: '0.25rem',
backgroundColor: '#7eb397',
borderColor: '#18633d',
borderWidth: '2px',
},
button: {
paddingLeft: '0.5rem',
paddingRight: '0.5rem',
paddingTop: '0.25rem',
paddingBottom: '0.25rem',
fontSize: '1.125rem',
fontWeight: 'bold',
cursor: 'pointer',
},
monthLabel: {
fontSize: '1.25rem',
fontWeight: 'bold',
padding: '0.25rem',
backgroundColor: '#e0e0e0',
borderRadius: '0.5rem',
},
dayName: {
backgroundColor: '#18633d',
color: '#fff',
borderRadius: '0.5rem',
height: '3rem',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
fontSize: '20px',
},
day: {
marginTop: '0.25rem',
height: '6rem',
backgroundColor: '#7eb397',
borderColor: '#ccc',
borderWidth: '1px',
borderRadius: '0.5rem',
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'flex-start',
padding: '0.5rem',
},
emptyDay: {
marginTop: '0.25rem',
width: '100%',
height: '6rem',
backgroundColor: '#e0e0e0',
borderRadius: '0.5rem',
},
grid: {
display: 'grid',
gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
gap: '0.25rem',
},
};
4 changes: 2 additions & 2 deletions apps/frontend/src/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ function Navbar() {
<Image src='/logo.png' alt='Logo' width={50} height={50} title='by KirDev' />
</div>
<div className='font-bold text-3xl no-underline text-gray-900 text-center mt-1'>
<a href='/home' title='Kezdőlap'>
<a href='/calendarPage' title='Kezdőlap'>
ProgramSCH
</a>
</div>
</div>
<div className='flex'>
<Icon href='./pages/newEvent.tsx' src='/new.png' alt='Új' title='Új esemény' />
<Icon href='/newEvent' src='/new.png' alt='Új' title='Új esemény' />
<Icon href='' src='/profile.png' alt='Profil' title='Profil' />
</div>
</nav>
Expand Down