Skip to content

Commit

Permalink
Move displayCreators helper into a global helper file as it's used gl…
Browse files Browse the repository at this point in the history
…obally
  • Loading branch information
Adamik10 committed Dec 20, 2024
1 parent 4afdd08 commit 31a3cbc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion components/pages/workPageLayout/WorkPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
import { Badge } from "@/components/shared/badge/Badge"
import { CoverPicture } from "@/components/shared/coverPicture/CoverPicture"
import SlideSelect, { SlideSelectOption } from "@/components/shared/slideSelect/SlideSelect"
import { displayCreators } from "@/components/shared/workCard/helper"
import { WorkFullWorkPageFragment } from "@/lib/graphql/generated/fbi/graphql"
import { getCoverUrls, getLowResCoverUrl } from "@/lib/helpers/covers"
import { displayCreators } from "@/lib/helpers/helper.creators"
import { getIsbnsFromManifestation } from "@/lib/helpers/ids"
import { useGetCoverCollection } from "@/lib/rest/cover-service-api/generated/cover-service"
import { GetCoverCollectionSizesItem } from "@/lib/rest/cover-service-api/generated/model"
Expand Down
3 changes: 2 additions & 1 deletion components/shared/workCard/WorkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from "react"

import { WorkTeaserSearchPageFragment } from "@/lib/graphql/generated/fbi/graphql"
import { getCoverUrls, getLowResCoverUrl } from "@/lib/helpers/covers"
import { displayCreators } from "@/lib/helpers/helper.creators"
import { resolveUrl } from "@/lib/helpers/helper.routes"
import { getIsbnsFromWork } from "@/lib/helpers/ids"
import { useGetCoverCollection } from "@/lib/rest/cover-service-api/generated/cover-service"
Expand All @@ -12,7 +13,7 @@ import { useGetV1ProductsIdentifier } from "@/lib/rest/publizon-api/generated/pu
import { Badge } from "../badge/Badge"
import { CoverPicture } from "../coverPicture/CoverPicture"
import WorkCardAvailabilityRow from "./WorkCardAvailabilityRow"
import { displayCreators, getAllWorkPids } from "./helper"
import { getAllWorkPids } from "./helper"

type WorkCardProps = {
work: WorkTeaserSearchPageFragment
Expand Down
19 changes: 0 additions & 19 deletions components/shared/workCard/helper.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
import {
GeneralMaterialTypeCodeEnum,
ManifestationDetailsFragment,
SearchWithPaginationQuery,
WorkFullWorkPageFragment,
WorkTeaserSearchPageFragment,
} from "@/lib/graphql/generated/fbi/graphql"

export const displayCreators = (
creators: WorkFullWorkPageFragment["creators"] | ManifestationDetailsFragment["contributors"],
amount: number
) => {
return creators.reduce((acc, creator, index) => {
// We shorten to max <amount> creators
if (index === amount) {
return acc + ", et. al"
}
// We don't want to show one person twice
if (index > amount || acc.includes(creator.display)) {
return acc
}
return acc + (index > 0 ? ", " : "") + creator.display
}, "")
}

export const materialTypeCategories = {
reading: [
GeneralMaterialTypeCodeEnum.Articles,
Expand Down
21 changes: 21 additions & 0 deletions lib/helpers/helper.creators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
ManifestationDetailsFragment,
WorkFullWorkPageFragment,
} from "@/lib/graphql/generated/fbi/graphql"

export const displayCreators = (
creators: WorkFullWorkPageFragment["creators"] | ManifestationDetailsFragment["contributors"],
amount: number
) => {
return creators.reduce((acc, creator, index) => {
// We shorten to max <amount> creators
if (index === amount) {
return acc + ", et. al"
}
// We don't want to show one person twice
if (index > amount || acc.includes(creator.display)) {
return acc
}
return acc + (index > 0 ? ", " : "") + creator.display
}, "")
}

0 comments on commit 31a3cbc

Please sign in to comment.