Skip to content

Commit

Permalink
Merge branch 'server'
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-m-2983 committed Mar 28, 2024
2 parents 6f7fbc2 + 18219e0 commit 19e7ed8
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 20 deletions.
3 changes: 1 addition & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import nextPWA from 'next-pwa';

const withPWA = nextPWA({ dest: "public" })
const nextConfig = withPWA({
output: 'export',
const nextConfig = withPWA({
basePath: "/turbo-scout",
assetPrefix: "/turbo-scout",
images: {
Expand Down
8 changes: 0 additions & 8 deletions src/app/api/download/route.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/app/api/pull/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* This route will return all of the data on the server.
*/
import { NextResponse } from "next/server";

export async function GET() {
return NextResponse.json({message: "The pull route is not yet finished!"});
}
31 changes: 31 additions & 0 deletions src/app/api/push/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* This route allows the client to send data with the server
*/
import { existsSync, mkdirSync, writeFile } from "fs";
import { NextRequest, NextResponse } from "next/server";

export async function GET() {
return NextResponse.json({ "error_message": "You cannot GET this api route!" });
}

export async function POST(
req: NextRequest
) {
const dataDir = "./turbo-data/";

if (!existsSync(dataDir)) {
mkdirSync(dataDir);
}

if (req.body == null) {
return NextResponse.json({ "error_message": "You must send some data!" });
}

//TODO: check if data is blank but not null, e.g. {} or []

const fileName = "data-" + btoa(new Date().toISOString()) + ".json";
writeFile(fileName, await req.json(), () => { });


return NextResponse.json({ "fileName": fileName });
}
8 changes: 0 additions & 8 deletions src/app/api/sync/route.ts

This file was deleted.

16 changes: 15 additions & 1 deletion src/app/lib/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,24 @@ export interface TurboState {
*/
teams?: any[]
setTeams?: Function

/**
* The sendqueue, responsible for storing things that need to be sent to the server.
*
* Please do not clear the send queue for any reason- other than after it has all been sent.
* Never use `clearSendQueue` in your code.
*/
sendQueue?: any[]
addToSendQueue?: Function
clearSendQueue?: Function // Do not call this function, otherwise bad things will happen.
}

export function useDefaultTurboState(): TurboState {
const [currentEvent, setCurrentEvent] = useLocalStorage<string | undefined>({key: "current_event", defaultValue: undefined});
const [teams, setTeams] = useLocalStorage<any[] | undefined>({key: "teams", defaultValue: undefined});
const [checkboxState, setCheckboxState] = useLocalStorage<string[]>({key: "pit_checkbox_state", defaultValue: []});
const [username, setUsername] = useLocalStorage<string>({key: "username", defaultValue: ""});
const [sendQueue, do_not_call_this] = useLocalStorage<any[]>({key: "sendqueue", defaultValue: []});

return {
currentEvent: currentEvent,
Expand All @@ -45,7 +56,10 @@ export function useDefaultTurboState(): TurboState {
checkboxState: checkboxState,
setCheckboxState: setCheckboxState,
username: username,
setUsername: setUsername
setUsername: setUsername,
sendQueue: sendQueue,
addToSendQueue: (item: any) => do_not_call_this([...sendQueue, item]),
clearSendQueue: (_: any) => do_not_call_this([])
};
}

Expand Down
9 changes: 8 additions & 1 deletion src/app/pit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ function PitScoutingMenu(props: { team: any }) {
});
};

const advanceButton: Function = () => {
setCurrentStep((current) => (current < (Object.keys(SEASON_CONFIG).length) ? current + 1 : current));
if(currentStep >= (Object.keys(SEASON_CONFIG).length)) {
alert("clicked finish!");
}
};

return <Stepper active={currentStep} onStepClick={setCurrentStep} orientation="horizontal">
{Object.entries(SEASON_CONFIG).map(([category, questions]) => <Stepper.Step label={category} key={category}>
<Stack>
{questions.map(question => <PitQuestion category={category} question={question} key={question.name} questionSetter={questionSetter} />)}
<Button onClick={() => setCurrentStep((current) => (current < (Object.keys(SEASON_CONFIG).length) ? current + 1 : current))}>
<Button onClick={() => advanceButton()}>
{currentStep != Object.keys(SEASON_CONFIG).length - 1 ? <p>Next</p> : <p>Finish</p>}
</Button>
<Button onClick={() => { console.log(JSON.stringify(collectedData)) }} color="red">
Expand Down

0 comments on commit 19e7ed8

Please sign in to comment.