Skip to content

Commit e64d69d

Browse files
authored
Layout optimizations (#23)
* removed many unnecessary paddings, flex boxes, and optimize alignment of elements in console output box * console options reduce size to medium, remove overflow for interaction choosing window which causes extra scroll bar * execute box optimization * refacoring of imports * TD Doc Viewer formatted better * multiple bug fixes for making payload IO work * make sidebar example things copyable to clipboard * app settings can use browser local storage now (almost) correctly * show setting option to undock and redock components * add a zoomable input suitable for mobile app * make current thing shareable * make interaction window select scrollable horizontally on very small screen size
1 parent 0679671 commit e64d69d

15 files changed

+1067
-1211
lines changed

src/App.tsx

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,79 @@ import "@fontsource/roboto/300.css";
55
import "@fontsource/roboto/400.css";
66
import "@fontsource/roboto/500.css";
77
import "@fontsource/roboto/700.css";
8-
import { Box, Slide, Snackbar, ThemeProvider, Alert } from "@mui/material";
8+
import { Box, Slide, Snackbar, ThemeProvider, Alert, Checkbox, FormControl, FormControlLabel } from "@mui/material";
99
// Custom component libraries
1010
import { theme } from "./overall-theme";
11-
import { ThingClient } from './builtins/client/view';
12-
import React from "react";
11+
import { ThingClient } from './builtins/client/index';
12+
import React, { createContext, useContext, useState } from "react";
13+
import { AppSettingsType, defaultAppSettings } from "./builtins/app-settings";
14+
import { useLocalStorage } from "./builtins/hooks";
1315

1416

1517

18+
export type PageProps = {
19+
settings : AppSettingsType
20+
updateSettings : React.Dispatch<React.SetStateAction<AppSettingsType>>
21+
showSettings : boolean
22+
setShowSettings : React.Dispatch<React.SetStateAction<boolean>> | Function
23+
showSidebar : boolean
24+
setShowSidebar : React.Dispatch<React.SetStateAction<boolean>> | Function
25+
updateLocalStorage : (value : AppSettingsType) => void
26+
}
27+
28+
export const PageContext = createContext<any>({
29+
settings : defaultAppSettings,
30+
updateSettings : () => {},
31+
showSettings : false,
32+
setShowSettings : () => {},
33+
showSidebar : false,
34+
setShowSidebar : () => {},
35+
updateLocalStorage : (_ : AppSettingsType) => {},
36+
})
37+
1638
const App = () => {
1739

18-
return (
19-
<Box id='main-layout' sx={{ display : 'flex', flexGrow : 1, alignItems : 'center'}}>
20-
<ThemeProvider theme={theme}>
40+
const [showSettings, setShowSettings] = useState<boolean>(false)
41+
const [showSidebar, setShowSidebar] = useState(false)
42+
43+
const [_existingSettings, updateLocalStorage] = useLocalStorage('app-settings', defaultAppSettings)
44+
const [settings, updateSettings] = useState<AppSettingsType>(_existingSettings)
45+
46+
const pageState = { settings, updateSettings, showSettings, setShowSettings,
47+
showSidebar, setShowSidebar, updateLocalStorage }
48+
49+
return (
50+
<ThemeProvider theme={theme}>
51+
<PageContext.Provider value={pageState}>
2152
<ThingClient />
2253
<OnLoadMessage />
23-
</ThemeProvider>
24-
</Box>
54+
</PageContext.Provider>
55+
</ThemeProvider>
2556
)
2657
}
2758

2859

2960
const OnLoadMessage = () => {
3061

31-
const [open, setOpen] = React.useState(true);
62+
const { settings, updateLocalStorage } = useContext(PageContext) as PageProps
63+
const [showWarningAgain, setShowWarningAgain] = useState(settings.showWebsiteWarningAgain);
64+
const [open, setOpen] = useState(showWarningAgain);
3265

3366
const handleClose = (event?: React.SyntheticEvent, reason?: string) => {
34-
if (reason === 'clickaway') {
35-
return;
36-
}
67+
if (reason === 'clickaway')
68+
return
69+
if (settings.useLocalStorage)
70+
updateLocalStorage({ ...settings, showWebsiteWarningAgain: showWarningAgain })
3771
setOpen(false);
3872
};
3973

74+
if (!settings.showWebsiteWarningAgain)
75+
return null
76+
4077
return (
4178
<Snackbar
4279
open={open}
4380
onClose={handleClose}
44-
TransitionComponent={(props) => <Slide {...props} direction="up" />}
4581
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
4682
>
4783
<Alert onClose={handleClose} severity="warning" sx={{ width: '100%' }}>
@@ -51,13 +87,25 @@ const OnLoadMessage = () => {
5187
<li>check your server configuration for CORS headers and allow CORS on the browser</li>
5288
<li>please do report security issues at the GitHub Repository</li>
5389
</ul>
54-
Please use it at your own risk. This website does not use cookies.
90+
Please use it at your own risk. This website does not use cookies. <br />
91+
{settings.useLocalStorage ?
92+
<FormControlLabel
93+
label="Dont show this message again"
94+
control={
95+
<Checkbox size="small"
96+
onChange={(event) => setShowWarningAgain(!event.target.checked)}
97+
/>
98+
}
99+
checked={!showWarningAgain}
100+
/> : null
101+
}
55102
</Alert>
56103
</Snackbar>
57104
)
58105
}
59106

60107

108+
61109
export default App
62110

63111

0 commit comments

Comments
 (0)