kopia lustrzana https://github.com/bugout-dev/moonstream
set/unset appView trough App layout useeffect
rodzic
bd2001d163
commit
9c20d45845
|
@ -32,13 +32,7 @@ const UIProvider = ({ children }) => {
|
|||
const [isLoggedIn, setLoggedIn] = useState(user && user.username);
|
||||
const [isLoggingOut, setLoggingOut] = useState(false);
|
||||
const [isAppReady, setAppReady] = useState(false);
|
||||
const [isAppView, setAppView] = useState(
|
||||
router.nextRouter.asPath.includes("/stream") ||
|
||||
router.nextRouter.asPath.includes("/account") ||
|
||||
router.nextRouter.asPath.includes("/subscriptions") ||
|
||||
router.nextRouter.asPath.includes("/analytics") ||
|
||||
router.nextRouter.asPath.includes("/welcome")
|
||||
);
|
||||
const [isAppView, setAppView] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (isAppView && isAppReady && !user?.username && !isLoggingOut) {
|
||||
|
@ -69,15 +63,6 @@ const UIProvider = ({ children }) => {
|
|||
}
|
||||
}, [user]);
|
||||
|
||||
useEffect(() => {
|
||||
setAppView(
|
||||
router.nextRouter.asPath.includes("/stream") ||
|
||||
router.nextRouter.asPath.includes("/account") ||
|
||||
router.nextRouter.asPath.includes("/subscriptions") ||
|
||||
router.nextRouter.asPath.includes("/analytics") ||
|
||||
router.nextRouter.asPath.includes("/welcome")
|
||||
);
|
||||
}, [router.nextRouter.asPath, user]);
|
||||
|
||||
// *********** Sidebar states **********************
|
||||
|
||||
|
|
|
@ -1,11 +1,21 @@
|
|||
import { Flex } from "@chakra-ui/react";
|
||||
import { getLayout as getSiteLayout } from "./RootLayout";
|
||||
import React, { useContext } from "react";
|
||||
import React, { useContext, useLayoutEffect } from "react";
|
||||
import UIContext from "../core/providers/UIProvider/context";
|
||||
|
||||
const AppLayout = ({ children }) => {
|
||||
const ui = useContext(UIContext);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (ui.isAppReady) {
|
||||
ui.setAppView(true);
|
||||
return () => {
|
||||
ui.setAppView(false);
|
||||
};
|
||||
}
|
||||
//eslint-disable-next-line
|
||||
}, [ui.isAppReady]);
|
||||
|
||||
return (
|
||||
<Flex
|
||||
direction="row"
|
||||
|
|
Ładowanie…
Reference in New Issue