Skip to content

Commit

Permalink
feat: handle change in hygraph tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierniki committed Nov 9, 2023
1 parent c1ff0df commit 190e1f3
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/app/[lang]/article/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default async function Web({ params: { slug, lang } }: ArticlePageProps)
publicationDate: publishedAt,
title,
author: { name: author?.name ?? "Anonymous", imageUrl: author?.avatar?.data?.url },
tags,
tags: tags.map(({ tag }) => tag),
slug,
}}
asLink={false}
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/webhook/publish/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function handleAlgoliaPublishWebhook(req: NextRequestWithValidBody<Publish
title,
content: slateToText(content),
slug,
tags,
tags: tags.map(({ tag }) => tag),
})

return { title, locale }
Expand Down Expand Up @@ -55,7 +55,7 @@ const articleSchema = z.object({
title: z.string(),
locale: z.string(),
slug: z.string(),
tags: z.array(z.string()),
tags: z.array(z.object({ tag: z.string() })),
})
),
id: z.string(),
Expand Down
4 changes: 2 additions & 2 deletions src/components/ArticleCard/ArticleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type ArticleCardProps = {
}

export const hygraphArticleToCardProps = (article: {
tags: string[]
tags: { tag: string }[]
title: string
author?: { name: string; avatar?: { data: { url: string } } | undefined | null } | null
image?: { data: { url: string }; description?: { text: string } | undefined | null } | null
Expand All @@ -39,7 +39,7 @@ export const hygraphArticleToCardProps = (article: {
slug: string
}) => {
return {
tags: article?.tags,
tags: article?.tags?.map(({ tag }) => tag),
imageUrl: article?.image?.data?.url,
imageAlt: article.image?.description?.text,
title: article?.title,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ArticlesGrid/ArticlesGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Article = {
id: string
slug: string
title: string
tags: string[]
tags: { tag: string }[]
image?: Nullable<{
description?: ImageDescription
data: ImageData
Expand Down
8 changes: 5 additions & 3 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { env } from "@/env.mjs"
import { Locale, standardNotationToHygraphLocale } from "@/i18n/i18n"
import { TypedDocumentNode } from "@graphql-typed-document-node/core"
import { print } from "graphql"
import omit from "lodash/omit"
import pThrottle from "p-throttle"
import { env } from "@/env.mjs"
import { Locale, standardNotationToHygraphLocale } from "@/i18n/i18n"
import {
getArticleBySlugQuery,
getArticleMetadataBySlugQuery,
Expand Down Expand Up @@ -149,7 +149,8 @@ export async function getRecentArticles(variables: { locale: Locale; skip?: numb
tags: ["ARTICLE"],
variables,
})
return { articles, count: articlesConnection.aggregate.count }

return { articles: articles, count: articlesConnection.aggregate.count }
}

export async function getRecentArticlesWithMain(variables: { locale: Locale; skip?: number; first?: number }) {
Expand All @@ -159,6 +160,7 @@ export async function getRecentArticlesWithMain(variables: { locale: Locale; ski
tags: ["ARTICLE"],
variables,
})

return { articles, count: articlesConnection.aggregate.count, mainArticle }
}

Expand Down
28 changes: 21 additions & 7 deletions src/lib/queries/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export const getRecentArticlesWithMainQuery = graphql(`
locale
slug
title
tags
tags {
tag
}
content {
raw
}
Expand Down Expand Up @@ -74,7 +76,9 @@ export const getRecentArticlesWithMainQuery = graphql(`
locale
slug
title
tags
tags {
tag
}
image {
description {
text
Expand Down Expand Up @@ -109,7 +113,9 @@ export const getRecentArticlesQuery = graphql(`
locale
slug
title
tags
tags {
tag
}
image {
description {
text
Expand All @@ -134,7 +140,9 @@ export const getArticleRecommendedArticlesQuery = graphql(`
title
slug
id
tags
tags {
tag
}
publishedAt
author {
name
Expand Down Expand Up @@ -163,7 +171,9 @@ export const getArticleBySlugQuery = graphql(`
id
title
publishedAt
tags
tags {
tag
}
image(forceParentLocale: true) {
id
description {
Expand Down Expand Up @@ -249,7 +259,9 @@ export const listArticlesBySlugQuery = graphql(`
}
}
}
tags
tags {
tag
}
}
}
`)
Expand Down Expand Up @@ -280,7 +292,9 @@ export const listArticlesByCategoryQuery = graphql(`
}
}
publishedAt
tags
tags {
tag
}
slug
title
id
Expand Down
8 changes: 6 additions & 2 deletions src/lib/queries/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export const getHomepageQuery = graphql(`
locale
slug
title
tags
tags {
tag
}
image {
description {
text
Expand Down Expand Up @@ -109,7 +111,9 @@ export const getHomepageQuery = graphql(`
locale
slug
title
tags
tags {
tag
}
image {
description {
text
Expand Down

0 comments on commit 190e1f3

Please sign in to comment.