mirror of
https://github.com/Vomitblood/stort.git
synced 2024-11-26 13:55:27 +08:00
added debug panel
This commit is contained in:
parent
e48611b11c
commit
f237031eb3
|
@ -1,5 +1,11 @@
|
||||||
import { BugReportOutlined, SettingsOutlined } from "@mui/icons-material";
|
import {
|
||||||
import { LoadingButton, TabContext, TabList, TabPanel } from "@mui/lab";
|
BugReportOutlined,
|
||||||
|
FormatPaintOutlined,
|
||||||
|
SettingsOutlined,
|
||||||
|
WallpaperOutlined,
|
||||||
|
WebAssetOutlined,
|
||||||
|
} from "@mui/icons-material";
|
||||||
|
import { TabContext, TabList, TabPanel } from "@mui/lab";
|
||||||
import { Box, Button, IconButton, Tab, Tooltip, useTheme } from "@mui/material";
|
import { Box, Button, IconButton, Tab, Tooltip, useTheme } from "@mui/material";
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
|
@ -10,6 +16,7 @@ import { FloatingDialog } from "../../Generic/FloatingDialog";
|
||||||
import { Background } from "./SettingsTabs/Background";
|
import { Background } from "./SettingsTabs/Background";
|
||||||
import { Style } from "./SettingsTabs/Style";
|
import { Style } from "./SettingsTabs/Style";
|
||||||
import { Window } from "./SettingsTabs/Window";
|
import { Window } from "./SettingsTabs/Window";
|
||||||
|
import { Debug } from "./SettingsTabs/Debug";
|
||||||
|
|
||||||
export const Settings = () => {
|
export const Settings = () => {
|
||||||
// contexts
|
// contexts
|
||||||
|
@ -24,8 +31,6 @@ export const Settings = () => {
|
||||||
const [settingsOpenState, setSettingsOpenState] = useState<boolean>(false);
|
const [settingsOpenState, setSettingsOpenState] = useState<boolean>(false);
|
||||||
const [settingsMaximisedState, setSettingsMaximisedState] = useState<boolean>(false);
|
const [settingsMaximisedState, setSettingsMaximisedState] = useState<boolean>(false);
|
||||||
const [subTabValue, setSubTabValue] = useState("style");
|
const [subTabValue, setSubTabValue] = useState("style");
|
||||||
const [applyLoading, setApplyLoading] = useState<boolean>(false);
|
|
||||||
const [saveLoading, setSaveLoading] = useState<boolean>(false);
|
|
||||||
|
|
||||||
const toggleSettings = () => {
|
const toggleSettings = () => {
|
||||||
setSettingsOpenState((prevState) => !prevState);
|
setSettingsOpenState((prevState) => !prevState);
|
||||||
|
@ -47,9 +52,7 @@ export const Settings = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const applyClickEvent = () => {
|
const applyClickEvent = () => {
|
||||||
setApplyLoading(true);
|
|
||||||
updateSettings(stagedSettings);
|
updateSettings(stagedSettings);
|
||||||
setApplyLoading(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveClickEvent = () => {
|
const saveClickEvent = () => {
|
||||||
|
@ -61,24 +64,11 @@ export const Settings = () => {
|
||||||
// set staged settings back to current settings on close
|
// set staged settings back to current settings on close
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!settingsOpenState) setStagedSettings(settings);
|
if (!settingsOpenState) setStagedSettings(settings);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [settingsOpenState]);
|
}, [settingsOpenState]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FloatingDialog
|
<FloatingDialog
|
||||||
actionButtons={
|
|
||||||
<>
|
|
||||||
<IconButton
|
|
||||||
onClick={() => {
|
|
||||||
router.push("/testing");
|
|
||||||
}}
|
|
||||||
sx={{
|
|
||||||
mr: 1,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<BugReportOutlined />
|
|
||||||
</IconButton>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
body={
|
body={
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
|
@ -104,22 +94,31 @@ export const Settings = () => {
|
||||||
variant="scrollable"
|
variant="scrollable"
|
||||||
>
|
>
|
||||||
<Tab
|
<Tab
|
||||||
|
icon={<FormatPaintOutlined />}
|
||||||
label="Style"
|
label="Style"
|
||||||
value="style"
|
value="style"
|
||||||
/>
|
/>
|
||||||
<Tab
|
<Tab
|
||||||
|
icon={<WallpaperOutlined />}
|
||||||
label="Background"
|
label="Background"
|
||||||
value="background"
|
value="background"
|
||||||
/>
|
/>
|
||||||
<Tab
|
<Tab
|
||||||
|
icon={<WebAssetOutlined />}
|
||||||
label="Window"
|
label="Window"
|
||||||
value="window"
|
value="window"
|
||||||
/>
|
/>
|
||||||
|
<Tab
|
||||||
|
icon={<BugReportOutlined />}
|
||||||
|
label="Debug"
|
||||||
|
value="debug"
|
||||||
|
/>
|
||||||
</TabList>
|
</TabList>
|
||||||
<Box
|
<Box
|
||||||
overflow="auto"
|
|
||||||
sx={{
|
sx={{
|
||||||
height: "100%",
|
height: "100%",
|
||||||
|
overflowY: "auto",
|
||||||
|
m: 0,
|
||||||
width: "100%",
|
width: "100%",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -141,6 +140,12 @@ export const Settings = () => {
|
||||||
>
|
>
|
||||||
<Window />
|
<Window />
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
<TabPanel
|
||||||
|
sx={{ p: 2 }}
|
||||||
|
value="debug"
|
||||||
|
>
|
||||||
|
<Debug />
|
||||||
|
</TabPanel>
|
||||||
</Box>
|
</Box>
|
||||||
</TabContext>
|
</TabContext>
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -164,8 +169,7 @@ export const Settings = () => {
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<LoadingButton
|
<Button
|
||||||
loading={applyLoading}
|
|
||||||
onClick={applyClickEvent}
|
onClick={applyClickEvent}
|
||||||
size="small"
|
size="small"
|
||||||
sx={{
|
sx={{
|
||||||
|
@ -174,15 +178,14 @@ export const Settings = () => {
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
>
|
>
|
||||||
Apply
|
Apply
|
||||||
</LoadingButton>
|
</Button>
|
||||||
<LoadingButton
|
<Button
|
||||||
loading={saveLoading}
|
|
||||||
onClick={saveClickEvent}
|
onClick={saveClickEvent}
|
||||||
size="small"
|
size="small"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
>
|
>
|
||||||
Save
|
Save
|
||||||
</LoadingButton>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
}
|
}
|
||||||
close={closeSettings}
|
close={closeSettings}
|
||||||
|
|
|
@ -18,7 +18,7 @@ interface BackgroundProps {
|
||||||
|
|
||||||
export const Background: FC<BackgroundProps> = ({ sx }) => {
|
export const Background: FC<BackgroundProps> = ({ sx }) => {
|
||||||
// contexts
|
// contexts
|
||||||
const { settings, updateSettings } = useSettings();
|
const { settings } = useSettings();
|
||||||
|
|
||||||
// atoms
|
// atoms
|
||||||
const [stagedSettings, setStagedSettings] = useAtom(stagedSettingsAtom);
|
const [stagedSettings, setStagedSettings] = useAtom(stagedSettingsAtom);
|
||||||
|
@ -112,6 +112,7 @@ export const Background: FC<BackgroundProps> = ({ sx }) => {
|
||||||
applyWallpaper();
|
applyWallpaper();
|
||||||
|
|
||||||
setOldWallpaperPath(settings.background.background_image_path);
|
setOldWallpaperPath(settings.background.background_image_path);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [settings.background.background_image_path]);
|
}, [settings.background.background_image_path]);
|
||||||
|
|
||||||
// update the preview image when stagedSettings.background.background_image_path changes
|
// update the preview image when stagedSettings.background.background_image_path changes
|
||||||
|
|
47
src/components/HeaderBar/Settings/SettingsTabs/Debug.tsx
Normal file
47
src/components/HeaderBar/Settings/SettingsTabs/Debug.tsx
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
import { Box, Typography } from "@mui/material";
|
||||||
|
import { FC } from "react";
|
||||||
|
import { useSettings } from "../../../../contexts/SettingsContext";
|
||||||
|
import { CategoryTitle } from "../CategoryTitle";
|
||||||
|
|
||||||
|
interface DebugProps {
|
||||||
|
sx?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Debug: FC<DebugProps> = ({ sx }) => {
|
||||||
|
// contexts
|
||||||
|
const { settings, resetSettings } = useSettings();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ sx }}>
|
||||||
|
<CategoryTitle title="Debug Panel" />
|
||||||
|
<Typography
|
||||||
|
color="error"
|
||||||
|
variant="h6"
|
||||||
|
>
|
||||||
|
Here do be dragons
|
||||||
|
</Typography>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
resetSettings();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
reset settings
|
||||||
|
</button>
|
||||||
|
<button>update settings</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
console.log(settings);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
log settings
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
console.log(settings.background.background_image_path);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
testing
|
||||||
|
</button>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
Loading…
Reference in a new issue