Removed tags from cached payload

This commit is contained in:
DrMint 2024-03-09 11:44:36 +01:00
parent ae74a8988f
commit b06c624d41
5 changed files with 18 additions and 39 deletions

View File

@ -1,17 +1,22 @@
---
import Metadata from "components/Metadata.astro";
import { getI18n } from "src/i18n/i18n";
import type { EndpointTagsGroup } from "src/shared/payload/payload-sdk";
interface Props {
slug: string;
icon: string;
values: string[];
tagGroup: EndpointTagsGroup;
}
const { icon, slug, values } = Astro.props;
const { formatTag, formatTagsGroup } = await getI18n(Astro.locals.currentLocale);
const {
tagGroup: { icon, translations, tags },
} = Astro.props;
const { getLocalizedMatch } = await getI18n(Astro.locals.currentLocale);
---
{/* ------------------------------------------- HTML ------------------------------------------- */}
<Metadata icon={icon} title={formatTagsGroup(slug)} values={values.map(formatTag)} />
<Metadata
icon={icon}
title={getLocalizedMatch(translations).name}
values={tags.map(({ translations }) => getLocalizedMatch(translations).name)}
/>

View File

@ -1,8 +1,9 @@
---
import type { EndpointTagsGroup } from "src/shared/payload/payload-sdk";
import TagGroup from "./TagGroup.astro";
interface Props {
tagGroups: { slug: string; icon: string; values: string[] }[];
tagGroups: EndpointTagsGroup[];
}
const { tagGroups } = Astro.props;
@ -11,7 +12,7 @@ const { tagGroups } = Astro.props;
{/* ------------------------------------------- HTML ------------------------------------------- */}
<div>
{tagGroups.map((tag) => <TagGroup {...tag} />)}
{tagGroups.map((tag) => <TagGroup tagGroup={tag} />)}
<slot />
</div>

View File

@ -126,18 +126,6 @@ export const getI18n = async (locale: string) => {
const getLocalizedUrl = (url: string): string => `/${locale}${url}`;
const formatTag = (id: string): string => {
const tag = cache.tags.find(({ slug }) => slug === id);
if (!tag) return "UNKNOWN";
return getLocalizedMatch(tag.translations).name;
};
const formatTagsGroup = (id: string): string => {
const tag = cache.tagsGroups.find(({ slug }) => slug === id);
if (!tag) return "UNKNOWN";
return getLocalizedMatch(tag.translations).name;
};
const formatPrice = (price: { amount: number; currency: string }): string =>
price.amount.toLocaleString(locale, { style: "currency", currency: price.currency });
@ -172,8 +160,6 @@ export const getI18n = async (locale: string) => {
t,
getLocalizedMatch,
getLocalizedUrl,
formatTag,
formatTagsGroup,
formatPrice,
formatDate,
formatInches,

View File

@ -1474,12 +1474,11 @@ export type EndpointTag = {
language: string;
name: string;
}[];
group: string;
};
export type EndpointTagsGroup = {
slug: string;
icon?: string;
icon: string;
translations: {
language: string;
name: string;
@ -1492,7 +1491,7 @@ export type EndpointPagePreview = {
type: PageType;
thumbnail?: PayloadImage;
authors: EndpointRecorder[];
tagGroups: TagGroup[];
tagGroups: EndpointTagsGroup[];
translations: {
language: string;
pretitle?: string;
@ -1533,7 +1532,7 @@ export type EndpointCollectiblePreview = {
subtitle?: string;
description?: RichTextContent;
}[];
tagGroups: TagGroup[];
tagGroups: EndpointTagsGroup[];
status: "draft" | "published";
releaseDate?: string;
languages: string[];
@ -1599,8 +1598,6 @@ export type EndpointCollectible = EndpointCollectiblePreview & {
parentPages: ParentPage[];
};
export type TagGroup = { slug: string; icon: string; values: string[] };
export type TableOfContentEntry = {
prefix: string;
title: string;

View File

@ -1,24 +1,14 @@
import {
payload,
type Language,
type EndpointTag,
type EndpointTagsGroup,
type EndpointWording,
} from "src/shared/payload/payload-sdk";
import { payload, type Language, type EndpointWording } from "src/shared/payload/payload-sdk";
type Cache = {
locales: Language[];
currencies: string[];
wordings: EndpointWording[];
tags: EndpointTag[];
tagsGroups: EndpointTagsGroup[];
};
const fetchNewData = async (): Promise<Cache> => ({
locales: await payload.getLanguages(),
currencies: (await payload.getCurrencies()).map(({ id }) => id),
tags: await payload.getTags(),
tagsGroups: await payload.getTagsGroups(),
wordings: await payload.getWordings(),
});