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 | 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x | import { Link as MuiLink } from "@mui/material"; import Alert from "components/Alert"; import Button from "components/Button"; import CenteredSpinner from "components/CenteredSpinner/CenteredSpinner"; import { EmailIcon } from "components/Icons"; import TextBody from "components/TextBody"; import { useListDiscussions } from "features/communities/hooks"; import { useTranslation } from "i18n"; import { COMMUNITIES } from "i18n/namespaces"; import Link from "next/link"; import { Community } from "proto/communities_pb"; import { composingDiscussionHash, routeToCommunity } from "routes"; import hasAtLeastOnePage from "utils/hasAtLeastOnePage"; import { SectionTitle, useCommunityPageStyles } from "../CommunityPage"; import DiscussionCard from "./DiscussionCard"; import useDiscussionsListStyles from "./useDiscussionsListStyles"; export default function DiscussionsSection({ community, }: { community: Community.AsObject; }) { const { t } = useTranslation([COMMUNITIES]); const classes = { ...useCommunityPageStyles(), ...useDiscussionsListStyles(), }; const { isLoading: isDiscussionsLoading, error: discussionsError, data: discussions, hasNextPage: discussionsHasNextPage, } = useListDiscussions(community.communityId); return ( <section> <div className={classes.discussionsHeader}> <SectionTitle icon={<EmailIcon />} variant="h2"> {t("communities:discussions_title")} </SectionTitle> </div> {discussionsError && ( <Alert severity="error">{discussionsError.message}</Alert> )} <Link href={`${routeToCommunity( community.communityId, community.slug, "discussions" )}#${composingDiscussionHash}`} passHref legacyBehavior > <Button size="small" className={classes.createResourceButton} component="a" > {t("communities:new_post_label")} </Button> </Link> <div className={classes.discussionsContainer}> {isDiscussionsLoading ? ( <CenteredSpinner /> ) : hasAtLeastOnePage(discussions, "discussionsList") ? ( discussions.pages .flatMap((res) => res.discussionsList) .map((discussion) => ( <DiscussionCard discussion={discussion} key={`discussioncard-${discussion.thread!.threadId}`} /> )) ) : ( <TextBody>{t("communities:discussions_empty_state")}</TextBody> )} {discussionsHasNextPage && ( <div className={classes.loadMoreButton}> <Link href={routeToCommunity( community.communityId, community.slug, "discussions" )} passHref legacyBehavior > <MuiLink component="a" underline="hover"> {t("communities:see_more_discussions_label")} </MuiLink> </Link> </div> )} </div> </section> ); } |