Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,29 @@
Group,
Card,
Flex,
Tooltip,
} from "@mantine/core";
import { useMediaQuery } from "@mantine/hooks";
import { IconClock } from "@tabler/icons-react";
import d from "dayjs";
import { useMemo } from "react";
import { Link } from "react-router-dom";

const clockIconStyle = {
position: "absolute" as const,
top: -8,
right: -8,
width: 22,
height: 22,
borderRadius: "50%",
backgroundColor: "var(--mantine-color-teal-7)",
border: "2px solid var(--mantine-color-dark-7)",
display: "flex",
alignItems: "center",
justifyContent: "center",
};

export default function UserSubmissions({ userId }: { userId: string }) {

Check failure on line 47 in js/src/app/user/[userId]/submissions/_components/UserSubmissions/UserSubmissions.tsx

View check run for this annotation

SonarQubeCloud / [codebloom_frontend] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=codebloom_frontend&issues=AZy6aHqhNERQer0CFk_A&open=AZy6aHqhNERQer0CFk_A&pullRequest=831
const {
data,
status,
Expand Down Expand Up @@ -73,6 +90,10 @@

const pageData = data.payload;

const dateRangeLabel =
(startDate || endDate) &&
`Viewing submissions from ${startDate ? d(startDate).format("MMM D, YYYY") : "now"} to ${endDate ? d(endDate).format("MMM D, YYYY") : "now"}`;

return (
<Box
mt={10}
Expand All @@ -84,30 +105,44 @@
>
{!isMobile && (
<Box display="block" style={{ textAlign: "right" }}>
<FilterDropdown buttonName="Filters">
<TopicFilterPopover
value={topics}
selectedTopicsSet={selectedTopicsSet}
onChange={setTopics}
onClear={clearTopics}
/>
<FilterDropdownItem
value={pointFilter}
toggle={togglePointFilter}
switchMode
name={
<Flex gap="0.5rem" align="center">
Points Received
</Flex>
}
/>
<DateRangePopover
startDate={startDate}
endDate={endDate}
onStartDateChange={setStartDate}
onEndDateChange={setEndDate}
/>
</FilterDropdown>
<Box pos="relative" display="inline-block">
<FilterDropdown buttonName="Filters">
<TopicFilterPopover
value={topics}
selectedTopicsSet={selectedTopicsSet}
onChange={setTopics}
onClear={clearTopics}
/>
<FilterDropdownItem
value={pointFilter}
toggle={togglePointFilter}
switchMode
name={
<Flex gap="0.5rem" align="center">
Points Received
</Flex>
}
/>
<DateRangePopover
startDate={startDate}
endDate={endDate}
onStartDateChange={setStartDate}
onEndDateChange={setEndDate}
/>
</FilterDropdown>
{dateRangeLabel && (
<Tooltip
label={dateRangeLabel}
withArrow
position="bottom"
withinPortal
>
<Box style={clockIconStyle} data-testid="date-range-clock-icon">
<IconClock size={13} color="white" stroke={2.5} />
</Box>
</Tooltip>
)}
</Box>
</Box>
)}
<Group
Expand All @@ -127,30 +162,37 @@
/>
</Box>
{isMobile && (
<FilterDropdown buttonName="Filters">
<TopicFilterPopover
value={topics}
selectedTopicsSet={selectedTopicsSet}
onChange={setTopics}
onClear={clearTopics}
/>
<FilterDropdownItem
value={pointFilter}
toggle={togglePointFilter}
switchMode
name={
<Flex gap="0.5rem" align="center">
Points Received
</Flex>
}
/>
<DateRangePopover
startDate={startDate}
endDate={endDate}
onStartDateChange={setStartDate}
onEndDateChange={setEndDate}
/>
</FilterDropdown>
<Box pos="relative" style={{ flexShrink: 0 }}>
<FilterDropdown buttonName="Filters">
<TopicFilterPopover
value={topics}
selectedTopicsSet={selectedTopicsSet}
onChange={setTopics}
onClear={clearTopics}
/>
<FilterDropdownItem
value={pointFilter}
toggle={togglePointFilter}
switchMode
name={
<Flex gap="0.5rem" align="center">
Points Received
</Flex>
}
/>
<DateRangePopover
startDate={startDate}
endDate={endDate}
onStartDateChange={setStartDate}
onEndDateChange={setEndDate}
/>
</FilterDropdown>
{dateRangeLabel && (
<Box style={{ ...clockIconStyle, pointerEvents: "none" }}>
<IconClock size={13} color="white" stroke={2.5} />
</Box>
)}
</Box>
)}
</Group>
<Box pos="relative">
Expand Down
Loading