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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 1x 5x 12x 12x 12x 12x 12x 7x 24x 7x 13x 1x | import { Typography, useMediaQuery, useTheme } from "@mui/material"; import classNames from "classnames"; import Alert from "components/Alert"; import Button from "components/Button"; import CenteredSpinner from "components/CenteredSpinner/CenteredSpinner"; import HorizontalScroller from "components/HorizontalScroller"; import TextBody from "components/TextBody"; import { useCommunityPageStyles } from "features/communities/CommunityPage"; import EventCard from "features/communities/events/EventCard"; import { myEventsKey } from "features/queryKeys"; import { RpcError } from "grpc-web"; import { useTranslation } from "i18n"; import { COMMUNITIES, DASHBOARD } from "i18n/namespaces"; import { ListMyEventsRes } from "proto/events_pb"; import { useInfiniteQuery } from "react-query"; import { service } from "service"; import hasAtLeastOnePage from "utils/hasAtLeastOnePage"; import makeStyles from "utils/makeStyles"; const useStyles = makeStyles((theme) => ({ root: { display: "grid", rowGap: theme.spacing(2), margin: theme.spacing(2, 0, 3), }, upcomingEventContainer: { paddingLeft: theme.spacing(1), paddingRight: theme.spacing(1), [theme.breakpoints.up("sm")]: { display: "grid", gap: theme.spacing(3), gridTemplateColumns: "repeat(2, 1fr)", }, }, eventCard: { width: "90%", [theme.breakpoints.down("md")]: { width: "100%", }, }, allUpcomingEventsLink: { justifySelf: "center", }, buttonContainer: { display: "flex", justifyContent: "center", width: "100%", }, })); const PAGE_SIZE = 2; export default function MyEvents() { const { t } = useTranslation([COMMUNITIES, DASHBOARD]); const classes = { ...useCommunityPageStyles(), ...useStyles() }; const theme = useTheme(); const isBelowSm = useMediaQuery(theme.breakpoints.down("sm")); const { data, error, fetchNextPage, hasNextPage, isFetching, isLoading } = useInfiniteQuery<ListMyEventsRes.AsObject, RpcError>({ queryKey: myEventsKey("upcoming"), queryFn: ({ pageParam }) => service.events.listMyEvents({ pageToken: pageParam, pageSize: PAGE_SIZE, }), getNextPageParam: (lastPage) => lastPage.nextPageToken || undefined, }); return ( <div className={classes.root}> <Typography variant="h2">{t("dashboard:upcoming_events")}</Typography> {error && <Alert severity="error">{error.message}</Alert>} {isLoading ? ( <CenteredSpinner /> ) : hasAtLeastOnePage(data, "eventsList") ? ( <> <HorizontalScroller className={classNames( classes.cardContainer, classes.upcomingEventContainer )} fetchNext={isBelowSm ? fetchNextPage : undefined} hasMore={hasNextPage} isFetching={isFetching} > {data.pages .flatMap((page) => page.eventsList) .map((event) => { return ( <EventCard key={event.eventId} event={event} className={classNames( classes.placeEventCard, classes.eventCard )} /> ); })} </HorizontalScroller> {hasNextPage && !isBelowSm && ( <div className={classes.buttonContainer}> <Button onClick={() => fetchNextPage()} variant="outlined" sx={{ color: theme.palette.common.black, borderColor: theme.palette.grey[300], "&:hover": { borderColor: theme.palette.grey[300], backgroundColor: "#3135390A", }, }} > {t("communities:see_more_events_label")} </Button> </div> )} </> ) : ( !error && <TextBody>{t("communities:events_empty_state")}</TextBody> )} </div> ); } |