Conversation
| CLIENT_ORIGIN=http://localhost:5173 | ||
| CLIENT_ORIGINS=http://localhost:5173,http://127.0.0.1:5173,http://localhost:4173,http://127.0.0.1:4173,http://localhost:4174,http://127.0.0.1:4174 |
| function SunIcon() { | ||
| return ( | ||
| <svg viewBox="0 0 24 24" aria-hidden="true"> | ||
| <circle cx="12" cy="12" r="4.2" /> | ||
| <path d="M12 2.5v2.7M12 18.8v2.7M21.5 12h-2.7M5.2 12H2.5M18.7 5.3l-1.9 1.9M7.2 16.8l-1.9 1.9M18.7 18.7l-1.9-1.9M7.2 7.2 5.3 5.3" /> | ||
| </svg> | ||
| ); | ||
| } | ||
|
|
||
| function MoonIcon() { | ||
| return ( | ||
| <svg viewBox="0 0 24 24" aria-hidden="true"> | ||
| <path d="M16.9 14.8A7.7 7.7 0 0 1 9.2 7.1c0-1.6.5-3.1 1.3-4.4A9 9 0 1 0 21.3 13c-1.3.8-2.8 1.3-4.4 1.3Z" /> | ||
| </svg> | ||
| ); | ||
| } |
There was a problem hiding this comment.
svg можно вынести в отдельные svg-файлы
| import { LoadingBlock } from "./LoadingBlock"; | ||
| import { StationAutocomplete } from "./StationAutocomplete"; | ||
|
|
||
| function RouteCard({ segment }) { |
| } | ||
|
|
||
| let isCancelled = false; | ||
| const timeoutId = window.setTimeout(async () => { |
There was a problem hiding this comment.
обращаться к setTimeout через windows не обязательно
| export function StationMap({ nearbyStations, selectedStation, pickedPoint, onMapPointPick }) { | ||
| const mapElementRef = useRef(null); | ||
| const mapInstanceRef = useRef(null); | ||
| const markersRef = useRef(new VectorSource()); |
There was a problem hiding this comment.
Хранить в отдельной переменной даже не слой, а его source не имеет смысла, потому что получить его вообще не трудно
const vectorLayer = mapRef.current?.getAllLayers().find(/* тут функция по которой вы ищете слой*/);
const source = vectorLayer?.getSource(); Возможно вы скажете, что это выглядит длиннее и будете правы, однако предположим, что слоёв у нас не 1, а как минимум 10 и получить данные из слоя может понадобиться в любом месте программы. Тогда мы в папочке utils создаём файлик, в котором у нас лежит функция с выше описанным кодом, к примеру вот так
function getSourceFromVectorLayerByName(mapObject, layerName) {
if (!mapObject) return null;
const vectorLayer = mapObject.getAllLayers().find(l => l.get('name') === layerName);
if (!vectorLayer) return null;
return vectorLayer.getSource();
}И теперь вместо 10 переменных в компоненте с картой мы получаем 1 универсальную функцию, которую можно почти откуда угодно вызвать.
P.S. Если что, чтобы добавить поле name слою нужно сделать
const newLayer = new VectorLayer(/* ... */);
newLayer.set('name', 'my-layer');| import { EmptyState } from "./EmptyState"; | ||
| import { LoadingBlock } from "./LoadingBlock"; | ||
|
|
||
| function ScheduleCard({ entry }) { |
There was a problem hiding this comment.
Это тоже отдельный компонент
| import { StationAutocomplete } from "./StationAutocomplete"; | ||
| import { StationMap } from "./StationMap"; | ||
|
|
||
| function FavoriteButton({ active, onClick }) { |
| export function canUseStorage() { | ||
| return typeof window !== "undefined" && typeof window.localStorage !== "undefined"; | ||
| } |
| import { todayDateValue } from "./utils/dates"; | ||
| import { readStoredValue, writeStoredValue } from "./utils/storage"; | ||
|
|
||
| const DEFAULT_THEME = "light"; |
| function openSection(sectionId) { | ||
| window.location.hash = sectionId; | ||
| } |
No description provided.