[PUI] Mobile ignore warning in dev (#7009)

* enable overwrite of mobileView warning

* only show exception on dev
This commit is contained in:
Matthias Mair 2024-04-12 23:25:31 +02:00 committed by GitHub
parent f4d748ebed
commit 3467af361c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 1 deletions

View File

@ -33,6 +33,8 @@ interface LocalStateProps {
addDetailDrawer: (value: number | false) => void;
navigationOpen: boolean;
setNavigationOpen: (value: boolean) => void;
allowMobile: boolean;
setAllowMobile: (value: boolean) => void;
}
export const useLocalState = create<LocalStateProps>()(
@ -94,6 +96,10 @@ export const useLocalState = create<LocalStateProps>()(
navigationOpen: false,
setNavigationOpen: (value) => {
set({ navigationOpen: value });
},
allowMobile: false,
setAllowMobile: (value) => {
set({ allowMobile: value });
}
}),
{

View File

@ -3,6 +3,7 @@ import { lazy, useEffect } from 'react';
import { setApiDefaults } from '../App';
import { Loadable } from '../functions/loading';
import { useLocalState } from '../states/LocalState';
function checkMobile() {
const { height, width } = useViewportSize();
@ -15,6 +16,7 @@ const DesktopAppView = Loadable(lazy(() => import('./DesktopAppView')));
// Main App
export default function MainView() {
const [allowMobile] = useLocalState((state) => [state.allowMobile]);
// Set initial login status
useEffect(() => {
// Local state initialization
@ -22,7 +24,7 @@ export default function MainView() {
}, []);
// Check if mobile
if (checkMobile()) {
if (!allowMobile && checkMobile()) {
return <MobileAppView />;
}

View File

@ -3,8 +3,16 @@ import { Anchor, Center, Container, Stack, Text, Title } from '@mantine/core';
import { BaseContext } from '../contexts/BaseContext';
import { docLinks } from '../defaults/links';
import { IS_DEV } from '../main';
import { useLocalState } from '../states/LocalState';
export default function MobileAppView() {
const [setAllowMobile] = useLocalState((state) => [state.setAllowMobile]);
function ignore() {
setAllowMobile(true);
window.location.reload();
}
return (
<BaseContext>
<Center h="100vh">
@ -22,6 +30,11 @@ export default function MobileAppView() {
<Anchor href={docLinks.app}>
<Trans>Read the docs</Trans>
</Anchor>
{IS_DEV && (
<Text onClick={ignore}>
<Trans>Ignore and continue to Desktop view</Trans>
</Text>
)}
</Stack>
</Container>
</Center>