Conversation
| <!-- | ||
| manifest.json provides metadata used when your web app is installed on a | ||
| user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
| --> | ||
| <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
| <!-- | ||
| Notice the use of %PUBLIC_URL% in the tags above. | ||
| It will be replaced with the URL of the `public` folder during the build. | ||
| Only files inside the `public` folder can be referenced from the HTML. | ||
|
|
||
| Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
| work correctly both with client-side routing and a non-root public URL. | ||
| Learn how to configure a non-root public URL by running `npm run build`. | ||
| --> | ||
| <title>React App</title> | ||
| </head> | ||
| <body> | ||
| <noscript>You need to enable JavaScript to run this app.</noscript> | ||
| <div id="root"></div> | ||
| <!-- | ||
| This HTML file is a template. | ||
| If you open it directly in the browser, you will see an empty page. | ||
|
|
||
| You can add webfonts, meta tags, or analytics to this file. | ||
| The build step will place the bundled scripts into the <body> tag. | ||
|
|
||
| To begin the development, run `npm start` or `yarn start`. | ||
| To create a production bundle, use `npm run build` or `yarn build`. | ||
| --> |
There was a problem hiding this comment.
Комментарии в целом можно удалить и тег <noscript>
| const [routeSchedule, setRouteSchedule] = useState(null); | ||
| const [loading, setLoading] = useState(false); | ||
| const [activeTab, setActiveTab] = useState('station'); | ||
| const mapRef = useRef(null); |
There was a problem hiding this comment.
mapRef должен храниться только в компоненте карты
| const popupRef = useRef(null); | ||
| const [popupContent, setPopupContent] = useState(''); | ||
|
|
||
| const samaraCenter = fromLonLat([50.15, 53.2]); |
There was a problem hiding this comment.
Координаты нужно вынести отдельно в конфиг или .env
| import { fromLonLat } from 'ol/proj'; | ||
| import { Style, Icon, Text, Fill, Stroke } from 'ol/style'; | ||
| import Overlay from 'ol/Overlay'; | ||
| import { stationsData } from '../data/stations'; |
There was a problem hiding this comment.
Забыли добавить файл в гит
| } | ||
| }); | ||
|
|
||
| window.selectStationFromMap = (code) => { |
There was a problem hiding this comment.
Если я всё правильно увидел, то вы нигде не используете эту функцию как минимум, а как максимум записываете это в объект window, единственное применение такому подходу это дебаг через консоль разработчика разве что, но проверить не могу, так как приложение у меня не запускается
| if (mapInstanceRef.current) { | ||
| mapInstanceRef.current.setTarget(null); | ||
| } |
| } | ||
| }; | ||
|
|
||
| const defaultDate = new Date().toISOString().split('T')[0]; |
There was a problem hiding this comment.
Лучше в useState запихнуть или useRef, чтобы не выполнять лишние операции при каждом обновлении компоненты
Или если хотите сделать прям обновляющуюся в реальном времени дату, то это делается через простые манипуляции довольно
| const formatTime = (date) => { | ||
| if (!date) return 'Время уточняется'; | ||
| try { | ||
| const dateObj = typeof date === 'string' ? new Date(date) : date; | ||
| if (isNaN(dateObj.getTime())) return 'Время уточняется'; | ||
| return dateObj.toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' }); | ||
| } catch { | ||
| return 'Время уточняется'; | ||
| } | ||
| }; | ||
|
|
||
| const formatFullDate = (date) => { | ||
| if (!date) return null; | ||
| try { | ||
| const dateObj = typeof date === 'string' ? new Date(date) : date; | ||
| if (isNaN(dateObj.getTime())) return null; | ||
| return dateObj.toLocaleString('ru-RU', { | ||
| day: '2-digit', | ||
| month: '2-digit', | ||
| hour: '2-digit', | ||
| minute: '2-digit' | ||
| }); | ||
| } catch { | ||
| return null; | ||
| } | ||
| }; |
There was a problem hiding this comment.
Это функции утилиты их в папку utils/
| const app = express(); | ||
| const port = 3001; | ||
|
|
||
| const API_KEY = process.env.REACT_APP_API_KEY || '5c35214b-1ca9-4216-a86e-d852deeecfaf'; |
There was a problem hiding this comment.
лучше вот так
const API_KEY = process.env.REACT_APP_API_KEY ?? null;
if (!API_KEY) {
console.error("Invalid API_KEY")
return;
}
Веб-версия "Прибывалки для электричек"
Возможности: