Merge pull request #2672 from MartinFournier/fix/sidebar-stays-collapsed

Keep the sidebar opened or closed on reload
This commit is contained in:
hydroflame 2022-01-17 15:52:01 -05:00 committed by GitHub
commit a9a2764d62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

@ -142,6 +142,11 @@ interface IDefaultSettings {
* Character overview settings * Character overview settings
*/ */
overview: OverviewSettings; overview: OverviewSettings;
/**
* If the game's sidebar is opened
*/
IsSidebarOpened: boolean;
} }
/** /**
@ -194,6 +199,7 @@ export const defaultSettings: IDefaultSettings = {
SuppressSavedGameToast: false, SuppressSavedGameToast: false,
UseIEC60027_2: false, UseIEC60027_2: false,
ExcludeRunningScriptsFromSave: false, ExcludeRunningScriptsFromSave: false,
IsSidebarOpened: true,
theme: defaultTheme, theme: defaultTheme,
styles: defaultStyles, styles: defaultStyles,
@ -231,6 +237,8 @@ export const Settings: ISettings & ISelfInitializer & ISelfLoading = {
SuppressSavedGameToast: defaultSettings.SuppressSavedGameToast, SuppressSavedGameToast: defaultSettings.SuppressSavedGameToast,
UseIEC60027_2: defaultSettings.UseIEC60027_2, UseIEC60027_2: defaultSettings.UseIEC60027_2,
ExcludeRunningScriptsFromSave: defaultSettings.ExcludeRunningScriptsFromSave, ExcludeRunningScriptsFromSave: defaultSettings.ExcludeRunningScriptsFromSave,
IsSidebarOpened: defaultSettings.IsSidebarOpened,
MonacoTheme: "monokai", MonacoTheme: "monokai",
MonacoInsertSpaces: false, MonacoInsertSpaces: false,
MonacoFontSize: 20, MonacoFontSize: 20,

@ -106,6 +106,8 @@ interface IProps {
player: IPlayer; player: IPlayer;
router: IRouter; router: IRouter;
page: Page; page: Page;
opened: boolean;
onToggled: (newValue: boolean) => void;
} }
export function SidebarRoot(props: IProps): React.ReactElement { export function SidebarRoot(props: IProps): React.ReactElement {
@ -337,8 +339,13 @@ export function SidebarRoot(props: IProps): React.ReactElement {
}, []); }, []);
const classes = useStyles(); const classes = useStyles();
const [open, setOpen] = useState(true); const [open, setOpen] = useState(props.opened);
const toggleDrawer = (): void => setOpen((old) => !old); const toggleDrawer = (): void => setOpen((old) => !old);
useEffect(() => {
props.onToggled(open);
}, [open]);
return ( return (
<Drawer open={open} anchor="left" variant="permanent"> <Drawer open={open} anchor="left" variant="permanent">
<ListItem classes={{ root: classes.listitem }} button onClick={toggleDrawer}> <ListItem classes={{ root: classes.listitem }} button onClick={toggleDrawer}>

@ -78,6 +78,7 @@ import { Context } from "./Context";
import { RecoveryMode, RecoveryRoot } from "./React/RecoveryRoot"; import { RecoveryMode, RecoveryRoot } from "./React/RecoveryRoot";
import { AchievementsRoot } from "../Achievements/AchievementsRoot"; import { AchievementsRoot } from "../Achievements/AchievementsRoot";
import { ErrorBoundary } from "./ErrorBoundary"; import { ErrorBoundary } from "./ErrorBoundary";
import { Settings } from "../Settings/Settings";
const htmlLocation = location; const htmlLocation = location;
@ -220,6 +221,7 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
const [cinematicText, setCinematicText] = useState(""); const [cinematicText, setCinematicText] = useState("");
const [errorBoundaryKey, setErrorBoundaryKey] = useState<number>(0); const [errorBoundaryKey, setErrorBoundaryKey] = useState<number>(0);
const [sidebarOpened, setSideBarOpened] = useState(Settings.IsSidebarOpened);
function resetErrorBoundary(): void { function resetErrorBoundary(): void {
setErrorBoundaryKey(errorBoundaryKey + 1); setErrorBoundaryKey(errorBoundaryKey + 1);
@ -517,7 +519,12 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
</Overview> </Overview>
{withSidebar ? ( {withSidebar ? (
<Box display="flex" flexDirection="row" width="100%"> <Box display="flex" flexDirection="row" width="100%">
<SidebarRoot player={player} router={Router} page={page} /> <SidebarRoot player={player} router={Router} page={page}
opened={sidebarOpened}
onToggled={(isOpened) => {
setSideBarOpened(isOpened);
Settings.IsSidebarOpened = isOpened;
}} />
<Box className={classes.root}>{mainPage}</Box> <Box className={classes.root}>{mainPage}</Box>
</Box> </Box>
) : ( ) : (