-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'staging-blog' into james/acx-2701-implement-semantic-he…
…ading-tag-for-blog-header
- Loading branch information
Showing
3 changed files
with
26 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,27 @@ | ||
import { Text } from "@/app/_components/text"; | ||
import ArticleSnippetCard from "./article-snippet-card"; | ||
import ArticleFullCard from "./article-full-card"; | ||
import { | ||
BlogPostWithRelevantEntries, | ||
retrieveContentfulPublishedSlugs, | ||
} from "@/app/_lib/contentful"; | ||
import { retrieveContentfulPublishedSlugs } from "@/app/_lib/contentful"; | ||
import { SearchParams } from "../page"; | ||
import { useState } from "react"; | ||
|
||
export async function Posts({ | ||
getStartedSnippets, | ||
recentArticleSlugs, | ||
searchParams, | ||
}: { | ||
searchParams: SearchParams; | ||
recentArticleSlugs: string[]; | ||
getStartedSnippets: (BlogPostWithRelevantEntries | undefined)[]; | ||
}) { | ||
export async function Posts({ searchParams }: { searchParams: SearchParams }) { | ||
const search = searchParams["search"]; | ||
if (!search) { | ||
return ( | ||
<> | ||
<div className="flex w-full flex-col gap-4"> | ||
<Text variant="body" className="text-grey-400"> | ||
Get started with Across | ||
</Text> | ||
<div className="w-full overflow-x-scroll scrollbar-hide"> | ||
<div className="grid w-[1024px] grid-cols-3 gap-5 md:w-full"> | ||
{getStartedSnippets.slice(0, 3).map((snippet) => ( | ||
<div className="w-full" key={snippet?.fields.slug}> | ||
<ArticleSnippetCard article={snippet!} /> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
<div className="flex w-full flex-col gap-4"> | ||
<Text variant="body" className="text-grey-400"> | ||
Most recent articles | ||
</Text> | ||
{recentArticleSlugs.map((slug) => ( | ||
<ArticleFullCard key={slug} slug={slug} /> | ||
))} | ||
</div> | ||
</> | ||
); | ||
} else { | ||
const searchedSlugs = await retrieveContentfulPublishedSlugs({ | ||
query: search, | ||
}); | ||
return searchedSlugs.length === 0 ? ( | ||
<h2 className="text-2xl my-auto flex-1 text-grey-400">No results.</h2> | ||
) : ( | ||
<div className="flex w-full flex-col gap-4"> | ||
<Text variant="body" className="text-grey-400"> | ||
Search results | ||
</Text> | ||
{searchedSlugs.map((slug) => ( | ||
<ArticleFullCard key={slug} slug={slug} /> | ||
))} | ||
</div> | ||
); | ||
} | ||
const isSearch = Boolean(!!search); | ||
const pageLength = 6; | ||
const searchedSlugs = await retrieveContentfulPublishedSlugs({ | ||
query: search ? decodeURI(search) : undefined, | ||
sortByRecent: true, | ||
limit: pageLength, | ||
}); | ||
|
||
return ( | ||
<div className="flex w-full flex-col gap-4"> | ||
<Text variant="body" className="text-grey-400"> | ||
{isSearch ? "Search results" : "Most recent articles"} | ||
</Text> | ||
{searchedSlugs.map((slug) => ( | ||
<ArticleFullCard key={slug} slug={slug} /> | ||
))} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters