set titles

pull/43/head
Alexander Bentkamp 2 years ago
parent 340700aba4
commit 91c77a0d93

@ -11,18 +11,12 @@ import { AppBar, CssBaseline, Toolbar, Typography } from '@mui/material';
import { useAppSelector } from './hooks';
function App() {
const [conclusion, setConclusion] = useState("")
const [levelTitle, setLevelTitle] = useState("")
const [nbLevels, setNbLevels] = useState(0)
const [curLevel, setCurLevel] = useState(0)
const [finished, setFinished] = useState(false)
function startGame() {
setCurLevel(1)
}
type SetTitleType = {setTitle: (string) => void, setSubtitle: (string) => void}
export const SetTitleContext = React.createContext<SetTitleType>({setTitle: () => {}, setSubtitle: () => {}})
const title = ""//useAppSelector(state => state.gameApi.data.title)
function App() {
const [title, setTitle] = useState("")
const [subtitle, setSubtitle] = useState("")
return (
<div className="App">
@ -33,11 +27,13 @@ function App() {
{title}
</Typography>
<Typography variant="h6" noWrap component="div">
{levelTitle}
{subtitle}
</Typography>
</Toolbar>
</AppBar>
<Outlet />
<SetTitleContext.Provider value={{setTitle, setSubtitle}}>
<Outlet />
</SetTitleContext.Provider>
</div>
)
}

@ -32,6 +32,7 @@ import { styled, useTheme, Theme, CSSObject } from '@mui/material/styles';
import { AppBarProps as MuiAppBarProps } from '@mui/material/AppBar';
import Divider from '@mui/material/Divider';
import Markdown from './Markdown';
import { SetTitleContext } from '../App';
@ -133,6 +134,16 @@ function Level() {
const {editor, infoProvider} =
useLevelEditor(worldId, levelId, codeviewRef, infoviewRef, initialCode, onDidChangeContent)
const {setTitle, setSubtitle} = React.useContext(SetTitleContext);
useEffect(() => {
setTitle(`World: ${worldId}`)
}, [worldId])
useEffect(() => {
setSubtitle(`Level ${levelId}: ${level?.data?.title}`)
}, [level?.data?.title])
return <>
<Box style={level.isLoading ? null : {display: "none"}} display="flex" alignItems="center" justifyContent="center" sx={{ height: "calc(100vh - 64px)" }}><CircularProgress /></Box>
<Box style={level.isLoading ? {display: "none"} : null} display="flex" className="level" sx={{ mt: 0, ml: 0, mr: 0 }} >

Loading…
Cancel
Save