Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/daisyui-4.12.23
Browse files Browse the repository at this point in the history
  • Loading branch information
renatodellosso authored Dec 31, 2024
2 parents 6359a20 + 5cfa086 commit 242231b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 18 deletions.
32 changes: 32 additions & 0 deletions components/XpProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { User } from "@/lib/Types";
import { xpRequiredForNextLevel } from "@/lib/Xp";
import { useState } from "react";

export default function XpProgressBar({
user,
size,
}: {
user: User;
size: string;
}) {
const [hovered, setHovered] = useState(false);

return (
<div
className={`radial-progress text-accent m-2 text-${hovered ? "xs" : "sm"}`}
style={
{
"--value": (user.xp / xpRequiredForNextLevel(user.level)) * 100,
"--size": size,
} as any
}
role="progressbar"
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
>
{hovered
? `${user.xp}/${xpRequiredForNextLevel(user.level)}`
: `Lvl ${user.level}`}
</div>
);
}
8 changes: 4 additions & 4 deletions components/competition/MatchScheduleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ export default function MatchScheduleCard(props: {
1000;

return (
<Link
<a
href={`/${team?.slug}/${seasonSlug}/${comp?.slug}/${reportId}`}
key={reportId}
className={`${color} ${mine && !submitted ? "border-4" : "border-2"}
${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>
</a>
);
})}
</div>
Expand Down Expand Up @@ -287,7 +287,7 @@ export default function MatchScheduleCard(props: {
<div>No subjective scouter assigned</div>
)}
</div>
<Link
<a
className={`btn btn-primary btn-sm ${match.subjectiveScouter && usersById[match.subjectiveScouter]?.slackId && "-translate-y-1"}`}
href={`/${team?.slug}/${seasonSlug}/${comp?.slug}/${match._id}/subjective`}
>
Expand All @@ -301,7 +301,7 @@ export default function MatchScheduleCard(props: {
: 0
} in progress`}
)
</Link>
</a>
</div>
))}
</div>
Expand Down
56 changes: 42 additions & 14 deletions components/forms/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AllianceColor, Report, QuantData, FieldPos } from "@/lib/Types";
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import FormPage from "./FormPages";
import { useCurrentSession } from "@/lib/client/useCurrentSession";
import { FaArrowLeft, FaArrowRight } from "react-icons/fa";
Expand All @@ -14,6 +14,8 @@ import Slider from "./Sliders";
import { BlockElement, FormLayout, FormElement } from "@/lib/Layout";
import Loading from "../Loading";
import { Analytics } from "@/lib/client/Analytics";
import useDynamicState from "@/lib/client/useDynamicState";
import toast from "react-hot-toast";

const api = new ClientApi();

Expand All @@ -32,7 +34,9 @@ export default function Form(props: FormProps) {
const [page, setPage] = useState(0);
const [formData, setFormData] = useState<QuantData>(props.report?.data);
const [syncing, setSyncing] = useState(false);
const [changeNumber, setChangeNumber, getChangeNumber] = useDynamicState(0);
const [submitting, setSubmitting] = useState(false);
const [submitErrorMsg, setSubmitErrorMsg] = useState<string>();

const alliance = props.report?.color;

Expand All @@ -45,15 +49,18 @@ export default function Form(props: FormProps) {
.submitForm(props.report?._id!, formData)
.then(() => {
console.log("Submitted form successfully!");

location.href = location.href.substring(
0,
location.href.lastIndexOf("/"),
);
})
.finally(() => {
if (location.href.includes("offline"))
location.href = `/offline/${props.compId}`;
else
location.href = location.href.substring(
0,
location.href.lastIndexOf("/"),
);
.catch((err) => {
console.error("Failed to submit form. Error:", err);
toast.error("Failed to submit form. Please try again. Error:", err);
setSubmitErrorMsg(err.toString());

setSubmitting(false);
});

Analytics.quantReportSubmitted(
Expand All @@ -64,11 +71,27 @@ export default function Form(props: FormProps) {
);
}

// Don't sync more than once every 500ms
const sync = useCallback(async () => {
setSyncing(true);
await api.updateReport({ data: formData }, props.report?._id!);
setSyncing(false);
}, [formData, props.report?._id]);
const newChangeNumber = changeNumber! + 1;
setChangeNumber(newChangeNumber);

setTimeout(async () => {
getChangeNumber(async (currentNumber) => {
if (currentNumber !== newChangeNumber) return;

setSyncing(true);
await api.updateReport({ data: formData }, props.report?._id!);
setSyncing(false);
});
}, 500);
}, [
formData,
props.report?._id,
changeNumber,
getChangeNumber,
setChangeNumber,
]);

const setCallback = useCallback(
(key: any, value: boolean | string | number | object) => {
Expand All @@ -82,7 +105,7 @@ export default function Form(props: FormProps) {
[sync],
);

useCallback(() => {
useEffect(() => {
// Set all Nan values to 0
for (const key in formData) {
if (typeof formData[key] === "number" && isNaN(formData[key])) {
Expand Down Expand Up @@ -266,6 +289,11 @@ export default function Form(props: FormProps) {
"Submit"
)}
</button>
{submitErrorMsg ? (
<p className="text-red-500 text-lg">{submitErrorMsg}</p>
) : (
<></>
)}
</FormPage>,
);

Expand Down
7 changes: 7 additions & 0 deletions pages/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import TeamCard from "@/components/TeamCard";
import { UpdateModal } from "@/components/UpdateModal";
import { Analytics } from "@/lib/client/Analytics";
import { signOut } from "next-auth/react";
import XpProgressBar from "@/components/XpProgressBar";

const api = new ClientApi();

Expand Down Expand Up @@ -120,6 +121,12 @@ export default function Profile(props: { teamList: Team[] }) {
<></>
)}
</Flex>
{user != null && (
<XpProgressBar
user={user}
size="4rem"
/>
)}
</div>
</Flex>
</Card>
Expand Down

0 comments on commit 242231b

Please sign in to comment.