Repository navigation
Viewer -> Drivers app master #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: drivers-app/master
Are you sure you want to change the base?
Changes from all commits
37f6a26
37734ec
fa35025
a8dcdfe
b1b04c2
11a0680
044bc58
1241684
f3d7729
f637cfb
1ac97ae
c7a82f1
9d32806
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,5 @@ dist | |
| .secret.env | ||
| .env | ||
| dev-dist | ||
| sheets-key.json | ||
| sheets-key.json | ||
| /apps/drivers/backend/temp/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import axios from "axios"; | ||
| import { parseDates } from "@repo/flow-utils"; | ||
|
|
||
| axios.interceptors.response.use((response) => { | ||
| parseDates(response.data); | ||
| return response; | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import type { DrivingData } from "@repo/drivers-types"; | ||
| import axios from "axios"; | ||
| import { SERVER_URL } from "../App.tsx"; | ||
| import { LogSelector } from "./components/LogSelector.tsx"; | ||
| import { ScoresDisplay } from "./components/ScoresDisplay.tsx"; | ||
| import { StatusCodes } from "http-status-codes"; | ||
|
|
||
| export const DataViewer = () => { | ||
| const [drivingDataArray, setDrivingDataArray] = useState<DrivingData[]>([]); | ||
| const [drivingData, setDrivingData] = useState<DrivingData | undefined>( | ||
| undefined, | ||
| ); | ||
| const [errorMessage, setErrorMessage] = useState<string>(""); | ||
| useEffect(() => { | ||
| axios.get(SERVER_URL + "/logs").then( | ||
| (result) => { | ||
| if (result.status === StatusCodes.OK) { | ||
| setDrivingDataArray(result.data); | ||
| setErrorMessage(""); | ||
| } else { | ||
| setErrorMessage("Error " + result.statusText + ": " + result.data); | ||
| } | ||
| }, | ||
| (error: Error) => | ||
| setErrorMessage( | ||
| `Error ${error.name}: ${error.message} at ${error.stack}`, | ||
|
hillelv marked this conversation as resolved.
Resolved
|
||
| ), | ||
| ); | ||
| }, []); | ||
| return ( | ||
| <> | ||
| <LogSelector | ||
| setDrivingData={setDrivingData} | ||
| drivingDataArray={drivingDataArray} | ||
| /> | ||
| <ScoresDisplay drivingData={drivingData} /> | ||
| {errorMessage && <h2>{errorMessage}</h2>} | ||
| </> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import * as React from "react"; | ||
| import { type ChangeEvent, type SetStateAction, useEffect } from "react"; | ||
| import { type DrivingData } from "@repo/drivers-types"; | ||
|
|
||
| interface SelectorProps { | ||
| setDrivingData: React.Dispatch<SetStateAction<DrivingData | undefined>>; | ||
| drivingDataArray: DrivingData[]; | ||
| } | ||
|
|
||
| export const LogSelector: React.FC<SelectorProps> = ({ | ||
| setDrivingData, | ||
| drivingDataArray, | ||
| }) => { | ||
| const setDrivingDataOnChange = ( | ||
| changeEvent: ChangeEvent<HTMLSelectElement>, | ||
| ) => { | ||
| setDrivingData(drivingDataArray[Number(changeEvent.target.value)]); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| if (drivingDataArray.length > 0) { | ||
| setDrivingData(drivingDataArray[0]); | ||
| } | ||
| }, [drivingDataArray]); | ||
|
|
||
| return ( | ||
| <> | ||
| <select id={"driving data selector"} onChange={setDrivingDataOnChange}> | ||
| <optgroup label={"competition"}> | ||
| {drivingDataArray.map((drivingData, index) => { | ||
| if (drivingData.log.match.type !== "test") { | ||
| return ( | ||
| <option key={index} value={index}> | ||
| {`${drivingData.log.match.type} ${drivingData.log.match.number}`} | ||
| </option> | ||
|
Comment on lines
+30
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typescript is a lil dum dum and can't understant the type verification in the filter so I'd need to check with the if either way, so I didn't add the redundant filter |
||
| ); | ||
| } | ||
| })} | ||
| </optgroup> | ||
| <optgroup label={"test"}> | ||
| {drivingDataArray.map((drivingData, index) => { | ||
| if (drivingData.log.match.type === "test") { | ||
| return ( | ||
| <option key={index} value={index}> | ||
| {`${drivingData.log.name} - ${drivingData.log.date.toString()}`} | ||
| </option> | ||
| ); | ||
| } | ||
| })} | ||
| </optgroup> | ||
| </select> | ||
| </> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import * as React from "react"; | ||
| import type { DrivingData } from "@repo/drivers-types"; | ||
|
|
||
| interface ScoresDisplayProps { | ||
| drivingData: DrivingData | undefined; | ||
| } | ||
|
|
||
| export const ScoresDisplay: React.FC<ScoresDisplayProps> = ({ | ||
| drivingData, | ||
| }) => { | ||
| return ( | ||
| <> | ||
| {drivingData ? ( | ||
| Object.entries(drivingData.scores).map(([key, value]) => ( | ||
| <h3 key={key}>{key + ": " + value}</h3> | ||
| )) | ||
| ) : ( | ||
| <h3>Loading...</h3> | ||
| )} | ||
| </> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
|
|
||
| const ROOT_MARKER = "turbo.json"; | ||
|
|
||
| let cachedRoot: string | null = null; | ||
|
|
||
| export function getMonorepoRoot(currentDir: string = process.cwd()): string { | ||
| if (cachedRoot) return cachedRoot; | ||
|
|
||
| const resolvedDir = path.resolve(currentDir); | ||
|
|
||
| if (fs.existsSync(path.join(resolvedDir, ROOT_MARKER))) { | ||
| cachedRoot = resolvedDir; | ||
| return resolvedDir; | ||
| } | ||
|
|
||
| const parentDir = path.dirname(resolvedDir); | ||
|
|
||
| if (parentDir === resolvedDir) { | ||
| throw new Error(`Could not find monorepo root containing ${ROOT_MARKER}`); | ||
| } | ||
|
|
||
| return getMonorepoRoot(parentDir); | ||
| } | ||
|
|
||
| export function resolveFromRoot(...segments: string[]): string { | ||
| return path.join(getMonorepoRoot(), ...segments); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "name": "@repo/directory-paths", | ||
| "version": "0.0.0", | ||
| "type": "module", | ||
| "private": true, | ||
| "exports": { | ||
| ".": "./index.ts" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| const isoDateRegex = | ||
| /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/; | ||
|
|
||
| export function parseDates(body: any) { | ||
| if (body === null || body === undefined || typeof body !== "object") { | ||
| return body; | ||
| } | ||
|
|
||
| Object.entries(body).forEach(([key, value]) => { | ||
| if (typeof value === "string" && isoDateRegex.test(value)) { | ||
| body[key] = new Date(value); | ||
| } else if (typeof value === "object") { | ||
| parseDates(value); | ||
| } | ||
| }); | ||
| return body; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure this does the same thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but it's less informative