Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | import {
Divider,
DividerProps,
styled,
Typography,
useMediaQuery,
useTheme,
} from "@mui/material";
import CenteredSpinner from "components/CenteredSpinner/CenteredSpinner";
import HtmlMeta from "components/HtmlMeta";
import PageTitle from "components/PageTitle";
import Badge from "features/badges/Badge";
import { useBadges } from "features/badges/hooks";
import { useTranslation } from "i18n";
import { GLOBAL, PROFILE } from "i18n/namespaces";
import BadgeUserList from "./BadgeUserList";
const BadgeListItem = styled("div")(({ theme }) => ({
[theme.breakpoints.down("md")]: {
display: "inline-block",
},
}));
const StyledDivider = styled(Divider)<DividerProps>(({ theme }) => ({
margin: theme.spacing(2),
}));
const FlexDiv = styled("div")(({ theme }) => ({
display: "flex",
gap: theme.spacing(2),
alignItems: "start",
}));
const ParentFlexDiv = styled(FlexDiv)(({ theme }) => ({
[theme.breakpoints.down("md")]: {
flexDirection: "column",
gap: theme.spacing(0),
},
}));
const ContentDiv = styled("div")(({ theme }) => ({
padding: theme.spacing(2),
alignSelf: "stretch",
width: "100%",
}));
const CenteredDiv = styled(ContentDiv)(({ theme }) => ({
display: "flex",
alignItems: "center",
justifyContent: "center",
}));
export interface BadgesPageProps {
badgeId?: string;
}
export default function BadgesPage({ badgeId = undefined }: BadgesPageProps) {
const { t } = useTranslation([GLOBAL, PROFILE]);
const { badges, isLoading: isBadgesLoading } = useBadges();
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("md"));
return (
<>
<HtmlMeta title={t("global:nav.badges")} />
<PageTitle>{t("profile:badges.title")}</PageTitle>
<Typography variant="subtitle1">
{t("profile:badges.subtitle")}
</Typography>
<StyledDivider />
<ParentFlexDiv>
<div>
{badges &&
Object.values(badges).map((badge) => (
<BadgeListItem key={badge.id}>
<Badge badge={badge} />
</BadgeListItem>
))}
</div>
<StyledDivider
orientation={isMobile ? "horizontal" : "vertical"}
flexItem
/>
{badgeId ? (
<ContentDiv>
{isBadgesLoading ? (
<CenteredSpinner />
) : badges && badgeId in badges ? (
<>
<FlexDiv>
<Badge badge={badges[badgeId]} />
<Typography variant="body1">
{badges[badgeId].description}
</Typography>
</FlexDiv>
<BadgeUserList badgeId={badgeId} />
</>
) : (
<>{t("profile:badges.not_found")}</>
)}
</ContentDiv>
) : (
<CenteredDiv>
<Typography variant="subtitle1">
{t("profile:badges.click_on_left")}
</Typography>
</CenteredDiv>
)}
</ParentFlexDiv>
</>
);
}
|