2022-03-03 03:19:26 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import { useAppSelector, useAppDispatch } from "../lib/hooks";
|
2022-03-09 06:35:20 +00:00
|
|
|
import { excludedPlugins } from "../lib/plugins";
|
2022-03-15 05:03:51 +00:00
|
|
|
import {
|
|
|
|
enableAllPlugins,
|
|
|
|
disableAllPlugins,
|
|
|
|
togglePlugin,
|
|
|
|
} from "../slices/plugins";
|
2022-03-03 03:19:26 +00:00
|
|
|
import styles from "../styles/PluginList.module.css";
|
|
|
|
|
2022-03-10 05:59:13 +00:00
|
|
|
type Props = {
|
2022-03-10 06:18:19 +00:00
|
|
|
selectedCell?: { x: number; y: number };
|
2022-03-10 05:59:13 +00:00
|
|
|
};
|
2022-03-03 03:19:26 +00:00
|
|
|
|
2022-03-10 05:59:13 +00:00
|
|
|
const PluginsList: React.FC<Props> = ({ selectedCell }) => {
|
2022-03-03 03:19:26 +00:00
|
|
|
const dispatch = useAppDispatch();
|
2022-03-10 05:59:13 +00:00
|
|
|
const plugins = useAppSelector((state) =>
|
|
|
|
selectedCell
|
|
|
|
? state.plugins.plugins.filter((plugin) =>
|
|
|
|
plugin.parsed?.cells.some(
|
2022-03-10 06:10:14 +00:00
|
|
|
(cell) =>
|
|
|
|
cell.x === selectedCell.x &&
|
|
|
|
cell.y === selectedCell.y &&
|
|
|
|
// TODO: support other worlds
|
2022-03-19 19:28:10 +00:00
|
|
|
cell.world_form_id === 60 &&
|
|
|
|
plugin.parsed?.header.masters[0] === "Skyrim.esm"
|
2022-03-10 05:59:13 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
: state.plugins.plugins
|
|
|
|
);
|
2022-03-03 03:19:26 +00:00
|
|
|
const pluginsPending = useAppSelector((state) => state.plugins.pending);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-03-15 04:47:31 +00:00
|
|
|
{plugins.length > 0 && <h2>Loaded Plugins ({plugins.length})</h2>}
|
2022-03-15 05:03:51 +00:00
|
|
|
{!selectedCell && plugins.length > 0 && (
|
|
|
|
<div className={styles.buttons}>
|
|
|
|
<button onClick={() => dispatch(enableAllPlugins())}>
|
|
|
|
Enable all
|
|
|
|
</button>
|
|
|
|
<button onClick={() => dispatch(disableAllPlugins())}>
|
|
|
|
Disable all
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-03-17 05:11:59 +00:00
|
|
|
<ol
|
|
|
|
className={`${styles["plugin-list"]} ${
|
|
|
|
plugins.length > 0 ? styles["bottom-spacing"] : ""
|
|
|
|
}`}
|
|
|
|
>
|
2022-03-03 03:19:26 +00:00
|
|
|
{plugins.map((plugin) => (
|
|
|
|
<li key={plugin.filename} title={plugin.filename}>
|
|
|
|
<input
|
|
|
|
id={plugin.filename}
|
|
|
|
type="checkbox"
|
|
|
|
disabled={
|
|
|
|
excludedPlugins.includes(plugin.filename) || !!plugin.parseError
|
|
|
|
}
|
2022-03-19 19:38:33 +00:00
|
|
|
checked={plugin.enabled ?? false}
|
|
|
|
value={plugin.enabled ? "on" : "off"}
|
2022-03-03 03:19:26 +00:00
|
|
|
onChange={() => dispatch(togglePlugin(plugin.filename))}
|
|
|
|
/>
|
|
|
|
<label htmlFor={plugin.filename} className={styles["plugin-label"]}>
|
|
|
|
{excludedPlugins.includes(plugin.filename) ? (
|
|
|
|
<span>{plugin.filename}</span>
|
|
|
|
) : (
|
|
|
|
<Link href={`/?plugin=${plugin.hash}`}>
|
|
|
|
<a
|
|
|
|
className={plugin.parseError ? styles["plugin-error"] : ""}
|
|
|
|
>
|
|
|
|
{plugin.filename}
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
</label>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ol>
|
|
|
|
{pluginsPending > 0 && (
|
|
|
|
<span className={styles.loading}>
|
|
|
|
Loading {pluginsPending} plugin{pluginsPending === 1 ? "" : "s"}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PluginsList;
|