Skip to content
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

Check In #176

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +20,7 @@ export default function Avatar(props: {
const admin = user?.admin;

return (
<div className={"avatar " + (props.scale ?? "") + " " + props.className}>
<div className={`avatar ${props.online && "online"} ${props.scale} ${props.className}`}>
{ (props.showLevel ?? true) &&
<div className="absolute z-10 bg-base-100 rounded-tl-xl rounded-br-xl h-6 w-14 text-center text-sm font-semibold">
LVL: {user?.level}
Expand Down
13 changes: 2 additions & 11 deletions lib/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ export namespace API {

form.data = data.formData;
form.submitted = true;
form.checkedIn = false;
form.submitter = data.userId;

await db.updateObjectById(
Expand Down Expand Up @@ -632,19 +631,11 @@ export namespace API {
);
},

updateCheckIn: async (req, res, { db, data }) => {
checkInForReport: async (req, res, { db, data }) => {
await db.updateObjectById<Report>(
Collections.Reports,
new ObjectId(data.reportId),
{ checkedIn: true }
);
},

updateCheckOut: async (req, res, { db, data }) => {
await db.updateObjectById<Report>(
Collections.Reports,
new ObjectId(data.reportId),
{ checkedIn: false }
{ checkInTimestamp: new Date().toISOString() }
);
},

Expand Down
3 changes: 1 addition & 2 deletions lib/CompetitionHandeling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ export async function generateReportsForMatch(match: string | Match, scouters?:
teamNumber,
color,
String(match._id),
0,
false,
0
);

reports.push(
Expand Down
7 changes: 4 additions & 3 deletions lib/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "next-auth";
import { TheBlueAlliance } from "./TheBlueAlliance";
import { Statbotics } from "./Statbotics";
import { DatasetJsonLdProps } from "next-seo";

/**
* Standard Account Type
Expand Down Expand Up @@ -322,7 +323,7 @@ export class Report {
submitted: boolean = false;
data: FormData;

checkedIn: boolean = false;
checkInTimestamp: string | undefined;

constructor(
user: string | undefined,
Expand All @@ -331,15 +332,15 @@ export class Report {
color: AllianceColor,
match: string,
timestamp: number = 0,
checkedIn: boolean
checkInTimestamp: string | undefined = undefined
) {
this.timestamp = timestamp;
this.user = user;
this.data = data;
this.robotNumber = robotNumber;
this.match = match;
this.color = color;
this.checkedIn = checkedIn;
this.checkInTimestamp = checkInTimestamp;
}
}

Expand Down
10 changes: 3 additions & 7 deletions lib/client/ClientAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 (
<Container requireAuthentication={false} hideMenu={!hide}>
{report ? (
Expand Down
33 changes: 24 additions & 9 deletions pages/[teamSlug]/[seasonSlug]/[competitonSlug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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 (
<Link
href={`/${team?.slug}/${season?.slug}/${comp?.slug}/${reportId}`}
Expand All @@ -832,7 +847,7 @@ export default function Home(props: ResolvedUrlData) {
mine && !submitted
? "border-4"
: "border-2"
} rounded-lg w-12 h-12 flex items-center justify-center text-white border-white`}
} ${timeSinceCheckIn && timeSinceCheckIn < 10 && "avatar online"} rounded-lg w-12 h-12 flex items-center justify-center text-white border-white`}
>
<h1>{report.robotNumber}</h1>
</Link>
Expand Down
Loading