aboutsummaryrefslogtreecommitdiffstats
path: root/thallium-frontend/src/App.tsx
blob: f5512af138ade7755b4b2ee239369290c81dbeeb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import styled, { createGlobalStyle, ThemeProvider } from "styled-components";
import React, { Suspense } from "react";
import {
  createBrowserRouter,
  RouterProvider,
} from "react-router-dom";

import themes from "./themes.tsx";

import Header from "./components/Header";
import LoadingBar from "./components/LoadingBar";

const LandingPage = React.lazy(() => import("./pages/LandingPage"));
const ErrorPage = React.lazy(() => import("./pages/ErrorPage"));
const DesignSystem = React.lazy(() => import("./pages/DesignSystem"));
const StorePage = React.lazy(() => import("./pages/StorePage"));
const CheckoutPage = React.lazy(() => import("./pages/CheckoutPage"));

import { maybeRefreshTask } from "./api/jwt";
import { ToastContainer } from "react-toastify";

import "react-toastify/dist/ReactToastify.css";
import "./styles/toast-overrides.css";
import { useMediaQuery } from "./utils/hooks.ts";


const GlobalStyle = createGlobalStyle`
  html,
  body, #root {
    margin: 0;
    padding: 0;
    font-family: 'Fira Code Variable', monospace;
    background-color: ${({ theme }) => theme.backgroundColor};
    color: ${({ theme }) => theme.textColor};
    height: 100%;
  }

  a:not(.Header-bar) {
    color: ${({ theme }) => theme.linkColor};
    text-decoration: none;
    transition: border-bottom 0.2s;
    border-bottom: 1px dotted transparent;
  }

  a:not(.Header-bar):hover {
    border-bottom: 1px dotted ${({ theme }) => theme.linkColor};
  }
`;

const AppContainer = styled.div`
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  height: 100%;
`;

const BodySeparator = styled.div`
flex-grow: 1;
`;

const ContentContainer = styled.div`
  align-self: center;
  width: 100%;
  display: flex;
  align-items: center;
  flex-direction: column;
`;

const FooterHolder = styled.footer`
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
`;

const router = createBrowserRouter([
  {
    path: "/",
    element: <LandingPage />,
    errorElement: <ErrorPage />
  },
  {
    path: "/design-system",
    element: <DesignSystem />,
    errorElement: <ErrorPage />
  },
  {
    path: "/store",
    element: <StorePage />,
    errorElement: <ErrorPage />
  },
  {
    path: "/checkout",
    element: <CheckoutPage />,
    errorElement: <ErrorPage />
  }
]);


function App() {
  const isDarkMode = useMediaQuery("(prefers-color-scheme: dark)");

  maybeRefreshTask();

  const theme = isDarkMode ? themes.dark : themes.light;

  return (
    <ThemeProvider theme={theme}>
      <AppContainer>
        <ToastContainer
          position="top-right"
          autoClose={5000}
          newestOnTop={false}
          closeOnClick
          rtl={false}
          pauseOnFocusLoss
          draggable
          pauseOnHover
          theme={isDarkMode ? "dark" : "light"}

        />
        <GlobalStyle />
        <ContentContainer>
          <Header />
          <Suspense fallback={<LoadingBar />}>
            <RouterProvider router={router} />
          </Suspense>
        </ContentContainer>

        <BodySeparator />

        <FooterHolder>
          <p>
            Made with <span role="img" aria-label="aliens">👾</span> by Owl Corp &bull; Thallium {VITE_APP_VERSION} ({VITE_COMMIT_HASH})
          </p>
        </FooterHolder>
      </AppContainer>
    </ThemeProvider>
  );
}

export default App;