From 1db130feb0f678dc972a72d9147225ba4f285a0b Mon Sep 17 00:00:00 2001 From: LasseStaus Date: Wed, 17 Jan 2024 18:22:55 +0100 Subject: [PATCH] WIP --- .../recommendation/recommendation.dev.tsx | 34 +++++ .../recommendation/recommendation.entry.tsx | 19 +++ .../recommendation/recommendation.mount.ts | 4 + src/apps/recommendation/recommendation.tsx | 117 ++++++++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 src/apps/recommendation/recommendation.dev.tsx create mode 100644 src/apps/recommendation/recommendation.entry.tsx create mode 100644 src/apps/recommendation/recommendation.mount.ts create mode 100644 src/apps/recommendation/recommendation.tsx diff --git a/src/apps/recommendation/recommendation.dev.tsx b/src/apps/recommendation/recommendation.dev.tsx new file mode 100644 index 0000000000..299607dde3 --- /dev/null +++ b/src/apps/recommendation/recommendation.dev.tsx @@ -0,0 +1,34 @@ +import { ComponentMeta, ComponentStory } from "@storybook/react"; +import React from "react"; +import Recommendation, { + RecommendationEntryProps +} from "./recommendation.entry"; +import globalTextArgs, { + GlobalEntryTextProps +} from "../../core/storybook/globalTextArgs"; +import serviceUrlArgs from "../../core/storybook/serviceUrlArgs"; + +export default { + title: "Apps / Recommendation", + component: Recommendation, + argTypes: { + titleText: { + defaultValue: "Greetings", + control: { type: "text" } + }, + introductionText: { + defaultValue: "We warmly welcome everybody by saying:", + control: { type: "text" } + }, + whatText: { + defaultValue: "world", + control: { type: "text" } + }, + ...globalTextArgs, + ...serviceUrlArgs + } +} as ComponentMeta; + +export const App: ComponentStory = ( + args: RecommendationEntryProps & GlobalEntryTextProps +) => ; diff --git a/src/apps/recommendation/recommendation.entry.tsx b/src/apps/recommendation/recommendation.entry.tsx new file mode 100644 index 0000000000..fb81b8dfa0 --- /dev/null +++ b/src/apps/recommendation/recommendation.entry.tsx @@ -0,0 +1,19 @@ +import React from "react"; +import { GlobalEntryTextProps } from "../../core/storybook/globalTextArgs"; +import { withText } from "../../core/utils/text"; +import Recommendation from "./recommendation"; +import { withConfig } from "../../core/utils/config"; +import { withUrls } from "../../core/utils/url"; + +export interface RecommendationEntryProps { + titleText: string; + introductionText: string; + whatText: string; + href: string; +} + +const RecommendationEntry: React.FC< + RecommendationEntryProps & GlobalEntryTextProps +> = () => ; + +export default withConfig(withUrls(withText(RecommendationEntry))); diff --git a/src/apps/recommendation/recommendation.mount.ts b/src/apps/recommendation/recommendation.mount.ts new file mode 100644 index 0000000000..e9d9e99323 --- /dev/null +++ b/src/apps/recommendation/recommendation.mount.ts @@ -0,0 +1,4 @@ +import addMount from "../../core/addMount"; +import recommendation from "./recommendation.entry"; + +addMount({ appName: "recommendation", app: recommendation }); diff --git a/src/apps/recommendation/recommendation.tsx b/src/apps/recommendation/recommendation.tsx new file mode 100644 index 0000000000..f8a75cb9d3 --- /dev/null +++ b/src/apps/recommendation/recommendation.tsx @@ -0,0 +1,117 @@ +import * as React from "react"; +import clsx from "clsx"; +import { Hello } from "../../components/hello/hello"; +import { + Manifestation, + useGetMaterialQuery +} from "../../core/dbc-gateway/generated/graphql"; +import { useText } from "../../core/utils/text"; +import { Work } from "../../core/utils/types/entities"; +import { + creatorsToString, + flattenCreators, + getManifestationPid +} from "../../core/utils/helpers/general"; +import { Cover } from "../../components/cover/cover"; +import Arrow from "../../components/atoms/icons/arrow/arrow"; +import { useDispatch } from "react-redux"; +import ButtonFavourite, { + ButtonFavouriteId +} from "../../components/button-favourite/button-favourite"; +import { guardedRequest } from "../../core/guardedRequests.slice"; +import { TypedDispatch } from "../../core/store"; + +export type RecommendationProps = { + positionImageRight?: boolean; + href: string; +}; + +const Recommendation: React.FC = ({ + positionImageRight, + href +}) => { + const t = useText(); + const { data, isLoading } = useGetMaterialQuery({ + wid: "work-of:870970-basis:136336282" + }); + const [selectedManifestations, setSelectedManifestations] = React.useState< + Manifestation[] | null + >(null); + + if (isLoading) { + return
Loading...
; + } + const { + work, + work: { + manifestations: { all: manifestations }, + relations: { hasReview }, + creators, + workId + } + } = data as { work: Work }; + + const pid = manifestations ? getManifestationPid(manifestations) : null; // Noget med typen + const dispatch = useDispatch(); + console.log("work", work); + const author = creatorsToString(flattenCreators(creators), t); + + const addToListRequest = (id: ButtonFavouriteId) => { + dispatch( + guardedRequest({ + type: "addFavorite", + args: { id }, + app: "search-result" + }) + ); + }; + return ( + <> +
+
+
+
+ +
+ + {pid && ( +
+ {" "} + +
+ )} +
+

+ {author}{" "} + + something year + +

+

+ something text +

+
+
+
+ +

midlertidig titel

+

midlertidig text

+ +
+
+ + ); +}; +export default Recommendation;