Skip to content

Commit

Permalink
use routes to render ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludea committed Sep 7, 2024
1 parent 4a02ecd commit 7c47def
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 69 deletions.
68 changes: 7 additions & 61 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,20 @@
import { useEffect, useMemo, useState } from "react";
import Grid from "@mui/material/Grid";
import Tabs from "@mui/material/Tabs";
import Tab from "@mui/material/Tab";
import AppBar from "@mui/material/AppBar";

import Grid from "@mui/material/Grid2";
import { useRoutes } from "react-router-dom";
import { ThemeProvider, createTheme } from "@mui/material/styles";

// components
import Header from "components/Header";
import routes from "routes";
import { DesktopRoutes, MobileRoutes } from "routes";
import DesktopBackground from "assets/DesktopBackground.jpg";
import MobileBackground from "assets/MobileBackground.jpg";
import SparusErrorContext from "utils/Context";

// Icons
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import HomeIcon from "@mui/icons-material/Home";

function HomePanel({ value, index }: { value: number; index: number }) {
return value === index ? (
<Grid
sx={{
display: {
sm: "none",
xs: "block",
},
height: "93%",
width: "100vw",
backgroundSize: "cover",
backgroundImage: `url(${MobileBackground})`,
}}
/>
) : null;
}

function App() {
const [globalError, setGlobalError] = useState("");
const [currentTab, setCurrentTab] = useState(0);

const theme = createTheme();
const routing = useRoutes(routes);
const DesktopRouting = useRoutes(DesktopRoutes);
const MobileRouting = useRoutes(MobileRoutes);

const errorCache = useMemo(
() => ({
Expand Down Expand Up @@ -83,12 +57,10 @@ function App() {
},
}}
>
<Grid item xs={12}>
<Grid xs={12}>

Check failure on line 60 in src/App.tsx

View workflow job for this annotation

GitHub Actions / android_build

No overload matches this call.

Check failure on line 60 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, x86_64-unknown-linux-gnu, linux_x86_64)

No overload matches this call.

Check failure on line 60 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (macos-latest, x86_64-apple-darwin, macos_x86_64)

No overload matches this call.

Check failure on line 60 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (macos-latest, aarch64-apple-darwin, macos_aarch64)

No overload matches this call.

Check failure on line 60 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (windows-latest, x86_64-pc-windows-msvc, windows_x86_64)

No overload matches this call.
<Header />
</Grid>
<Grid item xs={12}>
{routing}
</Grid>
<Grid xs={12}>{DesktopRouting}</Grid>

Check failure on line 63 in src/App.tsx

View workflow job for this annotation

GitHub Actions / android_build

No overload matches this call.

Check failure on line 63 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, x86_64-unknown-linux-gnu, linux_x86_64)

No overload matches this call.

Check failure on line 63 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (macos-latest, x86_64-apple-darwin, macos_x86_64)

No overload matches this call.

Check failure on line 63 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (macos-latest, aarch64-apple-darwin, macos_aarch64)

No overload matches this call.

Check failure on line 63 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (windows-latest, x86_64-pc-windows-msvc, windows_x86_64)

No overload matches this call.
</Grid>
<Grid
container
Expand All @@ -103,33 +75,7 @@ function App() {
},
}}
>
<HomePanel value={currentTab} index={0} />
<AppBar
position="fixed"
sx={{
top: "auto",
bottom: 0,
display: {
sm: "none",
xs: "block",
},
}}
>
<Tabs
indicatorColor="secondary"
textColor="inherit"
variant="fullWidth"
value={currentTab}
aria-label="menu tab"
onChange={(_, tab: number) => setCurrentTab(tab)}
>
<Tab icon={<HomeIcon fontSize="large" />} aria-label="home" />
<Tab
icon={<AccountCircleIcon fontSize="large" />}
aria-label="account"
/>
</Tabs>
</AppBar>
{MobileRouting}
</Grid>
</ThemeProvider>
</SparusErrorContext.Provider>
Expand Down
12 changes: 6 additions & 6 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useContext } from "react";
import IconButton from "@mui/material/IconButton";
import Grid from "@mui/material/Grid";
import Grid from "@mui/material/Grid2";
import { useNavigate, useLocation } from "react-router-dom";

// Icons
Expand All @@ -22,7 +22,7 @@ function Header() {

return (
<Grid container>
<Grid item xs={1}>
<Grid size={1}>
{location.pathname !== "/" ? (
<IconButton
color="primary"
Expand All @@ -34,8 +34,7 @@ function Header() {
) : null}
</Grid>
<Grid
item
xs={9}
size={8}
sx={{ height: 50 }}
onMouseDown={() => {
getCurrentWindow()
Expand All @@ -44,13 +43,14 @@ function Header() {
}}
/>
<Grid
item
container
size={4}
sx={{
display: {
sm: "block",
xs: "none",
},
position: "fixed",
position: "absolute",
right: 0,
}}
>
Expand Down
10 changes: 8 additions & 2 deletions src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Index from "components/Index";
import Options from "components/Options";
import MobileIndex from "views/MobileIndex";

const routes = [
export const DesktopRoutes = [
{
path: "/",
element: <Index />,
Expand All @@ -12,4 +13,9 @@ const routes = [
},
];

export default routes;
export const MobileRoutes = [
{
path: "/",
element: <MobileIndex />,
},
];
65 changes: 65 additions & 0 deletions src/views/MobileIndex.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { useState } from "react";
import Grid from "@mui/material/Grid";
import Tabs from "@mui/material/Tabs";
import Tab from "@mui/material/Tab";
import AppBar from "@mui/material/AppBar";
import MobileBackground from "assets/MobileBackground.jpg";

// Icons
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import HomeIcon from "@mui/icons-material/Home";

function HomePanel({ value, index }: { value: number; index: number }) {
return value === index ? (
<Grid
sx={{
display: {
sm: "none",
xs: "block",
},
height: "93%",
width: "100vw",
backgroundSize: "cover",
backgroundImage: `url(${MobileBackground})`,
}}
/>
) : null;
}

function MobileIndex() {
const [currentTab, setCurrentTab] = useState(0);

return (
<>
<HomePanel value={currentTab} index={0} />
<AppBar
position="fixed"
sx={{
top: "auto",
bottom: 0,
display: {
sm: "none",
xs: "block",
},
}}
>
<Tabs
indicatorColor="secondary"
textColor="inherit"
variant="fullWidth"
value={currentTab}
aria-label="menu tab"
onChange={(_, tab: number) => setCurrentTab(tab)}
>
<Tab icon={<HomeIcon fontSize="large" />} aria-label="home" />
<Tab
icon={<AccountCircleIcon fontSize="large" />}
aria-label="account"
/>
</Tabs>
</AppBar>
</>
);
}

export default MobileIndex;

0 comments on commit 7c47def

Please sign in to comment.