Skip to content

Commit

Permalink
fix: better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Battlesquid committed Dec 18, 2024
1 parent b7cab4e commit 03e10e8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
34 changes: 28 additions & 6 deletions packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export default function App() {
towerDampening: 4
});

const [fallback, setFallback] = useState<Pick<SkylineModelParameters, "name" | "year">>({
name: "Battlesquid",
year: new Date().getFullYear()
});

const [requestOk, setRequestOk] = useState(true);

const [mobileOpened, { toggle: toggleMobile }] = useDisclosure();
const [desktopOpened, { toggle: toggleDesktop }] = useDisclosure(true);

Expand All @@ -52,13 +59,30 @@ export default function App() {
const [ready, setReady] = useState(false);

useEffect(() => {
setRequestOk(true);
setReady(
localStorage.getItem("token") !== null
&& !result.fetching
)
}, [result.fetching]);

const appContent = ready
useEffect(() => {
if (result.data?.user) {
setFallback({
name: parameters.name,
year: parameters.year
});
} else {
setRequestOk(false);
setParameters({
...parameters,
name: fallback.name,
year: fallback.year
})
}
}, [result.data]);

const content = ready
? (
<>
<Skyline
Expand All @@ -84,17 +108,15 @@ export default function App() {
>
<AppShell.Navbar p="md">
<Sidebar
ready={ready}
authenticated={localStorage.getItem("token") !== null}
ok={requestOk}
parameters={parameters}
setParameters={setParameters}
onExport={() => {

}}
/>
</AppShell.Navbar>
<AppShell.Main style={{ height: "calc(100vh)", backgroundColor: theme.colors.dark[7] }}>
<LoadingOverlay visible={result.fetching} zIndex={1000} overlayProps={{ radius: "sm", blur: 2 }} />
{appContent}
{content}
<t.Out />
</AppShell.Main>
</AppShell >
Expand Down
22 changes: 17 additions & 5 deletions packages/app/src/components/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppShell, Button, Checkbox, ColorInput, Divider, NumberInput, Stack, TextInput, Tooltip } from "@mantine/core";
import { SkylineModelParameters } from "../App";
import { useState } from "react";
import { useEffect, useState } from "react";
import { useSceneStore } from "../scene";
import { STLExporter } from "three/examples/jsm/Addons.js";

Expand All @@ -10,19 +10,30 @@ export interface GenerateOptions {
}

interface SidebarProps {
ready: boolean;
authenticated: boolean;
ok: boolean;
setParameters: React.Dispatch<React.SetStateAction<SkylineModelParameters>>;
parameters: SkylineModelParameters;
onExport(): void;
}

export function Sidebar(props: SidebarProps) {
const { ready, parameters, setParameters } = props;
const { authenticated, ok, parameters, setParameters } = props;
const [name, setName] = useState(parameters.name);
const [year, setYear] = useState(parameters.year);
const [modified, setModified] = useState(false);
const { scene, dirty } = useSceneStore();

if (!ready) {
useEffect(() => {
setModified(false);
}, [ok]);

useEffect(() => {
if (!ok) {
setModified(true);
}
}, [name])

if (!authenticated) {
return (
<AppShell.Section h="100%">
<h2>skyline</h2>
Expand All @@ -46,6 +57,7 @@ export function Sidebar(props: SidebarProps) {
placeholder="Github Username"
value={name}
onChange={e => setName(e.target.value)}
error={ok || modified ? "" : `Unable to find profile for "${name}".`}
/>
<NumberInput
label="Year"
Expand Down

0 comments on commit 03e10e8

Please sign in to comment.