Fix load order re-applying and transition between sidebar pages
This commit is contained in:
@@ -290,14 +290,15 @@ const Map: React.FC = () => {
|
||||
clearSelectedCells();
|
||||
selectCell(cell);
|
||||
}
|
||||
} else if (
|
||||
router.query.mod &&
|
||||
typeof router.query.mod === "string" &&
|
||||
selectedCells
|
||||
) {
|
||||
clearSelectedCell();
|
||||
setSidebarOpen(true);
|
||||
selectCells(selectedCells);
|
||||
} else if (router.query.mod && typeof router.query.mod === "string") {
|
||||
if (selectedCells) {
|
||||
clearSelectedCell();
|
||||
setSidebarOpen(true);
|
||||
selectCells(selectedCells);
|
||||
} else {
|
||||
// TODO: this is so spaghetti
|
||||
clearSelectedCell();
|
||||
}
|
||||
} else if (router.query.plugin && typeof router.query.plugin === "string") {
|
||||
clearSelectedCells();
|
||||
setSidebarOpen(true);
|
||||
@@ -320,9 +321,32 @@ const Map: React.FC = () => {
|
||||
selectCells(cells);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
clearSelectedCell();
|
||||
} else if (plugins && plugins.length > 0 && pluginsPending === 0) {
|
||||
clearSelectedCells();
|
||||
clearSelectedCell();
|
||||
const cells = plugins.reduce(
|
||||
(acc: { x: number; y: number }[], plugin: PluginFile) => {
|
||||
if (plugin.enabled && plugin.parsed) {
|
||||
const newCells = [...acc];
|
||||
for (const cell of plugin.parsed.cells) {
|
||||
if (
|
||||
cell.x !== undefined &&
|
||||
cell.y !== undefined &&
|
||||
cell.world_form_id === 60
|
||||
) {
|
||||
newCells.push({ x: cell.x, y: cell.y });
|
||||
}
|
||||
}
|
||||
return newCells;
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
[]
|
||||
);
|
||||
selectCells(cells);
|
||||
} else {
|
||||
clearSelectedCells();
|
||||
clearSelectedCell();
|
||||
}
|
||||
}, [
|
||||
selectedCell,
|
||||
@@ -346,49 +370,6 @@ const Map: React.FC = () => {
|
||||
}
|
||||
}, [router.query.mod, clearSelectedMod, heatmapLoaded]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!heatmapLoaded) return; // wait for all map layers to load
|
||||
if (
|
||||
plugins &&
|
||||
plugins.length > 0 &&
|
||||
pluginsPending === 0 &&
|
||||
!router.query.cell &&
|
||||
!router.query.mod &&
|
||||
!router.query.plugin
|
||||
) {
|
||||
clearSelectedCells();
|
||||
const cells = plugins.reduce(
|
||||
(acc: { x: number; y: number }[], plugin: PluginFile) => {
|
||||
if (plugin.enabled && plugin.parsed) {
|
||||
const newCells = [...acc];
|
||||
for (const cell of plugin.parsed.cells) {
|
||||
if (
|
||||
cell.x !== undefined &&
|
||||
cell.y !== undefined &&
|
||||
cell.world_form_id === 60
|
||||
) {
|
||||
newCells.push({ x: cell.x, y: cell.y });
|
||||
}
|
||||
}
|
||||
return newCells;
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
[]
|
||||
);
|
||||
selectCells(cells);
|
||||
}
|
||||
}, [
|
||||
plugins,
|
||||
pluginsPending,
|
||||
heatmapLoaded,
|
||||
clearSelectedCells,
|
||||
selectCells,
|
||||
router.query.cell,
|
||||
router.query.mod,
|
||||
router.query.plugin,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (map.current) return; // initialize map only once
|
||||
map.current = new mapboxgl.Map({
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createPortal } from "react-dom";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
import { useAppSelector, useAppDispatch } from "../lib/hooks";
|
||||
import { setPluginsTxt } from "../slices/pluginsTxt";
|
||||
import { setPluginsTxtAndApplyLoadOrder } from "../slices/pluginsTxt";
|
||||
import { applyLoadOrder } from "../slices/plugins";
|
||||
import styles from "../styles/PluginTxtEditor.module.css";
|
||||
|
||||
@@ -24,8 +24,6 @@ const PluginsLoader: React.FC<Props> = () => {
|
||||
|
||||
useEffect(() => {
|
||||
setPluginsTxtShown(false);
|
||||
console.log("going to apply!");
|
||||
dispatch(applyLoadOrder());
|
||||
}, [dispatch, pluginsTxt]);
|
||||
|
||||
const onPluginsTxtButtonClick = async () => {
|
||||
@@ -69,7 +67,9 @@ const PluginsLoader: React.FC<Props> = () => {
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
dispatch(setPluginsTxt(editPluginsTxt ?? ""));
|
||||
dispatch(
|
||||
setPluginsTxtAndApplyLoadOrder(editPluginsTxt ?? "")
|
||||
);
|
||||
setPluginsTxtShown(false);
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user