mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
fix(react/collections/geomap): note shifting on its own randomly
This commit is contained in:
parent
f281e9691d
commit
a162d697da
@ -38,6 +38,8 @@ enum State {
|
|||||||
|
|
||||||
export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewModeProps<MapData>) {
|
export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewModeProps<MapData>) {
|
||||||
const [ state, setState ] = useState(State.Normal);
|
const [ state, setState ] = useState(State.Normal);
|
||||||
|
const [ coordinates, setCoordinates ] = useState(viewConfig?.view?.center);
|
||||||
|
const [ zoom, setZoom ] = useState(viewConfig?.view?.zoom);
|
||||||
const [ layerName ] = useNoteLabel(note, "map:style");
|
const [ layerName ] = useNoteLabel(note, "map:style");
|
||||||
const [ hasScale ] = useNoteLabelBoolean(note, "map:scale");
|
const [ hasScale ] = useNoteLabelBoolean(note, "map:scale");
|
||||||
const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly");
|
const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly");
|
||||||
@ -50,6 +52,12 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
|
|||||||
|
|
||||||
useEffect(() => { froca.getNotes(noteIds).then(setNotes) }, [ noteIds ]);
|
useEffect(() => { froca.getNotes(noteIds).then(setNotes) }, [ noteIds ]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!note) return;
|
||||||
|
setCoordinates(viewConfig?.view?.center ?? DEFAULT_COORDINATES);
|
||||||
|
setZoom(viewConfig?.view?.zoom ?? DEFAULT_ZOOM);
|
||||||
|
}, [ note, viewConfig ]);
|
||||||
|
|
||||||
// Note creation.
|
// Note creation.
|
||||||
useTriliumEvent("geoMapCreateChildNote", () => {
|
useTriliumEvent("geoMapCreateChildNote", () => {
|
||||||
toast.showPersistent({
|
toast.showPersistent({
|
||||||
@ -122,10 +130,10 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`geo-view ${state === State.NewNote ? "placing-note" : ""}`}>
|
<div className={`geo-view ${state === State.NewNote ? "placing-note" : ""}`}>
|
||||||
<Map
|
{ coordinates && zoom && <Map
|
||||||
apiRef={apiRef} containerRef={containerRef}
|
apiRef={apiRef} containerRef={containerRef}
|
||||||
coordinates={viewConfig?.view?.center ?? DEFAULT_COORDINATES}
|
coordinates={coordinates}
|
||||||
zoom={viewConfig?.view?.zoom ?? DEFAULT_ZOOM}
|
zoom={zoom}
|
||||||
layerName={layerName ?? DEFAULT_MAP_LAYER_NAME}
|
layerName={layerName ?? DEFAULT_MAP_LAYER_NAME}
|
||||||
viewportChanged={(coordinates, zoom) => {
|
viewportChanged={(coordinates, zoom) => {
|
||||||
if (!viewConfig) viewConfig = {};
|
if (!viewConfig) viewConfig = {};
|
||||||
@ -137,7 +145,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
|
|||||||
scale={hasScale}
|
scale={hasScale}
|
||||||
>
|
>
|
||||||
{notes.map(note => <NoteWrapper note={note} isReadOnly={isReadOnly} />)}
|
{notes.map(note => <NoteWrapper note={note} isReadOnly={isReadOnly} />)}
|
||||||
</Map>
|
</Map>}
|
||||||
<GeoMapTouchBar state={state} map={apiRef.current} />
|
<GeoMapTouchBar state={state} map={apiRef.current} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user