Skip to content

Commit

Permalink
do not render "category" if there's no category filter
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangohjw committed Jan 2, 2025
1 parent 2a4720b commit cf20aa4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ export const BlogCard = ({
imageSrc,
itemTitle,
siteAssetsBaseUrl,
shouldShowCategory = true,
shouldShowDate = true,
tags = [],
}: CollectionCardProps & {
shouldShowCategory?: boolean
shouldShowDate?: boolean
siteAssetsBaseUrl: string | undefined
LinkComponent: CollectionPageSchemaType["LinkComponent"]
Expand Down Expand Up @@ -84,9 +86,11 @@ export const BlogCard = ({
</Text>
)}
{/* TODO: Feature enhancement? Filter by category when clicked */}
<Text className="prose-label-sm-medium text-base-content-subtle">
{category}
</Text>
{shouldShowCategory && (
<Text className="prose-label-sm-medium text-base-content-subtle">
{category}
</Text>
)}
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ export const CollectionCard = ({
imageSrc,
itemTitle,
siteAssetsBaseUrl,
shouldShowCategory = true,
shouldShowDate = true,
tags = [],
}: CollectionCardProps & {
shouldShowCategory?: boolean
shouldShowDate?: boolean
siteAssetsBaseUrl: string | undefined
LinkComponent: CollectionPageSchemaType["LinkComponent"]
Expand Down Expand Up @@ -69,9 +71,11 @@ export const CollectionCard = ({
</Text>
)}
{/* TODO: Feature enhancement? Filter by category when clicked */}
<Text className="prose-label-md mt-3 text-base-content-subtle lg:mt-2">
{category}
</Text>
{shouldShowCategory && (
<Text className="prose-label-md mt-3 text-base-content-subtle lg:mt-2">
{category}
</Text>
)}
</div>
{image && (
<div className="relative mt-3 min-h-40 w-full shrink-0 lg:ml-4 lg:mt-0 lg:h-auto lg:w-1/4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { Skeleton } from "../Skeleton"
import CollectionClient from "./CollectionClient"
import { getAvailableFilters } from "./filterUtils"
import { shouldShowDate } from "./utils"
import { shouldShowCategory, shouldShowDate } from "./utils"

const CATEGORY_OTHERS = "Others"

Expand Down Expand Up @@ -169,6 +169,7 @@ const CollectionLayout = ({
site.siteMap,
page.permalink.split("/").slice(1),
)
const availableFilters = getAvailableFilters(processedItems)

return (
<Skeleton
Expand All @@ -182,7 +183,8 @@ const CollectionLayout = ({
page={page}
breadcrumb={breadcrumb}
items={processedItems}
filters={getAvailableFilters(processedItems)}
filters={availableFilters}
shouldShowCategory={shouldShowCategory(availableFilters)}
shouldShowDate={shouldShowDate(processedItems)}
siteAssetsBaseUrl={site.assetsBaseUrl}
LinkComponent={LinkComponent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface CollectionClientProps {
page: CollectionPagePageProps
items: ProcessedCollectionCardProps[]
filters: FilterType[]
shouldShowCategory: boolean
shouldShowDate: boolean
siteAssetsBaseUrl: string | undefined
breadcrumb: BreadcrumbProps
Expand Down Expand Up @@ -55,6 +56,7 @@ const CollectionClient = ({
page,
items,
filters,
shouldShowCategory,
shouldShowDate,
siteAssetsBaseUrl,
breadcrumb,
Expand Down Expand Up @@ -130,6 +132,7 @@ const CollectionClient = ({
paginatedItems={paginatedItems}
searchValue={searchValue}
totalCount={totalCount}
shouldShowCategory={shouldShowCategory}
shouldShowDate={shouldShowDate}
siteAssetsBaseUrl={siteAssetsBaseUrl}
LinkComponent={LinkComponent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface CollectionResultProps
| "handleClearFilter"
| "totalCount"
> {
shouldShowCategory?: boolean
shouldShowDate?: boolean
variant?: CollectionVariant
siteAssetsBaseUrl: string | undefined
Expand Down Expand Up @@ -48,6 +49,7 @@ export const CollectionResults = ({
filteredCount,
handleClearFilter,
totalCount,
shouldShowCategory = true,
shouldShowDate = true,
siteAssetsBaseUrl,
LinkComponent,
Expand Down Expand Up @@ -88,6 +90,7 @@ export const CollectionResults = ({
<CollectionCard
key={`${item.title}-${item.category}`}
{...item}
shouldShowCategory={shouldShowCategory}
shouldShowDate={shouldShowDate}
siteAssetsBaseUrl={siteAssetsBaseUrl}
LinkComponent={LinkComponent}
Expand All @@ -96,6 +99,7 @@ export const CollectionResults = ({
<BlogCard
key={`${item.title}-${item.category}`}
{...item}
shouldShowCategory={shouldShowCategory}
shouldShowDate={shouldShowDate}
siteAssetsBaseUrl={siteAssetsBaseUrl}
LinkComponent={LinkComponent}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AppliedFilter } from "../../types/Filter"
import type { AppliedFilter, Filter } from "../../types/Filter"
import type { ProcessedCollectionCardProps } from "~/interfaces"
import {
FILTER_ID_CATEGORY,
Expand Down Expand Up @@ -124,6 +124,11 @@ export const updateAppliedFilters = (
}
}

// use filters generated as the single source of truth
export const shouldShowCategory = (filters: Filter[]): boolean => {
return Boolean(filters.find((filter) => filter.id === FILTER_ID_CATEGORY))
}

export const shouldShowDate = (
items: ProcessedCollectionCardProps[],
): boolean => {
Expand Down

0 comments on commit cf20aa4

Please sign in to comment.