From 549bc8232ad7efcc87878ef6f9d2a6017e2e1daf Mon Sep 17 00:00:00 2001 From: renatodellosso Date: Sat, 25 May 2024 12:35:49 -0400 Subject: [PATCH 1/2] Check in works now. --- components/Avatar.tsx | 3 +- lib/API.ts | 13 ++------ lib/Types.ts | 7 ++-- lib/client/ClientAPI.ts | 10 ++---- .../[competitonSlug]/[reportId]/index.tsx | 8 +++++ .../[seasonSlug]/[competitonSlug]/index.tsx | 33 ++++++++++++++----- 6 files changed, 43 insertions(+), 31 deletions(-) diff --git a/components/Avatar.tsx b/components/Avatar.tsx index e5fd1434..bccd87f1 100644 --- a/components/Avatar.tsx +++ b/components/Avatar.tsx @@ -11,6 +11,7 @@ export default function Avatar(props: { borderThickness?: number | undefined; onClick?: () => void | undefined; className?: string | undefined; + online?: boolean; }) { const { session, status } = useCurrentSession(); const user = props.user ?? session?.user; @@ -19,7 +20,7 @@ export default function Avatar(props: { const admin = user?.admin; return ( -
+
{ (props.showLevel ?? true) &&
LVL: {user?.level} diff --git a/lib/API.ts b/lib/API.ts index c7bfa09c..c536fd9d 100644 --- a/lib/API.ts +++ b/lib/API.ts @@ -554,7 +554,6 @@ export namespace API { form.data = data.formData; form.submitted = true; - form.checkedIn = false; form.submitter = data.userId; await db.updateObjectById( @@ -632,19 +631,11 @@ export namespace API { ); }, - updateCheckIn: async (req, res, { db, data }) => { + checkInForReport: async (req, res, { db, data }) => { await db.updateObjectById( Collections.Reports, new ObjectId(data.reportId), - { checkedIn: true } - ); - }, - - updateCheckOut: async (req, res, { db, data }) => { - await db.updateObjectById( - Collections.Reports, - new ObjectId(data.reportId), - { checkedIn: false } + { checkInTimestamp: new Date().toISOString() } ); }, diff --git a/lib/Types.ts b/lib/Types.ts index 121a8e0f..2fe7ad98 100644 --- a/lib/Types.ts +++ b/lib/Types.ts @@ -6,6 +6,7 @@ import { } from "next-auth"; import { TheBlueAlliance } from "./TheBlueAlliance"; import { Statbotics } from "./Statbotics"; +import { DatasetJsonLdProps } from "next-seo"; /** * Standard Account Type @@ -322,7 +323,7 @@ export class Report { submitted: boolean = false; data: FormData; - checkedIn: boolean = false; + checkInTimestamp: string | undefined; constructor( user: string | undefined, @@ -331,7 +332,7 @@ export class Report { color: AllianceColor, match: string, timestamp: number = 0, - checkedIn: boolean + checkInTimestamp: string | undefined = undefined ) { this.timestamp = timestamp; this.user = user; @@ -339,7 +340,7 @@ export class Report { this.robotNumber = robotNumber; this.match = match; this.color = color; - this.checkedIn = checkedIn; + this.checkInTimestamp = checkInTimestamp; } } diff --git a/lib/client/ClientAPI.ts b/lib/client/ClientAPI.ts index 3324641f..b5331eaa 100644 --- a/lib/client/ClientAPI.ts +++ b/lib/client/ClientAPI.ts @@ -305,14 +305,10 @@ export default class ClientAPI { return await this.request("/matchReports", { matchId: matchId }); } - async updateCheckIn(reportId: string | undefined) { - return await this.request("/updateCheckIn", { reportId }); + async checkInForReport(reportId: string | undefined) { + return await this.request("/checkInForReport", { reportId }); } - - async updateCheckOut(reportId: string | undefined) { - return await this.request("/updateCheckOut", { reportId }); - } - + async remindSlack( slackId: string | undefined, senderSlackId: string | undefined diff --git a/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/[reportId]/index.tsx b/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/[reportId]/index.tsx index 6960699a..6a77f23b 100644 --- a/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/[reportId]/index.tsx +++ b/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/[reportId]/index.tsx @@ -4,6 +4,9 @@ import Form from "@/components/forms/Form"; import { GetServerSideProps } from "next"; import UrlResolver, { ResolvedUrlData } from "@/lib/UrlResolver"; import { useEffect } from "react"; +import ClientAPI from "@/lib/client/ClientAPI"; + +const api = new ClientAPI("gearboxiscool"); export default function Homepage(props: ResolvedUrlData) { const team = props?.team; @@ -14,6 +17,11 @@ export default function Homepage(props: ResolvedUrlData) { const { session, status } = useCurrentSession(); const hide = status === "authenticated"; + useEffect(() => { + if (report) + setInterval(() => api.checkInForReport(report._id), 5000); + }, []); + return ( {report ? ( diff --git a/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/index.tsx b/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/index.tsx index 09147f56..6f597913 100644 --- a/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/index.tsx +++ b/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/index.tsx @@ -124,8 +124,10 @@ export default function Home(props: ResolvedUrlData) { setMatchesAssigned(matchesAssigned); } - const loadMatches = async () => { - setLoadingMatches(true); + const loadMatches = async (silent: boolean = false) => { + if (!silent) + setLoadingMatches(true); + window.location.hash = ""; const matches: Match[] = await api.allCompetitionMatches(comp?._id); matches.sort((a, b) => { @@ -149,12 +151,15 @@ export default function Home(props: ResolvedUrlData) { ); setMatches(matches); - setLoadingMatches(false); + + if (!silent) + setLoadingMatches(false); }; - const loadReports = async () => { + const loadReports = async (silent: boolean = false) => { const scoutingStats = (reps: Report[]) => { - setLoadingScoutStats(true); + if (!silent) + setLoadingScoutStats(true); let submittedCount = 0; reps.forEach((report) => { if (report.submitted) { @@ -163,10 +168,12 @@ export default function Home(props: ResolvedUrlData) { }); setSubmittedReports(submittedCount); - setLoadingScoutStats(false); + if (!silent) + setLoadingScoutStats(false); }; - setLoadingReports(true); + if (!silent) + setLoadingReports(true); const newReports: Report[] = await api.competitionReports( comp?._id, false @@ -180,12 +187,17 @@ export default function Home(props: ResolvedUrlData) { newReportId[report._id] = report; }); setReportsById(newReportId); - setLoadingReports(false); + if (!silent) + setLoadingReports(false); scoutingStats(newReports); updateMatchesAssigned(); }; + useEffect(() => { + setInterval(() => loadReports(true), 5000); + }, []); + useEffect(() => { const loadUsers = async () => { setLoadingUsers(true); @@ -824,6 +836,9 @@ export default function Home(props: ResolvedUrlData) { color = ours ? !report.submitted ? "bg-purple-500" : "bg-purple-300" : color; if (!report) return <>; + + const timeSinceCheckIn = report.checkInTimestamp && (new Date().getTime() - new Date(report.checkInTimestamp as any).getTime()) / 1000; + return (

{report.robotNumber}

From cade327a214f00f386dc29719f7a2933a55e8df1 Mon Sep 17 00:00:00 2001 From: renatodellosso Date: Sat, 25 May 2024 12:40:31 -0400 Subject: [PATCH 2/2] Fixed build issue --- lib/CompetitionHandeling.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/CompetitionHandeling.ts b/lib/CompetitionHandeling.ts index 846bf09a..e28cfe42 100644 --- a/lib/CompetitionHandeling.ts +++ b/lib/CompetitionHandeling.ts @@ -76,8 +76,7 @@ export async function generateReportsForMatch(match: string | Match, scouters?: teamNumber, color, String(match._id), - 0, - false, + 0 ); reports.push(