-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: added theme colors * feat: added header and new home page #4 * feat: added navbar to the statistic screen #4 * fix: sidebar scrolling * feat: show JSON parse error
- Loading branch information
Showing
30 changed files
with
538 additions
and
249 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import * as React from 'react'; | ||
import Sheet from '@mui/joy/Sheet'; | ||
import {Button, FormControl, FormHelperText, IconButton, Stack, Typography, useTheme} from "@mui/joy"; | ||
import InfoOutlined from "@mui/icons-material/InfoOutlined"; | ||
import {useGameStatsStore} from "@common/stores/gameStatsStore"; | ||
import {ChangeEvent, useState} from "react"; | ||
import MenuIcon from '@mui/icons-material/Menu'; | ||
import { toggleSidebar } from "./helper"; | ||
import {observer} from "mobx-react"; | ||
|
||
export interface HeaderProps { | ||
compact?: boolean | ||
} | ||
|
||
const Header = observer(({ compact }: HeaderProps) => { | ||
const theme = useTheme() | ||
const { setJson, error } = useGameStatsStore() | ||
|
||
const [fileError, setFileError] = useState<string>() | ||
|
||
const onFileInput = (e: ChangeEvent<HTMLInputElement>) => { | ||
const reader = new FileReader(); | ||
|
||
reader.readAsText(e.target.files![0], "UTF-8"); | ||
reader.onload = event => { | ||
try { | ||
setJson(JSON.parse(event.target!.result as string)) | ||
setFileError(undefined) | ||
} catch (e) { | ||
console.log(e) | ||
setFileError((e as Error).message) | ||
} | ||
} | ||
reader.onerror = event => { | ||
console.error(event) | ||
setFileError("Error occured reading the file") | ||
} | ||
} | ||
|
||
return ( | ||
<Sheet | ||
sx={{ | ||
position: 'fixed', | ||
top: 0, | ||
height: 'var(--Header-height)', | ||
zIndex: 9995, | ||
gap: 1, | ||
width: "100vw", | ||
backgroundColor: compact ? "#FFF" : theme.vars.palette.primary[600] | ||
}} | ||
> | ||
<Stack | ||
direction="row" | ||
justifyContent={{ xs: compact ? "space-between" : "flex-end", md: "space-between" }} | ||
alignItems="center" | ||
spacing={0} | ||
sx={{ p: compact ? 3 : 7 }} | ||
> | ||
{!compact && <Typography level="h1" | ||
sx={{ | ||
color: "#FFF", | ||
display: { | ||
xs: "none", | ||
md: "block" | ||
} | ||
}}> | ||
THE FINALS TRACKER | ||
</Typography>} | ||
{compact && <IconButton | ||
onClick={() => toggleSidebar()} | ||
variant="outlined" | ||
color="neutral" | ||
size="sm" | ||
> | ||
<MenuIcon/> | ||
</IconButton>} | ||
<Stack | ||
direction="row" | ||
justifyContent="flex-end" | ||
alignItems="center" | ||
spacing={4} | ||
> | ||
<Button size="lg" component="a" target="_blank" href="https://the-finals-leaderboard.leonlarsson.com/" color="neutral"> | ||
Leaderboard | ||
</Button> | ||
<FormControl error={true} sx={{ width: "100%" }} > | ||
<Button size="lg" color="neutral" component="label"> | ||
Upload JSON | ||
<input type="file" | ||
accept="application/json" | ||
hidden | ||
onChange={onFileInput} /> | ||
</Button> | ||
{(error || fileError) && <FormHelperText><InfoOutlined/> {error || fileError}</FormHelperText>} | ||
</FormControl> | ||
<a href="https://github.com/Swackles/the-finals-tracker" target="_blank"> | ||
<img style={{ width: 35, height: 35 }} src={compact ? "/github-mark.svg" : "/github-mark-white.svg"}/> | ||
</a> | ||
</Stack> | ||
</Stack> | ||
</Sheet> | ||
); | ||
}) | ||
|
||
export default Header |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export function openSidebar() { | ||
if (typeof document !== 'undefined') { | ||
document.body.style.overflow = 'hidden'; | ||
document.documentElement.style.setProperty('--SideNavigation-slideIn', '1'); | ||
} | ||
} | ||
|
||
export function closeSidebar() { | ||
if (typeof document !== 'undefined') { | ||
document.documentElement.style.removeProperty('--SideNavigation-slideIn'); | ||
document.body.style.removeProperty('overflow'); | ||
} | ||
} | ||
|
||
export function toggleSidebar() { | ||
if (typeof window !== 'undefined' && typeof document !== 'undefined') { | ||
const slideIn = window | ||
.getComputedStyle(document.documentElement) | ||
.getPropertyValue('--SideNavigation-slideIn'); | ||
if (slideIn) { | ||
closeSidebar(); | ||
} else { | ||
openSidebar(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Header from "./Header" | ||
|
||
export default Header |
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
...common/models/gameStatsJson/MapVariant.ts → src/common/models/MapVariant.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from "./gameStatsJson" | ||
|
||
export * from "./Archetype" | ||
export * from "./GameMode" | ||
export * from "./MapVariant" | ||
export * from "./RoundType" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
src/common/stores/gameStatsStore/models/ArchetypeGameStats.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.