Skip to content

Commit

Permalink
Merge pull request #1442 from danskernesdigitalebibliotek/find-on-sel…
Browse files Browse the repository at this point in the history
…f-no-creators

Ensure creatorsToString() always returns a string
  • Loading branch information
kasperg authored Sep 20, 2024
2 parents 3d2fc45 + 2eb2469 commit 29cce46
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/core/utils/helpers/general.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef } from "react";
import dayjs from "dayjs";
import { uniq } from "lodash";
import { first, uniq } from "lodash";
import { vi } from "vitest";
import { CoverProps } from "../../../components/cover/cover";
import { UseTextFunction } from "../text";
Expand Down Expand Up @@ -67,13 +67,18 @@ const getCreatorsFromManifestations = (manifestations: Manifestation[]) => {
return Array.from(new Set(creators)) as string[];
};

export const creatorsToString = (creators: string[], t: UseTextFunction) => {
export const creatorsToString = (
creators: string[],
t: UseTextFunction
): string => {
if (creators.length > 1) {
const firstTwo = creators.slice(0, 2);
return `${firstTwo.join(", ")} ${t("etAlText")}`;
}

return creators[0];
if (creators.length === 1) {
return first(creators) as string;
}
return "";
};

export const getCreatorTextFromManifestations = (
Expand Down

0 comments on commit 29cce46

Please sign in to comment.