From adf611cc2137049aa3c10e0a09c9e7f4f7dd74d7 Mon Sep 17 00:00:00 2001 From: Ferran Buireu Date: Sat, 7 Sep 2024 11:35:23 +0200 Subject: [PATCH] feat: add method to get article variant --- src/ui/modules/contact/utils/changeTab/changeTab.ts | 4 ++-- .../core/components/articleCard/ArticleCard.astro | 7 ++----- .../core/components/articleCard/ArticleCard.tsx | 11 ++--------- .../atoms/relatedArticleCard/RelatedArticleCard.astro | 9 +++------ .../articleVariantToClass/articleVariantToClass.ts | 10 ++++++++++ .../modules/core/utils/articleVariantToClass/index.ts | 1 + 6 files changed, 20 insertions(+), 22 deletions(-) create mode 100644 src/ui/modules/core/utils/articleVariantToClass/articleVariantToClass.ts create mode 100644 src/ui/modules/core/utils/articleVariantToClass/index.ts diff --git a/src/ui/modules/contact/utils/changeTab/changeTab.ts b/src/ui/modules/contact/utils/changeTab/changeTab.ts index b641560e..68e79ccc 100644 --- a/src/ui/modules/contact/utils/changeTab/changeTab.ts +++ b/src/ui/modules/contact/utils/changeTab/changeTab.ts @@ -28,8 +28,8 @@ export function initTabs() { for (const tab of tabs) { tab.addEventListener("click", () => { - changeTab(tab.dataset.target || ""); + changeTab(tab.dataset.target ?? ""); }); } - changeTab(tabs[0].dataset.target || ""); + changeTab(tabs[0].dataset.target ?? ""); } diff --git a/src/ui/modules/core/components/articleCard/ArticleCard.astro b/src/ui/modules/core/components/articleCard/ArticleCard.astro index 47c17f32..9e9764f9 100644 --- a/src/ui/modules/core/components/articleCard/ArticleCard.astro +++ b/src/ui/modules/core/components/articleCard/ArticleCard.astro @@ -1,8 +1,8 @@ --- import { Image } from "astro:assets"; import type { CollectionEntry } from "astro:content"; -import { ArticleType } from "@application/dto/article/types"; import { PAGES_ROUTES } from "@const/index"; +import { articleVariantToClass } from "@modules/core/utils/articleVariantToClass"; import { getLocation } from "@modules/core/utils/getLocation"; import clsx from "clsx"; import "./article-card.css"; @@ -17,10 +17,7 @@ const location = getLocation(Astro.url);
diff --git a/src/ui/modules/core/components/articleCard/ArticleCard.tsx b/src/ui/modules/core/components/articleCard/ArticleCard.tsx index 16411d98..6fca0468 100644 --- a/src/ui/modules/core/components/articleCard/ArticleCard.tsx +++ b/src/ui/modules/core/components/articleCard/ArticleCard.tsx @@ -1,5 +1,4 @@ import type { CollectionEntry } from "astro:content"; -import { ArticleType } from "@application/dto/article/types"; import { PAGES_ROUTES } from "@const/index"; import type { ArticleCardAuthorProps } from "@modules/core/components/articleCard/atoms/articleCardAuthor"; import { ArticleCardAuthor } from "@modules/core/components/articleCard/atoms/articleCardAuthor"; @@ -17,6 +16,7 @@ import type { ArticleCardTagsListProps } from "@modules/core/components/articleC import { ArticleCardTagsList } from "@modules/core/components/articleCard/atoms/articleCardTagsList"; import type { ArticleCardTitleProps } from "@modules/core/components/articleCard/atoms/articleCardTitle"; import { ArticleCardTitle } from "@modules/core/components/articleCard/atoms/articleCardTitle"; +import { articleVariantToClass } from "@modules/core/utils/articleVariantToClass"; import { getLocation } from "@modules/core/utils/getLocation"; import clsx from "clsx"; import type { ReactNode } from "react"; @@ -36,14 +36,7 @@ export const ArticleCard = ({ children, location: origin, data }: ArticleCardPro {" "}
{children}
diff --git a/src/ui/modules/core/components/relatedArticles/atoms/relatedArticleCard/RelatedArticleCard.astro b/src/ui/modules/core/components/relatedArticles/atoms/relatedArticleCard/RelatedArticleCard.astro index 41ffb351..be1b30ac 100644 --- a/src/ui/modules/core/components/relatedArticles/atoms/relatedArticleCard/RelatedArticleCard.astro +++ b/src/ui/modules/core/components/relatedArticles/atoms/relatedArticleCard/RelatedArticleCard.astro @@ -1,8 +1,8 @@ --- import { Image } from "astro:assets"; import type { CollectionEntry } from "astro:content"; -import { ArticleType } from "@application/dto/article/types"; import { PAGES_ROUTES } from "@const/index"; +import { articleVariantToClass } from "@modules/core/utils/articleVariantToClass"; import clsx from "clsx"; import "./related-article-card.css"; @@ -16,14 +16,11 @@ const relatedArticle = Astro.props as RelatedArticleCardProps;
{relatedArticle.data.featuredImage && ( - ([ + [ArticleType.DEFAULT, "--default-variant"], + [ArticleType.NO_IMAGE, "--no-image-variant"], +]); + +export function articleVariantToClass(variant: ArticleType) { + return variantClassMap.get(variant) ?? "--default-variant"; +} diff --git a/src/ui/modules/core/utils/articleVariantToClass/index.ts b/src/ui/modules/core/utils/articleVariantToClass/index.ts new file mode 100644 index 00000000..9abcfe89 --- /dev/null +++ b/src/ui/modules/core/utils/articleVariantToClass/index.ts @@ -0,0 +1 @@ +export * from "./articleVariantToClass";