set/unset appView trough App layout useeffect

pull/237/head
Tim Pechersky 2021-09-06 16:33:48 +02:00
rodzic bd2001d163
commit 9c20d45845
2 zmienionych plików z 12 dodań i 17 usunięć

Wyświetl plik

@ -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 **********************

Wyświetl plik

@ -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"