AppWrapper.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { Flex } from "reflexbox/styled-components";
  2. import React, { useEffect } from "react";
  3. import styled from "styled-components";
  4. import Router from "next/router";
  5. import { useStoreState, useStoreActions } from "../store";
  6. import PageLoading from "./PageLoading";
  7. import Header from "./Header";
  8. const Wrapper = styled(Flex)`
  9. input {
  10. filter: none;
  11. }
  12. * {
  13. box-sizing: border-box;
  14. }
  15. *::-moz-focus-inner {
  16. border: none;
  17. }
  18. `;
  19. const AppWrapper = ({ children }: { children: any }) => {
  20. const isAuthenticated = useStoreState(s => s.auth.isAuthenticated);
  21. const logout = useStoreActions(s => s.auth.logout);
  22. const fetched = useStoreState(s => s.settings.fetched);
  23. const loading = useStoreState(s => s.loading.loading);
  24. const getSettings = useStoreActions(s => s.settings.getSettings);
  25. useEffect(() => {
  26. if (isAuthenticated && !fetched) {
  27. getSettings().catch(() => logout());
  28. }
  29. }, []);
  30. return (
  31. <Wrapper
  32. minHeight="100vh"
  33. width={1}
  34. flex="0 0 auto"
  35. alignItems="center"
  36. flexDirection="column"
  37. >
  38. <Header />
  39. {loading ? <PageLoading /> : children}
  40. </Wrapper>
  41. );
  42. };
  43. export default AppWrapper;