diff --git a/src/components/client/campaigns/CampaignFilter.tsx b/src/components/client/campaigns/CampaignFilter.tsx index 7473306a6..820977212 100644 --- a/src/components/client/campaigns/CampaignFilter.tsx +++ b/src/components/client/campaigns/CampaignFilter.tsx @@ -1,6 +1,6 @@ import React, { useMemo, useState } from 'react' import { styled } from '@mui/material/styles' -import { Box, CircularProgress, IconButton, ImageList, Typography } from '@mui/material' +import { Box, CircularProgress, Grid, IconButton, Typography } from '@mui/material' import { useCampaignList } from 'common/hooks/campaigns' import CampaignsList from './CampaignsList' import { CampaignResponse } from 'gql/campaigns' @@ -20,42 +20,45 @@ import { TheaterComedy, VolunteerActivism, } from '@mui/icons-material' -import useMobile from 'common/hooks/useMobile' import theme from 'common/theme' const PREFIX = 'CampaignFilter' const classes = { filterButtons: `${PREFIX}-filterButtons`, + filterButtonContainer: `${PREFIX}-filterButtonsCtn`, } const Root = styled('div')(() => ({ + [`& .${classes.filterButtonContainer}`]: { + display: 'flex', + justifyContent: 'center', + }, [`& .${classes.filterButtons}`]: { - display: 'block', + width: '100%', height: '80px', borderRadius: 0, borderBottom: '1px solid transparent', - padding: 1, + display: 'flex', + flexDirection: 'column', - '&:active': { + '&:selected': { color: theme.palette.primary.light, borderBottom: `5px solid ${theme.palette.primary.light}`, }, - - '&:hover': { - backgroundColor: theme.palette.common.white, - borderBottom: `5px solid ${theme.palette.primary.light}`, + '&:active': { color: theme.palette.primary.light, + borderBottom: `5px solid ${theme.palette.primary.light}`, }, - '&:focus': { color: theme.palette.primary.light, borderBottom: `5px solid ${theme.palette.primary.light}`, + background: 'transperent', }, - - '&:selected': { + '&:hover': { color: theme.palette.primary.light, borderBottom: `5px solid ${theme.palette.primary.light}`, + backgroundColor: 'white', }, }, })) @@ -78,51 +81,61 @@ const categories: { export default function CampaignFilter() { const { t } = useTranslation() - const { mobile } = useMobile() const { data: campaigns, isLoading } = useCampaignList(true) const [selectedCategory, setSelectedCategory] = useState('ALL') // TODO: add filters&sorting of campaigns so people can select based on personal preferences const campaignToShow = useMemo(() => { - const filteredCampaigns = - campaigns?.filter((campaign) => { - if (selectedCategory != 'ALL') { - return campaign.campaignType.category === selectedCategory - } - return campaign - }) ?? [] - return filteredCampaigns + if (selectedCategory === 'ALL') { + return campaigns ?? [] + } + return ( + campaigns?.filter((campaign) => campaign.campaignType.category === selectedCategory) ?? [] + ) }, [campaigns, selectedCategory]) return ( - - - {Object.values(CampaignTypeCategory).map((category) => { - const count = - campaigns?.filter((campaign) => campaign.campaignType.category === category).length ?? 0 - return ( - setSelectedCategory(category)}> - {categories[category].icon ?? } - - {t(`campaigns:filters.${category}`)} ({count}) - - - ) - })} - setSelectedCategory('ALL')}> - - - {t(`campaigns:filters.all`)} ({campaigns?.length ?? 0}) - - - + <> + + + + {Object.values(CampaignTypeCategory).map((category) => { + const count = campaigns?.reduce((acc, curr) => { + return category === curr.campaignType.category ? acc + 1 : acc + }, 0) + return ( + + setSelectedCategory(category)}> + {categories[category].icon ?? } + + {t(`campaigns:filters.${category}`)} ({count}) + + + + ) + })} + + setSelectedCategory('ALL')}> + + + {t(`campaigns:filters.all`)} ({campaigns?.length ?? 0}) + + + + + + {isLoading ? ( @@ -130,6 +143,6 @@ export default function CampaignFilter() { ) : ( )} - + ) } diff --git a/src/components/client/campaigns/CampaignsList.tsx b/src/components/client/campaigns/CampaignsList.tsx index 9ec0c16d8..a15e56593 100644 --- a/src/components/client/campaigns/CampaignsList.tsx +++ b/src/components/client/campaigns/CampaignsList.tsx @@ -33,7 +33,7 @@ export default function CampaignsList({ campaignToShow }: Props) { marginLeft: `-${theme.spacing(2.75)}`, })}> {campaigns?.map((campaign, index) => ( - + - + {t('campaigns:campaigns')} - + {t('campaigns:cta.support-cause-today')} diff --git a/src/components/client/index/sections/ActiveCampaignsSection/ActiveCampaignCard/ActiveCampaignCard.styled.tsx b/src/components/client/index/sections/ActiveCampaignsSection/ActiveCampaignCard/ActiveCampaignCard.styled.tsx index 6ad317c10..00418d36f 100644 --- a/src/components/client/index/sections/ActiveCampaignsSection/ActiveCampaignCard/ActiveCampaignCard.styled.tsx +++ b/src/components/client/index/sections/ActiveCampaignsSection/ActiveCampaignCard/ActiveCampaignCard.styled.tsx @@ -42,7 +42,7 @@ export const StyledContent = styled(CardContent)(() => ({ '&:last-child': { paddingBottom: 0 }, })) -export const CampaignTitle = styled('h6')(() => ({ +export const CampaignTitle = styled('h3')(() => ({ fontSize: theme.typography.pxToRem(16), color: theme.palette.common.black, fontFamily: 'Montserrat, sans-serif', diff --git a/src/pages/campaigns/index.tsx b/src/pages/campaigns/index.tsx index a9e5cad03..a6cd1b5ba 100644 --- a/src/pages/campaigns/index.tsx +++ b/src/pages/campaigns/index.tsx @@ -10,19 +10,23 @@ import { CampaignResponse } from 'gql/campaigns' export const getServerSideProps: GetServerSideProps = async (params) => { const client = new QueryClient() - await client.prefetchQuery( - [endpoints.campaign.listCampaigns.url], - campaignsOrderQueryFunction, - ) - await prefetchCampaignTypesList(client) + const result = await Promise.allSettled([ + await client.prefetchQuery( + [endpoints.campaign.listCampaigns.url], + campaignsOrderQueryFunction, + ), + prefetchCampaignTypesList(client), + await serverSideTranslations(params.locale ?? 'bg', [ + 'common', + 'auth', + 'validation', + 'campaigns', + ]), + ]) + const ssrTranslations = result[2].status === 'fulfilled' ? result[2].value : null return { props: { - ...(await serverSideTranslations(params.locale ?? 'bg', [ - 'common', - 'auth', - 'validation', - 'campaigns', - ])), + ...ssrTranslations, dehydratedState: dehydrate(client), }, }