Skip to content

Commit

Permalink
Cleanup extraneous api requests, improve grid sizing on phones
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAman62 committed Aug 31, 2024
1 parent 3ba1ec4 commit ad496e1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
10 changes: 10 additions & 0 deletions server/GridBattle.Api/Api/LeaderboardApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ ClaimsPrincipal user
if (userId is null || username is null)
return Results.Forbid();

// check for an existing entry, and return it
var existing = await dbContext
.LeaderboardEntries.Where(x => x.GridId == gridId && x.UserId == userId)
.FirstOrDefaultAsync();

if (existing is not null)
{
return TypedResults.Ok(existing);
}

var newEntry = new LeaderboardEntry
{
GridId = gridId,
Expand Down
8 changes: 4 additions & 4 deletions ui/src/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function LoginModal({
<FloatingLabel
id="username"
name="username"
className="bg-slate-900"
className="dark:bg-slate-900"
variant="outlined"
label="Username"
autoComplete="username"
Expand All @@ -254,7 +254,7 @@ function LoginModal({
<FloatingLabel
id="email"
name="email"
className="bg-slate-900"
className="dark:bg-slate-900"
variant="outlined"
label="Email"
type="email"
Expand All @@ -268,7 +268,7 @@ function LoginModal({
<FloatingLabel
id="password"
name="password"
className="bg-slate-900"
className="dark:bg-slate-900"
variant="outlined"
label="Password"
type="password"
Expand All @@ -290,7 +290,7 @@ function LoginModal({
<FloatingLabel
id="verification-code"
name="verification-code"
className="bg-slate-900"
className="dark:bg-slate-900"
variant="outlined"
label="Verification Code"
autoCorrect="false"
Expand Down
2 changes: 1 addition & 1 deletion ui/src/grid/InteractiveGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
};

function Row({ children }: React.PropsWithChildren) {
return <div className="flex flex-row aspect-[6/1] gap-1 md:gap-2">{children}</div>;
return <div className="flex flex-row aspect-[5/1] md:aspect-[6/1] gap-1 md:gap-2">{children}</div>;
}

export default function InteractiveGrid({ grid, onCorrect, onIncorrect }: Props) {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/grid/SimpleGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export default function SimpleGrid({ grid, matchedCount, title }: { grid: Grid;
{title && <h1 className="self-center font-semibold text-sm text-black dark:text-gray-200">{title}</h1>}
{_.range(0, matchedCount).map((i) => {
return (
<div key={i} className="flex flex-row aspect-[6/1] bg-green-700 rounded">
<div key={i} className="flex flex-row aspect-[5/1] md:aspect-[6/1] bg-green-700 rounded">

</div>
);
})}
{_.range(matchedCount, rowCount).map((i) => {
return (
<div key={i} className="flex flex-row gap-1 aspect-[6/1]">
<div key={i} className="flex flex-row gap-1 aspect-[5/1] md:aspect-[6/1]">
{_.range(columnCount).map((j) => (
<div key={j} className="bg-gray-200 grow rounded"></div>
))}
Expand Down
16 changes: 8 additions & 8 deletions ui/src/leaderboard/LeaderboardEntriesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ export default function LeaderboardEntriesTable({ gridId, leaderboardId }: { gri
return (
<Table>
<Table.Head>
<Table.HeadCell>Pos</Table.HeadCell>
<Table.HeadCell>Username</Table.HeadCell>
<Table.HeadCell>Entry Date</Table.HeadCell>
<Table.HeadCell>Time</Table.HeadCell>
<Table.HeadCell className="p-1"></Table.HeadCell>
<Table.HeadCell className="p-2">Username</Table.HeadCell>
<Table.HeadCell className="p-2">Entry Date</Table.HeadCell>
<Table.HeadCell className="p-2">Time</Table.HeadCell>
</Table.Head>
<Table.Body>
{entries.map((entry, i) => (
<Table.Row key={entry.userId}>
<Table.Cell>{i + offset + 1}</Table.Cell>
<Table.Cell>
<Table.Cell className="p-1">{i + offset + 1}</Table.Cell>
<Table.Cell className="p-2">
<span className="inline-flex gap-2">
{entry.username}
{user?.username === entry.username && <Badge>You</Badge>}
</span>
</Table.Cell>
<Table.Cell>
<Table.Cell className="p-2">
{new Date(Date.parse(entry.createdDateTime)).toLocaleString(undefined, { dateStyle: "short", timeStyle: "short" })}
</Table.Cell>
<Table.Cell>
<Table.Cell className="p-2">
<TimeDisplay totalTime={entry.totalTime} penalties={entry.penalties} />
</Table.Cell>
</Table.Row>
Expand Down
4 changes: 2 additions & 2 deletions ui/src/useApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UserContext } from "./UserContext";
import { ErrorContext } from "./ErrorContext";

export default function useApiClient() {
const { user, refreshToken } = useContext(UserContext);
const { isLoggedIn, user, refreshToken } = useContext(UserContext);
const { addError } = useContext(ErrorContext);

const execute = async (url: string, options?: RequestInit) => {
Expand Down Expand Up @@ -71,5 +71,5 @@ export default function useApiClient() {
getLeaderboardEntriesForGrid,
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [user?.idToken]);
}, [isLoggedIn]);
}

0 comments on commit ad496e1

Please sign in to comment.