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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 94x 94x 94x 94x 2x 754x 188x 50x 40x 2x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 1x 94x 1x 1x 94x 1x 1x 94x 33x 33x 33x 8x | import { Pagination, styled, Typography, useMediaQuery } from "@mui/material"; import Alert from "components/Alert"; import CenteredSpinner from "components/CenteredSpinner/CenteredSpinner"; import LocationAutocomplete from "components/LocationAutocomplete"; import TextBody from "components/TextBody"; import { useTranslation } from "i18n"; import { COMMUNITIES, GLOBAL } from "i18n/namespaces"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { theme } from "theme"; import { GeocodeResult } from "utils/hooks"; import EventsList from "./EventsList"; import { useEventSearch } from "./hooks"; const StyledLocationSearch = styled(LocationAutocomplete)(() => ({ marginRight: theme.spacing(2), paddingBottom: theme.spacing(2), })); const StyledColumn = styled("div")(() => ({ display: "flex", flexDirection: "column", })); const StyledRow = styled("div")(() => ({ display: "flex", justifyContent: "space-between", width: "100%", [theme.breakpoints.down("md")]: { flexDirection: "column", }, })); const StyledFilterTagContainer = styled("div")(() => ({ display: "flex", alignItems: "center", marginTop: theme.spacing(2), marginBottom: theme.spacing(2), })); const StyledFilterTag = styled(Typography, { shouldForwardProp: (propName) => propName !== "isSelected", })<{ isSelected: boolean }>(({ isSelected }) => ({ backgroundColor: isSelected ? theme.palette.secondary.main : theme.palette.grey[200], color: isSelected ? theme.palette.common.white : theme.palette.text.primary, padding: theme.spacing(1, 2), textAlign: "center", fontWeight: "bold", margin: theme.spacing(0.5), borderRadius: theme.shape.borderRadius * 6, "&:hover": { cursor: "pointer", }, })); const StyledLoadingBox = styled("div")(() => ({ display: "flex", justifyContent: "center", padding: theme.spacing(2), width: "100%", minHeight: theme.spacing(20), })); const StyledPagination = styled(Pagination)(() => ({ display: "flex", justifyContent: "center", marginTop: theme.spacing(2), marginBottom: theme.spacing(2), })); const DiscoverEventsList = () => { // @TODO - Basically just making the form since LocationAutocomplete required the control prop // We don't validate or require this field so it's just a dummy form // Too much refactoring needed to change existing components to not require the control prop // Might be worth making a new uncontrolled omponent that doesn't require the control prop const { control } = useForm<{ location: GeocodeResult | undefined }>({ mode: "onChange", }); const { t } = useTranslation([GLOBAL, COMMUNITIES]); const isMobile = useMediaQuery(theme.breakpoints.down("md")); const pageSize = 12; const [pageNumber, setPageNumber] = useState(1); const [isMyCommunities, setIsMyCommunities] = useState<boolean>(false); const [isOnlineOnly, setIsOnlineOnly] = useState<boolean>(false); const [locationResult, setLocationResult] = useState<GeocodeResult | "">(""); const { data, error, isLoading } = useEventSearch({ pastEvents: false, pageSize, pageNumber, isMyCommunities, isOnlineOnly, searchLocation: locationResult, }); const hasEvents = data && data.eventsList && data.eventsList.length > 0; const numPages = Math.ceil((data?.totalItems ?? 0) / pageSize) ?? 1; const handlePageNumberChange = ( event: React.ChangeEvent<unknown>, value: number, ) => { setPageNumber(value); }; const handleFilterIsMyCommunitiesClick = () => { setIsMyCommunities(!isMyCommunities); setPageNumber(1); }; const handleFilterIsOnlineOnlyClick = () => { setIsOnlineOnly(!isOnlineOnly); setPageNumber(1); }; const handleOnChangeAutocomplete = (newLocationResult: GeocodeResult) => { if (typeof newLocationResult === "object") { setLocationResult(newLocationResult); } else E{ setLocationResult(""); } setPageNumber(1); }; const renderLocationAutoComplete = () => ( <StyledLocationSearch control={control} name="location" defaultValue={typeof locationResult === "object" ? locationResult : ""} label={t("global:location_autocomplete.search_location_button")} onChange={handleOnChangeAutocomplete} fieldError={undefined} fullWidth={isMobile} /> ); return ( <> <StyledColumn> <Typography variant="h2"> {t("communities:discover_events_title")} </Typography> <StyledRow> <StyledFilterTagContainer> <StyledFilterTag isSelected={isMyCommunities} variant="body2" onClick={handleFilterIsMyCommunitiesClick} > {t("communities:my_communities")} </StyledFilterTag> <StyledFilterTag isSelected={isOnlineOnly} variant="body2" onClick={handleFilterIsOnlineOnlyClick} > {t("communities:online")} </StyledFilterTag> </StyledFilterTagContainer> {!isMobile && renderLocationAutoComplete()} </StyledRow> {isMobile && renderLocationAutoComplete()} </StyledColumn> {!hasEvents && !isLoading && ( <TextBody>{t("communities:events_empty_state")}</TextBody> )} {error && <Alert severity="error">{error.message}</Alert>} {isLoading && ( <StyledLoadingBox> <CenteredSpinner /> </StyledLoadingBox> )} {hasEvents && !isLoading && ( <> <EventsList events={data.eventsList} isVerticalStyle /> <StyledPagination count={numPages} page={pageNumber} color="primary" onChange={handlePageNumberChange} size="large" /> </> )} </> ); }; export default DiscoverEventsList; |