@mui/material#ImageList TypeScript Examples

The following examples show how to use @mui/material#ImageList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CampaignFilter.tsx    From frontend with MIT License 5 votes vote down vote up
export default function CampaignFilter() {
  const { t } = useTranslation()
  const { mobile } = useMobile()
  const { data: campaigns, isLoading } = useCampaignList()
  const [selectedCategory, setSelectedCategory] = useState<string | undefined>()

  const campaignToShow = useMemo<CampaignResponse[]>(() => {
    return (
      campaigns?.filter((campaign) => {
        if (selectedCategory) {
          return campaign.campaignType.category === selectedCategory
        }
        return campaign
      }) ?? []
    )
  }, [campaigns, selectedCategory])

  return (
    <Root>
      <ImageList
        cols={mobile ? 2 : 6}
        rowHeight={164}
        sx={{ maxWidth: 'lg', margin: '0 auto', my: 6 }}>
        {Object.values(CampaignTypeCategory).map((category) => {
          const count =
            campaigns?.filter((campaign) => campaign.campaignType.category === category).length ?? 0
          return (
            <IconButton
              key={category}
              disabled={count === 0}
              className={classes.filterButtons}
              onClick={() => setSelectedCategory(category)}>
              {categories[category].icon ?? <Category fontSize="large" />}
              <Typography>
                {t(`campaigns:filters.${category}`)} ({count})
              </Typography>
            </IconButton>
          )
        })}
        <IconButton
          disabled={!selectedCategory}
          className={classes.filterButtons}
          onClick={() => setSelectedCategory(undefined)}>
          <FilterNone fontSize="large" />
          <Typography>
            {t(`campaigns:filters.all`)} ({campaigns?.length ?? 0})
          </Typography>
        </IconButton>
      </ImageList>
      {isLoading ? (
        <Box textAlign="center">
          <CircularProgress size="3rem" />
        </Box>
      ) : (
        <CampaignsList campaignToShow={campaignToShow} />
      )}
    </Root>
  )
}