Skip to content

Commit

Permalink
Merge branch 'main' of github.com:depocoder/YetAnotherCalendar into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
AzamatKomaev committed Oct 16, 2024
2 parents 235b078 + 17a3ff1 commit f939e53
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 139 deletions.
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
run: |
docker buildx build --platform linux/amd64,linux/arm64 --push ./frontend \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_frontend:latest \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_frontend:$IMAGE_TAG
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_frontend:$IMAGE_TAG
1 change: 1 addition & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const App = () => {
if (response.status === 200) {
setAuthData({email, password, personId});
localStorage.setItem('token', response.data["_netology-on-rails_session"]);

return {success: true};
} else {
return {success: false, message: "Неверный логин или пароль."};
Expand Down
57 changes: 31 additions & 26 deletions frontend/src/components/Calendar/Calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import cross from "../../img/arrow.png";

import '../../style/header.scss';
import '../../style/calendar.scss';
import DatePicker from "./DataPicker";
import camera from "../../img/camera.png";

const Calendar = ({events}) => {
console.log('events:', events);

Expand Down Expand Up @@ -91,10 +94,9 @@ const Calendar = ({events}) => {
</button>
</div>

{/* Информация о дедлайнах */}
<div className="header-deadline">
<div className="rectangle">
{netology?.homework?.length > 0 && netology.homework.map((homeworkItem, index) => (
<a className="header-deadline-info"
<a className="rectangle-info"
key={index}
href={homeworkItem?.url}
target="_blank"
Expand All @@ -118,6 +120,8 @@ const Calendar = ({events}) => {
</a>
))}
</div>

<DatePicker />
</header>

<div className="calendar">
Expand All @@ -126,29 +130,28 @@ const Calendar = ({events}) => {

<table className="shedule-table">
<thead>
<tr>
<tr>
<th className="days"></th>
{weekDays.map((day, index) => (
<th key={index} className={`days-${index + 1}`}>{day.day}</th>
))}
</tr>
{/*TODO: написать логику*/}
<tr>
<th className="vertical-heading">
дедлайны
<button className="off-deadline">Скрыть</button>
{/*TODO: написать логику*/}
<tr>
<th className="vertical-heading"> дедлайны
<div className="off-deadline">Скрыть</div>
</th>
<td className="vertical-deadline">
<button className="deadline-info">ТюмГУ</button>
<button className="deadline-info-on">Нетология</button>
<div className="deadline-info">ТюмГУ</div>
<div className="deadline-info-on">Нетология</div>
</td>
<td className="vertical-deadline"></td>
<td className="vertical-deadline">
<button className="deadline-info">ТюмГУ</button>
<div className="deadline-info">ТюмГУ</div>
</td>
<td className="vertical-deadline"></td>
<td className="vertical-deadline">
<button className="deadline-info">Нетология</button>
<div className="deadline-info">Нетология</div>
</td>
<td className="vertical-deadline"></td>
<td className="vertical-deadline"></td>
Expand All @@ -160,7 +163,7 @@ const Calendar = ({events}) => {
{[1, 2, 3, 4, 5, 6, 7].map((lessonNumber) => (
<tr key={lessonNumber}>
<th className="vertical-heading">
{lessonNumber} пара <br/> {lessonNumber * 2 + 8}:00 - {lessonNumber * 2 + 9}:30
{lessonNumber} пара <br/> {lessonNumber * 2 + 8}:00 {lessonNumber * 2 + 9}:30
</th>
{weekDays.map((day, index) => {
const eventsForDay = getEventsForDay(day.date);
Expand All @@ -169,13 +172,14 @@ const Calendar = ({events}) => {
<td key={index} className="vertical">
{eventsForSlot.length > 0 ? (
eventsForSlot.map(event => (
<div key={event.id} className="event-item">
<div key={event.id} className="TyumGU-lesson event-item">
<span className="company-name"><img src={camera} alt={camera}/> ТюмГУ<br/></span>
<div className="lesson-name">{event.nameShort}</div>
<div className="lesson-name">{event.name}</div>
<div className="lesson-time">
{new Date(event.start).toLocaleTimeString([], {
hour: '2-digit',
minute: '2-digit'
hour: '2-digit',
minute: '2-digit'
})} -
{new Date(event.end).toLocaleTimeString([], {
hour: '2-digit',
Expand All @@ -185,15 +189,16 @@ const Calendar = ({events}) => {
<span className="teacher-name">{event.teacher_full_name}</span>
</div>
))
) : (
<div className="empty-slot"></div>
)}
</td>
);
})}
</tr>
))}
</tbody>
) : (<div className="empty-slot"></div>
)}
</td>
);
})}
</tr>
)
)
}
</tbody>
</table>
</div>
</div>
Expand Down
82 changes: 54 additions & 28 deletions frontend/src/components/Calendar/DataPicker.jsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,67 @@
import React, { useRef, useEffect, useState } from "react";
import Flatpickr from "flatpickr";
import weekSelect from "flatpickr";
import React, { useEffect, useState } from "react";
import "flatpickr/dist/flatpickr.css";
import flatpickr from "flatpickr";
import { Russian } from "flatpickr/dist/l10n/ru.js";
// import flatpickr from "flatpickr";
// import { Russian } from "flatpickr/dist/l10n/ru.js";
import "../../style/DatePicker.scss"; // Для стилей компонента

const DatePicker = () => {
const datePickerRef = useRef(null);
// const datePickerRef = useRef(null);
const [currentDate, setCurrentDate] = useState(new Date()); // Текущая дата
const [weekRange, setWeekRange] = useState("");

const [dateOnCalendar, setDateOnCalendar] = useState("2024-09-19");
const [weekNumber, setWeekNumber] = useState(null);
// Рассчитать начало и конец недели
const calculateWeekRange = (date) => {
const startOfWeek = new Date(date);
const endOfWeek = new Date(date);

// Получаем понедельник текущей недели
startOfWeek.setDate(date.getDate() - date.getDay() + 1); // Понедельник
endOfWeek.setDate(startOfWeek.getDate() + 6); // Воскресенье

const formatOptions = { day: "numeric", month: "long" };
const startFormatted = startOfWeek.toLocaleDateString("ru-RU", formatOptions);
const endFormatted = endOfWeek.toLocaleDateString("ru-RU", formatOptions);

return `${startFormatted}${endFormatted}`;
};

// Обновить диапазон недели при изменении даты
useEffect(() => {
flatpickr(datePickerRef.current, {
locale: Russian,
onChange: [
() => {
setWeekNumber(
this.selectedDates[0] ? setWeekNumber(this.selectedDates[0]) : null,
);
console.log(weekNumber);
},
],
setWeekRange(calculateWeekRange(currentDate));
}, [currentDate]);

// Обработчик для переключения недель
const handlePrevWeek = () => {
setCurrentDate((prevDate) => {
const newDate = new Date(prevDate);
newDate.setDate(prevDate.getDate() - 7); // Переключение на предыдущую неделю
return newDate;
});
}, []);
};

const handleNextWeek = () => {
setCurrentDate((prevDate) => {
const newDate = new Date(prevDate);
newDate.setDate(prevDate.getDate() + 7); // Переключение на следующую неделю
return newDate;
});
};

return (
<div>
<input
className="calendar"
type="text"
ref={datePickerRef}
value={dateOnCalendar}
onChange={(e) => setDateOnCalendar(e.target.value)}
/>
<div className="date-picker-wrapper">
<div className="week-display">
<span className="week-range">{weekRange}</span>
<div className="week-navigation">
<button className="prev-week-btn" onClick={handlePrevWeek}>
&lt;
</button>
<button className="next-week-btn" onClick={handleNextWeek}>
&gt;
</button>
</div>
</div>
</div>
);
};
flatpickr.l10ns.default.firstDayOfWeek = 1;

export default DatePicker;
Empty file.
30 changes: 18 additions & 12 deletions frontend/src/components/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ export default function Header() {
<img className="exit-btn-cross" src={cross} alt={cross} />
</button>
</div>
<div id="rectangle" className="info">
<div className="source">
<span className="source-first-word">Дедлайн</span> Нетология <span className="date-event"><img src={arrow} alt={arrow} /> 23.09.2024</span>
</div>
<div className="name-event">
<span className="name-event-text">Программирование на Python</span>
</div>
<div className="task-event">
<span className="task-event-text">Домашнее задание с самопроверкой(дедлайн 12.12.24)</span>
<div className="rectangle">
<div className="rectangle-info">
<div className="source">
<span className="source-first-word">Дедлайн</span> Нетология <span className="date-event"><img src={arrow}
alt={arrow}/> 23.09.2024</span>
</div>
<div className="name-event">
<span className="name-event-text">Программирование на Python</span>
</div>
<div className="task-event">
<span className="task-event-text">Домашнее задание с самопроверкой(дедлайн 12.12.24)</span>
</div>
</div>
</div>
<div className="vertical-line"></div>
Expand All @@ -48,7 +51,7 @@ export default function Header() {
<td className="days-7">Вс 29.09</td>
</tr>
<tr>
<th className="vertical-heading">
<th className="vertical-heading">
дедлайны
<button className="off-deadline">Скрыть</button>
</th>
Expand All @@ -71,9 +74,12 @@ export default function Header() {
<td className="vertical"></td>
<td className="vertical"></td>
<td className="vertical"></td>
<td className="vertical"><button className="TyumGU-lesson">
<td className="vertical">
<div className="TyumGU-lesson">
<span className="company-name"><img src={camera} alt={camera} /> ТюмГУ<br /></span>
<span className="lesson-name">Математический анализ</span></button></td>
<span className="lesson-name">Математический анализ</span>
</div>
</td>
<td className="vertical"></td>
</tr>
<tr>
Expand Down
16 changes: 10 additions & 6 deletions frontend/src/pages/CalendarRoute.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import { getNetologyCourse, bulkEvents } from '../services/api'; // Ваши API-запросы
import Calendar from "../components/Calendar/Calendar";
// import Header from "../components/Header/Header";
import Header from "../components/Header/Header";

const CalendarRoute = ({ email, password, personId, token }) => {
const [events, setEvents] = useState(null);
Expand Down Expand Up @@ -42,21 +42,25 @@ const CalendarRoute = ({ email, password, personId, token }) => {
const courseData = await getNetologyCourse(token);
console.log('Данные курса:', courseData);

const fetchedCalendarId = courseData?.id;
const calendarId = courseData?.id;
console.log('calendarId add storage', calendarId)
localStorage.setItem('calendarId', calendarId);

if (fetchedCalendarId) {
if (calendarId) {
const eventsResponse = await bulkEvents(
email, // Email пользователя
password, // Пароль пользователя
token, // Токен сессии
fetchedCalendarId, // ID календаря
calendarId, // ID календаря
"2024-10-14T00:00:00+03:00", // Дата начала
"2024-10-20T23:59:59+03:00", // Дата окончания
personId // ID участника
);
console.log('События:', eventsResponse.data);
setEvents(eventsResponse.data);

// cached_at
localStorage.setItem('cached_at', eventsResponse.data.cached_at); // Сохраняем cached_at localstorage
console.log('eventsResponse.data.cached_at', eventsResponse.data.cached_at)
// Сохраняем события в localStorage
saveEventsToLocalStorage(eventsResponse.data);
}
Expand All @@ -82,7 +86,7 @@ const CalendarRoute = ({ email, password, personId, token }) => {
return (
<div className="calendar-page">
<Calendar events={events}/>
{/*<Header />*/}
<Header />
</div>
);
};
Expand Down
Loading

0 comments on commit f939e53

Please sign in to comment.