Skip to content

Commit

Permalink
reworking system start/app login flow. changes made ot the workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
siddheshraze committed Feb 26, 2024
1 parent 803f16e commit 7dfbb8b
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 46 deletions.
22 changes: 12 additions & 10 deletions frontend/app/(hub)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import {Census, Plot, Quadrat, siteConfig} from "@/config/macros";
import CircularProgress from "@mui/joy/CircularProgress";
import Sidebar from "@/components/sidebar";
import Header from "@/components/header";
import {Box} from "@mui/joy";
import {Box, Stack} from "@mui/joy";
import Divider from "@mui/joy/Divider";
import {loadServerDataIntoIDB} from "@/components/client/clientmacros";
import {LinearProgressWithLabel, loadServerDataIntoIDB} from "@/components/client/clientmacros";
import Typography from "@mui/joy/Typography";

function renderSwitch(endpoint: string) {
switch (endpoint) {
Expand Down Expand Up @@ -74,10 +75,6 @@ export default function HubLayout({children,}: Readonly<{ children: React.ReactN
const [loading, setLoading] = useState(0);
const [loadingMsg, setLoadingMsg] = useState('');
const [coreDataLoading, setCoreDataLoading] = useState(true);
let currentCensus = useCensusContext();
let currentPlot = usePlotContext();
const plotDispatch = usePlotDispatch();
const censusDispatch = useCensusDispatch();
const censusLoadDispatch = useCensusLoadDispatch();
const quadratsLoadDispatch = useQuadratsLoadDispatch();
const plotsLoadDispatch = usePlotsLoadDispatch();
Expand Down Expand Up @@ -124,8 +121,9 @@ export default function HubLayout({children,}: Readonly<{ children: React.ReactN
let pathname = usePathname();

const fetchAndDispatchCoreData = useCallback(async () => {
const delay = (ms: number | undefined) => new Promise(resolve => setTimeout(resolve, ms));
setCoreDataLoading(true);

setLoading(0);
// IDB load stored separately: QUADRATS
await loadServerDataIntoIDB('quadrats');
setLoadingMsg('Retrieving Quadrats...');
Expand All @@ -139,12 +137,14 @@ export default function HubLayout({children,}: Readonly<{ children: React.ReactN
let quadratList: Quadrat[] = await getData('quadratList');
setLoading(30);
if (!quadratList || quadratList.length === 0) throw new Error('quadratsList data failed');
await delay(500);
setLoading(40);
setLoadingMsg('Dispatching Quadrat List...');
setLoading(40)
if (quadratListDispatch) quadratListDispatch({quadratList: quadratList});

// IDB load stored separately: CENSUS
await loadServerDataIntoIDB('census');
await delay(500);
setLoading(50);
setLoadingMsg('Retrieving Census...');
let censusRDSLoad: CensusRDS[] = await getData('censusLoad');
Expand All @@ -157,6 +157,7 @@ export default function HubLayout({children,}: Readonly<{ children: React.ReactN

// IDB load stored separately: PLOTS
await loadServerDataIntoIDB('plots');
await delay(500);
setLoading(70);
setLoadingMsg('Retrieving Plots...');
// Check if plotsLoad data is available in localStorage
Expand All @@ -167,16 +168,17 @@ export default function HubLayout({children,}: Readonly<{ children: React.ReactN
// Check if plotList data is available in localStorage
const plotListData = await getData('plotList');
if (!plotListData || plotListData.length === 0) throw new Error('plotList data failed');
await delay(500);
setLoading(90);
setLoadingMsg('Dispatching Plot List...');
if (plotsListDispatch) plotsListDispatch({plotList: plotListData});

setLoading(100);
setCoreDataLoading(false);
}, [censusListDispatch, censusLoadDispatch, plotsListDispatch, plotsLoadDispatch, quadratListDispatch, quadratsLoadDispatch]);
return (
<>
{coreDataLoading ? (
<CircularProgress determinate value={loading} variant={"soft"} title={loadingMsg}/>
<LinearProgressWithLabel value={loading} currentlyrunningmsg={loadingMsg} />
) : (
<>
<Sidebar/>
Expand Down
3 changes: 0 additions & 3 deletions frontend/app/api/auth/[[...nextauth]]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const handler = NextAuth({
session: {
strategy: "jwt"
},
pages: {
signIn: "/login",
},
callbacks: {
async jwt({token, account}) {
if (account) {
Expand Down
21 changes: 18 additions & 3 deletions frontend/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
export default function Page() {
return <>Accidentally reached root page, yikes :/</>;
}
"use client";

import {useSession} from "next-auth/react";
import {redirect} from "next/navigation";
import {Stack} from "@mui/joy";
import CircularProgress from "@mui/joy/CircularProgress";
import Typography from "@mui/joy/Typography";

export default function HomePage() {
const {data: _session, status} = useSession();

if (status === "authenticated") redirect('/dashboard');
else if (status === "unauthenticated") redirect('/login');
else return <Stack direction={"column"} sx={{ alignItems: 'center'}}>
<CircularProgress size={"lg"} variant={"soft"} color={'primary'} />
<Typography color={"warning"} level={"title-md"}>Loading...</Typography>
</Stack>
}
27 changes: 27 additions & 0 deletions frontend/components/client/clientmacros.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {CensusRDS, PlotRDS, QuadratsRDS} from "@/config/sqlmacros";
import {Census, Plot, Quadrat} from "@/config/macros";
import {useCensusLoadDispatch, usePlotsLoadDispatch, useQuadratsLoadDispatch} from "@/app/contexts/coredataprovider";
import {useCensusListDispatch, usePlotListDispatch, useQuadratListDispatch} from "@/app/contexts/listselectionprovider";
import {Box, Typography} from "@mui/material";
import React from "react";
import { LinearProgress, LinearProgressProps } from "@mui/joy";

async function updateQuadratsIDB() {
const quadratRDSResponse = await fetch(`/api/fetchall/quadrats`, {method: 'GET'});
Expand Down Expand Up @@ -100,3 +103,27 @@ export async function loadServerDataIntoIDB(dataType: string) {
throw new Error('incorrect data type provided to loadServerDataIntoIDB, verify');
}
}

export function LinearProgressWithLabel(props: LinearProgressProps & { value?: number, currentlyrunningmsg?: string }) {
return (
<Box sx={{display: 'flex', flex: 1, alignItems: 'center', flexDirection: 'column'}}>
<Box sx={{ mr: 1}}>
{props.value ? (
<LinearProgress size={"lg"} determinate {...props} />
) : (
<LinearProgress size={"lg"} {...props} />
)}
</Box>
<Box sx={{minWidth: 35, display: 'flex', flex: 1, flexDirection: 'column'}}>
{props.value ? (
<Typography variant="body2" color="text.secondary">{`${Math.round(
props?.value,
)}% --> ${props?.currentlyrunningmsg}`}</Typography>
) : (
<Typography variant="body2" color="text.secondary">{`${props?.currentlyrunningmsg}`}</Typography>
)}

</Box>
</Box>
);
}
2 changes: 1 addition & 1 deletion frontend/components/loginlogout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const LoginLogout = () => {
</Typography>
</Box>
<IconButton size="sm" variant="plain" color="neutral" onClick={() => void signOut()}>
{status == "loading" ? <CircularProgress/> : <LogoutRoundedIcon/>}
{status == "loading" ? <CircularProgress size={"lg"}/> : <LogoutRoundedIcon/>}
</IconButton>
</Box>
);
Expand Down
7 changes: 4 additions & 3 deletions frontend/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ export default function Sidebar() {

if (loading) {
return (
<Box display="flex" justifyContent="center" alignItems="center">
<CircularProgress/>
<Box display="flex" justifyContent="center" alignItems="center" sx={{flexDirection: 'column'}}>
<CircularProgress size={"lg"} variant={"soft"} color={'primary'} />
<Typography color={"warning"} level={"title-md"}>Loading Sidebar...</Typography>
</Box>
);
}
Expand Down Expand Up @@ -206,7 +207,7 @@ export default function Sidebar() {
})}
/>
<Box sx={{display: 'flex', gap: 1, alignItems: 'left'}}>
<Typography level="h1">ForestGEO: <Typography className={"text-teal-400"}>Panama</Typography></Typography>
<Typography level="h1">ForestGEO: <Typography className={"text-teal-400"}>C. & S. America</Typography></Typography>
</Box>
<Divider orientation={"horizontal"}/>
<Box
Expand Down
18 changes: 2 additions & 16 deletions frontend/components/uploadsystem/uploadfire.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {FileCollectionRowSet, FileRow, ReviewStates, UploadFireProps} from '@/co
import {FileWithPath} from "react-dropzone";
import {Stack} from "@mui/joy";
import {CMIDRow} from "@/components/uploadsystem/uploadparent";
import {LinearProgressWithLabel} from "@/components/client/clientmacros";

interface IdToRow {
coreMeasurementID: number;
Expand Down Expand Up @@ -77,21 +78,6 @@ const UploadFire: React.FC<UploadFireProps> = ({
}
}, [currentCensus?.censusID, currentPlot?.key, setErrorComponent, setReviewState, setUploadError, user]);

function LinearProgressWithLabel(props: LinearProgressProps & { value: number, currentlyrunningmsg: string }) {
return (
<Box sx={{display: 'flex', alignItems: 'center'}}>
<Box sx={{width: '100%', mr: 1}}>
<LinearProgress variant="determinate" {...props} />
</Box>
<Box sx={{minWidth: 35, display: 'flex', flex: 1, flexDirection: 'column'}}>
<Typography variant="body2" color="text.secondary">{`${Math.round(
props.value,
)}% --> ${props.currentlyrunningmsg}`}</Typography>
</Box>
</Box>
);
}

useEffect(() => {
switch (uploadForm) {
case "fixeddata_codes.csv":
Expand Down Expand Up @@ -162,7 +148,7 @@ const UploadFire: React.FC<UploadFireProps> = ({
<Box sx={{display: 'flex', flex: 1, width: '100%', alignItems: 'center', mt: 4}}>
<Stack direction={"column"}>
<Typography variant="h6" gutterBottom>{`Total Operations: ${totalOperations}`}</Typography>
<LinearProgressWithLabel variant={"determinate"} value={(completedOperations / totalOperations) * 100}
<LinearProgressWithLabel determinate value={(completedOperations / totalOperations) * 100}
currentlyrunningmsg={currentlyRunning}/>
</Stack>
</Box>
Expand Down
10 changes: 0 additions & 10 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
// output: "standalone",
async redirects() {
return [
{
source: '/',
destination: '/login',
permanent: false,
},
]
},
logging: {
fetches: {
fullUrl: true,
Expand Down

0 comments on commit 7dfbb8b

Please sign in to comment.