-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from 2gis/main
Update gh-pages with main
- Loading branch information
Showing
51 changed files
with
223 additions
and
777 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import { FC, useCallback } from "react"; | ||
import type { FC} from "react"; | ||
import { useCallback } from "react"; | ||
import { DateInput } from "@mapgl-shadows/ui/datepicker"; | ||
import { formatToDatepicker, parseDatepickerFormat } from '../utils/date'; | ||
|
||
type Props = { | ||
interface DatepickerProps { | ||
value: Date, | ||
disabled?: boolean, | ||
onChange: (date: Date) => void | ||
} | ||
|
||
export const Datepicker: FC<Props> = ({ value, disabled = false, onChange }) => { | ||
const _onChange = useCallback((value: string | undefined) => { | ||
onChange(parseDatepickerFormat(value)) | ||
// eslint-disable-next-line react/function-component-definition -- wtf... | ||
export const Datepicker: FC<DatepickerProps> = ({ value, disabled = false, onChange }) => { | ||
const _onChange = useCallback((newValue: string | undefined) => { | ||
onChange(parseDatepickerFormat(newValue)) | ||
}, [onChange]); | ||
|
||
return <DateInput value={formatToDatepicker(value)} disabled={disabled} onChange={_onChange} /> | ||
return <DateInput disabled={disabled} onChange={_onChange} value={formatToDatepicker(value)} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,68 @@ | ||
import { useEffect } from "react"; | ||
import { MapWrapper } from "./MapWrapper"; | ||
import type { FC } from 'react' | ||
import { useMapContext } from '../hooks/useMapContext' | ||
import { MAP_EL_ID } from '../consts' | ||
import { TMap } from "../types"; | ||
import type { TMap } from "../types"; | ||
import { MapWrapper } from "./MapWrapper"; | ||
|
||
const DEFAULT_CENTER: [number, number] = [55.31878, 25.23584]; | ||
|
||
export function MapglMap() { | ||
const { ensureApi, setMap } = useMapContext(); | ||
|
||
useEffect(() => { | ||
let map: TMap | undefined = undefined; | ||
let cancelled = false; | ||
|
||
ensureApi().then((api) => { | ||
if (cancelled) { | ||
return; | ||
} | ||
|
||
const search = new URLSearchParams(window.location.search); | ||
const lng = search.get('lng') ? parseFloat(search.get('lng')!) : DEFAULT_CENTER[0]; | ||
const lat = search.has('lat') ? parseFloat(search.get('lat')!) : DEFAULT_CENTER[1]; | ||
|
||
map = new api.Map( | ||
MAP_EL_ID, | ||
{ | ||
center: [lng, lat], | ||
zoom: 18, | ||
key: '4970330e-7f1c-4921-808c-0eb7c4e63001', | ||
enableTrackResize: true, | ||
} | ||
); | ||
|
||
map.on('moveend', () => { | ||
search.set('lng', map!.getCenter()[0]!.toString()); | ||
search.set('lat', map!.getCenter()[1]!.toString()); | ||
history.replaceState({}, document.title, search.toString()); | ||
}); | ||
|
||
// Выкинем инстанс карты в глобальный скоуп для удобного дебага и для e2e-тестов | ||
(window as any).map = map; | ||
|
||
setMap(map); | ||
}); | ||
|
||
return () => { | ||
cancelled = true; | ||
map?.destroy(); | ||
setMap(undefined); | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
|
||
return <MapWrapper /> | ||
// eslint-disable-next-line react/function-component-definition -- wtf | ||
export const MapglMap: FC = () => { | ||
const { ensureApi, setMap } = useMapContext(); | ||
|
||
useEffect(() => { | ||
let map: TMap | undefined; | ||
let cancelled = false; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- ok here | ||
ensureApi().then((api) => { | ||
if (cancelled) { | ||
return; | ||
} | ||
|
||
const search = new URLSearchParams(window.location.search); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we're sure | ||
const lngFromURL = search.has('lng') ? parseFloat(search.get('lng')!) : DEFAULT_CENTER[0]; | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we're sure | ||
const latFromURL = search.has('lat') ? parseFloat(search.get('lat')!) : DEFAULT_CENTER[1]; | ||
|
||
map = new api.Map( | ||
MAP_EL_ID, | ||
{ | ||
center: [lngFromURL, latFromURL], | ||
zoom: 18, | ||
key: '4970330e-7f1c-4921-808c-0eb7c4e63001', | ||
enableTrackResize: true, | ||
} | ||
); | ||
|
||
map.on('moveend', () => { | ||
if (!map) { | ||
return; | ||
} | ||
|
||
const [lng, lat] = map.getCenter(); | ||
search.set('lng', lng.toPrecision(8)); | ||
search.set('lat', lat.toPrecision(8)); | ||
history.replaceState({}, document.title, `${window.location.origin}${window.location.pathname}?${search.toString()}`); | ||
}); | ||
|
||
// Выкинем инстанс карты в глобальный скоуп для удобного дебага и для e2e-тестов | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we have defined map instance | ||
window.map = map!; | ||
|
||
setMap(map); | ||
}); | ||
|
||
return () => { | ||
cancelled = true; | ||
map?.destroy(); | ||
setMap(undefined); | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps -- wtf | ||
}, []); | ||
|
||
|
||
return <MapWrapper /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
/* eslint-env node -- config */ | ||
|
||
/** @type {import('next').NextConfig} */ | ||
module.exports = { | ||
transpilePackages: ["@mapgl-shadows/ui"], | ||
output: 'export', | ||
basePath: '/lighting-control', | ||
assetPrefix: '/lighting-control', | ||
basePath: process.env.NODE_ENV === 'production' ? '/lighting-control' : '', | ||
assetPrefix: process.env.NODE_ENV === 'production' ? '/lighting-control' : '', | ||
distDir: '../../docs', | ||
cleanDistDir: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.