Skip to content

Commit c8e995b

Browse files
Merge pull request #176 from Decatur-Robotics/check-in
Check In
2 parents 1e15e6f + 93c93d7 commit c8e995b

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

components/Avatar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default function Avatar(props: {
1111
borderThickness?: number | undefined;
1212
onClick?: () => void | undefined;
1313
className?: string | undefined;
14+
online?: boolean;
1415
}) {
1516
const { session, status } = useCurrentSession();
1617
const user = props.user ?? session?.user;
@@ -19,7 +20,7 @@ export default function Avatar(props: {
1920
const admin = user?.admin;
2021

2122
return (
22-
<div className={"avatar " + (props.scale ?? "") + " " + props.className}>
23+
<div className={`avatar ${props.online && "online"} ${props.scale} ${props.className}`}>
2324
{ (props.showLevel ?? true) &&
2425
<div className="absolute z-10 bg-base-100 rounded-tl-xl rounded-br-xl h-6 w-14 text-center text-sm font-semibold">
2526
LVL: {user?.level}

lib/API.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,6 @@ export namespace API {
560560

561561
form.data = data.formData;
562562
form.submitted = true;
563-
form.checkedIn = false;
564563
form.submitter = data.userId;
565564

566565
await db.updateObjectById(
@@ -649,19 +648,11 @@ export namespace API {
649648
);
650649
},
651650

652-
updateCheckIn: async (req, res, { db, data }) => {
651+
checkInForReport: async (req, res, { db, data }) => {
653652
await db.updateObjectById<Report>(
654653
Collections.Reports,
655654
new ObjectId(data.reportId),
656-
{ checkedIn: true }
657-
);
658-
},
659-
660-
updateCheckOut: async (req, res, { db, data }) => {
661-
await db.updateObjectById<Report>(
662-
Collections.Reports,
663-
new ObjectId(data.reportId),
664-
{ checkedIn: false }
655+
{ checkInTimestamp: new Date().toISOString() }
665656
);
666657
},
667658

lib/CompetitionHandeling.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ export async function generateReportsForMatch(match: string | Match, scouters?:
9898
teamNumber,
9999
color,
100100
String(match._id),
101-
0,
102-
false,
101+
0
103102
);
104103

105104
reports.push(

lib/Types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "next-auth";
77
import { TheBlueAlliance } from "./TheBlueAlliance";
88
import { Statbotics } from "./Statbotics";
9+
import { DatasetJsonLdProps } from "next-seo";
910
import Subjective from '../pages/[teamSlug]/[seasonSlug]/[competitonSlug]/[reportId]/subjective';
1011

1112
/**
@@ -339,7 +340,7 @@ export class Report {
339340
submitted: boolean = false;
340341
data: FormData;
341342

342-
checkedIn: boolean = false;
343+
checkInTimestamp: string | undefined;
343344

344345
constructor(
345346
user: string | undefined,
@@ -348,15 +349,15 @@ export class Report {
348349
color: AllianceColor,
349350
match: string,
350351
timestamp: number = 0,
351-
checkedIn: boolean
352+
checkInTimestamp: string | undefined = undefined
352353
) {
353354
this.timestamp = timestamp;
354355
this.user = user;
355356
this.data = data;
356357
this.robotNumber = robotNumber;
357358
this.match = match;
358359
this.color = color;
359-
this.checkedIn = checkedIn;
360+
this.checkInTimestamp = checkInTimestamp;
360361
}
361362
}
362363

lib/client/ClientAPI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ export default class ClientAPI {
309309
return await this.request("/matchReports", { matchId: matchId });
310310
}
311311

312-
async updateCheckIn(reportId: string | undefined) {
313-
return await this.request("/updateCheckIn", { reportId });
312+
async checkInForReport(reportId: string | undefined) {
313+
return await this.request("/checkInForReport", { reportId });
314314
}
315315

316316
async updateCheckOut(reportId: string | undefined) {

pages/[teamSlug]/[seasonSlug]/[competitonSlug]/[reportId]/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import Form from "@/components/forms/Form";
44
import { GetServerSideProps } from "next";
55
import UrlResolver, { ResolvedUrlData } from "@/lib/UrlResolver";
66
import { useEffect } from "react";
7+
import ClientAPI from "@/lib/client/ClientAPI";
8+
9+
const api = new ClientAPI("gearboxiscool");
710

811
export default function Homepage(props: ResolvedUrlData) {
912
const team = props?.team;
@@ -14,6 +17,11 @@ export default function Homepage(props: ResolvedUrlData) {
1417
const { session, status } = useCurrentSession();
1518
const hide = status === "authenticated";
1619

20+
useEffect(() => {
21+
if (report)
22+
setInterval(() => api.checkInForReport(report._id), 5000);
23+
}, []);
24+
1725
return (
1826
<Container requireAuthentication={false} hideMenu={!hide}>
1927
{report ? (

pages/[teamSlug]/[seasonSlug]/[competitonSlug]/index.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export default function Home(props: ResolvedUrlData) {
136136
const loadMatches = async (silent: boolean = false) => {
137137
if (!silent)
138138
setLoadingMatches(true);
139+
139140
window.location.hash = "";
140141
const matches: Match[] = await api.allCompetitionMatches(comp?._id);
141142
matches.sort((a, b) => {
@@ -156,13 +157,15 @@ export default function Home(props: ResolvedUrlData) {
156157
);
157158

158159
setMatches(matches);
160+
159161
if (!silent)
160162
setLoadingMatches(false);
161163
};
162164

163-
const loadReports = async () => {
165+
const loadReports = async (silent: boolean = false) => {
164166
const scoutingStats = (reps: Report[]) => {
165-
setLoadingScoutStats(true);
167+
if (!silent)
168+
setLoadingScoutStats(true);
166169
let submittedCount = 0;
167170
reps.forEach((report) => {
168171
if (report.submitted) {
@@ -171,10 +174,12 @@ export default function Home(props: ResolvedUrlData) {
171174
});
172175

173176
setSubmittedReports(submittedCount);
174-
setLoadingScoutStats(false);
177+
if (!silent)
178+
setLoadingScoutStats(false);
175179
};
176180

177-
setLoadingReports(true);
181+
if (!silent)
182+
setLoadingReports(true);
178183
const newReports: Report[] = await api.competitionReports(
179184
comp?._id,
180185
false
@@ -188,10 +193,15 @@ export default function Home(props: ResolvedUrlData) {
188193
newReportId[report._id] = report;
189194
});
190195
setReportsById(newReportId);
191-
setLoadingReports(false);
196+
if (!silent)
197+
setLoadingReports(false);
192198
scoutingStats(newReports);
193199
};
194200

201+
useEffect(() => {
202+
setInterval(() => loadReports(true), 5000);
203+
}, []);
204+
195205
useEffect(() => {
196206
const loadUsers = async () => {
197207
setLoadingUsers(true);
@@ -887,6 +897,11 @@ export default function Home(props: ResolvedUrlData) {
887897
: "bg-blue-500"
888898
: "bg-slate-500";
889899
color = ours ? !report.submitted ? "bg-purple-500" : "bg-purple-300" : color;
900+
901+
if (!report) return <></>;
902+
903+
const timeSinceCheckIn = report.checkInTimestamp && (new Date().getTime() - new Date(report.checkInTimestamp as any).getTime()) / 1000;
904+
890905
return (
891906
<Link
892907
href={`/${team?.slug}/${season?.slug}/${comp?.slug}/${reportId}`}
@@ -895,7 +910,7 @@ export default function Home(props: ResolvedUrlData) {
895910
mine && !submitted
896911
? "border-4"
897912
: "border-2"
898-
} rounded-lg w-12 h-12 flex items-center justify-center text-white border-white`}
913+
} ${timeSinceCheckIn && timeSinceCheckIn < 10 && "avatar online"} rounded-lg w-12 h-12 flex items-center justify-center text-white border-white`}
899914
>
900915
<h1>{report.robotNumber}</h1>
901916
</Link>

0 commit comments

Comments
 (0)