|
|
|
@ -8,39 +8,48 @@ import '@fontsource/roboto/700.css';
|
|
|
|
|
|
|
|
|
|
|
|
import './css/reset.css';
|
|
|
|
import './css/reset.css';
|
|
|
|
import './css/app.css';
|
|
|
|
import './css/app.css';
|
|
|
|
import { MobileContext } from './components/infoview/context';
|
|
|
|
import { MobileContext, PreferencesContext} from './components/infoview/context';
|
|
|
|
import { useMobile } from './hooks';
|
|
|
|
import { AUTO_SWITCH_THRESHOLD, getWindowDimensions, setLayout, setisSavePreferences, PreferencesState} from './state/preferences';
|
|
|
|
import { AUTO_SWITCH_THRESHOLD, getWindowDimensions} from './state/preferences';
|
|
|
|
import { useAppDispatch, useAppSelector } from './hooks';
|
|
|
|
|
|
|
|
|
|
|
|
export const GameIdContext = React.createContext<string>(undefined);
|
|
|
|
export const GameIdContext = React.createContext<string>(undefined);
|
|
|
|
|
|
|
|
|
|
|
|
function App() {
|
|
|
|
function App() {
|
|
|
|
const { mobile, setMobile, lockMobile, setLockMobile } = useMobile();
|
|
|
|
const dispatch = useAppDispatch()
|
|
|
|
|
|
|
|
|
|
|
|
const params = useParams()
|
|
|
|
const params = useParams()
|
|
|
|
const gameId = "g/" + params.owner + "/" + params.repo
|
|
|
|
const gameId = "g/" + params.owner + "/" + params.repo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
const [mobile, setMobile] = React.useState<boolean>()
|
|
|
|
|
|
|
|
const layout = useAppSelector((state) => state.preferences.layout);
|
|
|
|
|
|
|
|
const changeLayout = (layout: PreferencesState["layout"]) => dispatch(setLayout(layout))
|
|
|
|
|
|
|
|
const isSavePreferences = useAppSelector((state) => state.preferences.isSavePreferences);
|
|
|
|
|
|
|
|
const changeIsSavePreferences = (isSave: boolean) => dispatch(setisSavePreferences(isSave))
|
|
|
|
|
|
|
|
|
|
|
|
const automaticallyAdjustLayout = () => {
|
|
|
|
const automaticallyAdjustLayout = () => {
|
|
|
|
const {width} = getWindowDimensions()
|
|
|
|
const {width} = getWindowDimensions()
|
|
|
|
setMobile(width < AUTO_SWITCH_THRESHOLD)
|
|
|
|
setMobile(width < AUTO_SWITCH_THRESHOLD)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
React.useEffect(()=>{
|
|
|
|
React.useEffect(()=>{
|
|
|
|
if (!lockMobile){
|
|
|
|
if (layout === "auto"){
|
|
|
|
void automaticallyAdjustLayout()
|
|
|
|
void automaticallyAdjustLayout()
|
|
|
|
window.addEventListener('resize', automaticallyAdjustLayout)
|
|
|
|
window.addEventListener('resize', automaticallyAdjustLayout)
|
|
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
return () => window.removeEventListener('resize', automaticallyAdjustLayout)
|
|
|
|
window.removeEventListener('resize', automaticallyAdjustLayout)
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
setMobile(layout === "mobile")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [lockMobile])
|
|
|
|
}, [layout])
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="app">
|
|
|
|
<div className="app">
|
|
|
|
<GameIdContext.Provider value={gameId}>
|
|
|
|
<GameIdContext.Provider value={gameId}>
|
|
|
|
<MobileContext.Provider value={{mobile, setMobile, lockMobile, setLockMobile}}>
|
|
|
|
<MobileContext.Provider value={{mobile, setMobile}}>
|
|
|
|
<Outlet />
|
|
|
|
<PreferencesContext.Provider value={{layout, isSavePreferences, setLayout: changeLayout, setIsSavePreferences: changeIsSavePreferences}}>
|
|
|
|
|
|
|
|
<Outlet />
|
|
|
|
|
|
|
|
</PreferencesContext.Provider>
|
|
|
|
</MobileContext.Provider>
|
|
|
|
</MobileContext.Provider>
|
|
|
|
</GameIdContext.Provider>
|
|
|
|
</GameIdContext.Provider>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|