fix: route home view-all links

This commit is contained in:
TerryM
2026-05-28 16:49:30 +08:00
parent 4c15e01460
commit 5fec82dbba
6 changed files with 90 additions and 68 deletions

View File

@@ -2,22 +2,20 @@ import { useSearchParams } from "react-router-dom";
import { MessageStream } from "../../components/messageStream/MessageStream";
import { SectionHeader } from "../../components/SectionHeader";
import { useI18n } from "../../i18n";
import { isPopularTag } from "../../utils/popularTag";
export function Browse() {
const { t, lang } = useI18n();
const { t } = useI18n();
const [sp] = useSearchParams();
const q = sp.get("q") || "";
const sort = sp.get("sort") || "";
const tag = sp.get("tag") || "";
const title = q
? `${t("search")}: ${q}`
: isPopularTag(tag, lang)
? t("popular")
: sort === "latest"
? t("latest")
: sort === "recommended"
? t("official")
: sort === "latest"
? t("latest")
: sort === "recommended"
? t("official")
: sort === "popular"
? t("popular")
: t("all");
return (
<section>

View File

@@ -13,7 +13,6 @@ import { SectionHeader } from "../../components/SectionHeader";
import { MessageBubble } from "../../components/messageStream/MessageBubble";
import { langQuery, useI18n } from "../../i18n";
import { sourceLanguageQuery } from "../../i18nLanguages";
import { popularTagParam } from "../../utils/popularTag";
import { cleanCategoryDisplayName } from "../../utils/categoryDisplay";
import {
postToResource,
@@ -68,9 +67,9 @@ export function Home() {
Promise.all([
getJSON<Category[]>(`/api/categories${catQ}`),
getJSON<{ items: Post[] }>(`/api/posts/recommended${postQ}&limit=12`),
getJSON<{ items: Post[] }>(`/api/posts/latest${postQ}&limit=5`),
getJSON<{ items: Post[] }>(`/api/posts${postQ}&sort=latest&limit=5`),
getJSON<{ items: Post[] }>(
`/api/posts${postQ}&tag=${popularTagParam(lang)}&limit=5`,
`/api/posts${postQ}&sort=popular&limit=5`,
).catch((): { items: Post[] } => ({ items: [] })),
])
.then(([c, r, l, p]) => {
@@ -367,7 +366,7 @@ export function Home() {
<div className="px-4 md:px-0">
<SectionHeader
title={t("latestSection")}
viewAllTo="/browse?sort=latest"
viewAllTo="/browse"
viewAllLabel={t("viewAll")}
/>
</div>
@@ -393,7 +392,7 @@ export function Home() {
<div className="px-4 md:px-0">
<SectionHeader
title={t("popularSection")}
viewAllTo={`/browse?tag=${popularTagParam(lang)}`}
viewAllTo="/browse?sort=popular"
viewAllLabel={t("viewAll")}
/>
</div>