mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +09:00
Add useLocalStorage hook for the console toggle
Move the instance console chat/log toggle persistence into a generic useLocalStorage hook that defers the write so it never blocks the toggle update. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
92f607a864
commit
6feb9c2762
2 files changed
+36
-7
No files matched your search
@@ -25,6 +25,7 @@ import { useHost } from "../model/host";
|
||||
import InstanceStatusTag from "./InstanceStatusTag";
|
||||
import Link from "./Link";
|
||||
import { instancePublicAddress } from "../util/instance";
|
||||
import useLocalStorage from "../util/useLocalStorage";
|
||||
import { MetricRelativeDate } from "./system_metrics";
|
||||
|
||||
type MenuItem = Required<MenuProps>["items"][number];
|
||||
@@ -180,9 +181,7 @@ export default function InstanceViewPage() {
|
||||
let params = useParams();
|
||||
let instanceId = Number(params.id);
|
||||
const [maxLevel, setMaxLevel] = useState<keyof typeof lib.levels>("server");
|
||||
const [actionsOnly, setActionsOnly] = useState<boolean>(
|
||||
() => localStorage.getItem(consoleActionsOnlyKey) !== "false"
|
||||
);
|
||||
const [actionsOnly, setActionsOnly] = useLocalStorage(consoleActionsOnlyKey, true);
|
||||
|
||||
let navigate = useNavigate();
|
||||
|
||||
@@ -239,10 +238,7 @@ export default function InstanceViewPage() {
|
||||
checkedChildren="Chat"
|
||||
unCheckedChildren="Log"
|
||||
checked={actionsOnly}
|
||||
onChange={value => {
|
||||
setActionsOnly(value);
|
||||
localStorage.setItem(consoleActionsOnlyKey, String(value));
|
||||
}}
|
||||
onChange={setActionsOnly}
|
||||
/>
|
||||
<SelectMaxLogLevel
|
||||
value={maxLevel}
|
||||
|
||||
Reference in new issue
Block a user