Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
29 changes: 20 additions & 9 deletions js/src/app/dashboard/Dashboard.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,26 @@ export default function DashboardPage() {
: <RefreshSubmissions schoolRegistered={schoolRegistered} />}
</Center>
<Flex direction={smallPhone ? "row" : "column"} gap={"md"}>
<Flex direction={"column"} flex={1}>
<ProblemOfTheDay />
</Flex>
<Flex direction={"column"} flex={1}>
<DashboardLeaderboard
userId={data.user.id}
userTags={data.user.tags}
/>
</Flex>
{(() => {
const leaderboardCard = (
<Flex direction={"column"} flex={1}>
<DashboardLeaderboard
userId={data.user.id}
userTags={data.user.tags}
/>
</Flex>
);
const problemOfTheDayCard = (
<Flex direction={"column"} flex={1}>
<ProblemOfTheDay />
</Flex>
);
const orderedComponents =
smallPhone ?
[problemOfTheDayCard, leaderboardCard]
: [leaderboardCard, problemOfTheDayCard];
return <>{orderedComponents}</>;
})()}
Comment thread
isabellalam12 marked this conversation as resolved.
Comment on lines +66 to +85
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The use of an immediately invoked function expression (IIFE) to conditionally order two components adds unnecessary complexity. For this scenario, a direct ternary operator within the JSX provides a clearer and more concise way to achieve the desired conditional rendering. This improves readability and aligns with the principle of keeping JSX declarative. [general, importance: 7]

Suggested change
{(() => {
const leaderboardCard = (
<Flex direction={"column"} flex={1}>
<DashboardLeaderboard
userId={data.user.id}
userTags={data.user.tags}
/>
</Flex>
);
const problemOfTheDayCard = (
<Flex direction={"column"} flex={1}>
<ProblemOfTheDay />
</Flex>
);
const orderedComponents =
smallPhone ?
[problemOfTheDayCard, leaderboardCard]
: [leaderboardCard, problemOfTheDayCard];
return <>{orderedComponents}</>;
})()}
{smallPhone ? (
<>
<Flex direction={"column"} flex={1}>
<ProblemOfTheDay />
</Flex>
<Flex direction={"column"} flex={1}>
<DashboardLeaderboard
userId={data.user.id}
userTags={data.user.tags}
/>
</Flex>
</>
) : (
<>
<Flex direction={"column"} flex={1}>
<DashboardLeaderboard
userId={data.user.id}
userTags={data.user.tags}
/>
</Flex>
<Flex direction={"column"} flex={1}>
<ProblemOfTheDay />
</Flex>
</>
)}

Comment on lines +66 to +85
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The use of an Immediately Invoked Function Expression (IIFE) for conditional rendering can reduce readability. Consider defining the component variables directly within the Flex component's scope and then using a more direct conditional rendering approach. This simplifies the render logic and aligns with common React patterns. [general, importance: 6]

Suggested change
{(() => {
const leaderboardCard = (
<Flex direction={"column"} flex={1}>
<DashboardLeaderboard
userId={data.user.id}
userTags={data.user.tags}
/>
</Flex>
);
const problemOfTheDayCard = (
<Flex direction={"column"} flex={1}>
<ProblemOfTheDay />
</Flex>
);
const orderedComponents =
smallPhone ?
[problemOfTheDayCard, leaderboardCard]
: [leaderboardCard, problemOfTheDayCard];
return <>{orderedComponents}</>;
})()}
const leaderboardCard = (
<Flex direction={"column"} flex={1}>
<DashboardLeaderboard
userId={data.user.id}
userTags={data.user.tags}
/>
</Flex>
);
const problemOfTheDayCard = (
<Flex direction={"column"} flex={1}>
<ProblemOfTheDay />
</Flex>
);
{smallPhone ? (
<>
{problemOfTheDayCard}
{leaderboardCard}
</>
) : (
<>
{leaderboardCard}
{problemOfTheDayCard}
</>
)}

<Flex direction={"column"} flex={1}>
<RecentSubmissions userId={data.user.id} />
</Flex>
Comment thread
isabellalam12 marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function ProblemOfTheDay() {
const json = data.payload;

return (
<CodebloomCard miw={"31vw"} mih={"63vh"}>
<CodebloomCard miw="31vw" mih={{ base: "auto", md: "63vh" }}>
<Center>
<Title style={{ textAlign: "center" }} order={3}>
Problem of the day
Expand Down
Loading