Skip to content

6411 Рыжова Алена Лаб.2 Вар. 2#55

Open
ryzalena wants to merge 2 commits intoitsecd:mainfrom
ryzalena:main
Open

6411 Рыжова Алена Лаб.2 Вар. 2#55
ryzalena wants to merge 2 commits intoitsecd:mainfrom
ryzalena:main

Conversation

@ryzalena
Copy link
Copy Markdown

@ryzalena ryzalena commented Mar 3, 2026

No description provided.

@ryzalena ryzalena changed the title 6411 Рыжова Алена Вариант 2 6411 Рыжова Алена Лаб.2 Вар. 2 Mar 3, 2026
@AvtoBBus AvtoBBus self-requested a review March 24, 2026 08:05
Copy link
Copy Markdown
Collaborator

@AvtoBBus AvtoBBus left a comment

Choose a reason for hiding this comment

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

Как бы не было печально, но поиск по карте является обязательным требованием, поэтому вам на помощь OpenLayers

<title>Прибывалка63: Электрички</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Коментарии и вот эту строку можно удалить

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Этот файл вам не нужен

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

И этот не нужен

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

И этот не нужен

Comment on lines +14 to +17
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Тоже не нужно

import { stationsList } from './stations';

const App = () => {
const [stations] = useState(stationsList);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

 const [stations, setStations] = useState(stationsList);

Если даже не будете использовать, нужно просто оставлять запятую по правильному

Comment on lines +165 to +192
const formatTime = (datetime) => {
if (!datetime) return '—';
try {
const date = new Date(datetime);
return date.toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' });
} catch {
return '—';
}
};

const formatDuration = (seconds) => {
if (!seconds) return null;

const totalMinutes = Math.floor(seconds / 60);
const hours = Math.floor(totalMinutes / 60);
const minutes = totalMinutes % 60;

if (hours > 0) {
return `${hours} ч ${minutes} мин`;
}
return `${minutes} мин`;
};

const getTrainStatus = (departureTime, arrivalTime) => {
if (!departureTime && !arrivalTime) return { text: 'нет отправления', type: 'no-departure' };

const now = currentTime;
const departure = departureTime ? new Date(departureTime) : null;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Вот эти 3 функции в целом вспомогательные и их лучше вынести отдельно, в идеале папка utils и там файл(-ы) с этими функциями

Comment on lines +45 to +65
useEffect(() => {
if (mode === 'between' && fromSearchQuery.length > 1) {
const filtered = stations.filter(station =>
station.title.toLowerCase().includes(fromSearchQuery.toLowerCase())
);
setFilteredFromStations(filtered);
} else {
setFilteredFromStations([]);
}
}, [fromSearchQuery, stations, mode]);

useEffect(() => {
if (mode === 'between' && toSearchQuery.length > 1) {
const filtered = stations.filter(station =>
station.title.toLowerCase().includes(toSearchQuery.toLowerCase())
);
setFilteredToStations(filtered);
} else {
setFilteredToStations([]);
}
}, [toSearchQuery, stations, mode]);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Не самый лучший вариант, поскольку это нагромождение кода, который может вызываться лишний раз из-за каких-то изменений

Эти три функции в useEffect они как минимум идентичны, кроме 1 переменной в двух местах, а как максимум нужны для того чтобы отлавливать изменение либо станции отправления, либо станции прибытия где в onChange вы поставили только функции, обновляющие состояния. Самое правильное это создать 1 функцию хэндлер, которая будет принимать значение mode, список станций и то в какую переменную нужно записывать.

Comment on lines +122 to +158
const handleStationSelect = (station) => {
setSelectedStation(station);
setSearchQuery('');
setFilteredStations([]);
setApiError('');
};

const handleFromStationSelect = (station) => {
setFromStation(station);
setFromSearchQuery('');
setFilteredFromStations([]);
setApiError('');
setNoRoutesMessage('');
};

const handleToStationSelect = (station) => {
setToStation(station);
setToSearchQuery('');
setFilteredToStations([]);
setApiError('');
setNoRoutesMessage('');
};

const resetSelection = () => {
setSelectedStation(null);
setFromStation(null);
setToStation(null);
setSearchQuery('');
setFromSearchQuery('');
setToSearchQuery('');
setFilteredStations([]);
setFilteredFromStations([]);
setFilteredToStations([]);
setSchedule([]);
setApiError('');
setNoRoutesMessage('');
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Очень что-то много повторяющихся вещей есть, лучше следовать DRY

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

В идеале разнести код на несколько отдельных файлов, к примеру карточку с классом schedule-item точно можно вынести. Какие-нибудь секция с вводом значений для поиска тоже выносится.

Т.е. в вашем случае, можно просто сделать папку features (читать про FSD) и там добавляется файл SearcSection и SheduleCard к примеру, в которые инкапсулируется логика и файл App сбросит лишние килограммы веса

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants