feat: unify search with browse page

This commit is contained in:
TerryM
2026-05-27 11:33:48 +08:00
parent f169144378
commit 3f0a395f40
6 changed files with 45 additions and 140 deletions

View File

@@ -1,5 +1,6 @@
import { useEffect, useMemo, useRef } from "react";
import { useSearchParams } from "react-router-dom";
import { postJSON } from "../../api";
import { useI18n } from "../../i18n";
import type { PostScope } from "../../types/post";
import { FilterChips } from "./FilterChips";
@@ -16,8 +17,12 @@ export function MessageStream({ scope }: MessageStreamProps) {
const [sp, setSp] = useSearchParams();
const type = sp.get("type") || "all";
const q = (sp.get("q") || "").trim();
const params = useMemo(() => ({ scope, type, lang }), [scope, type, lang]);
const params = useMemo(
() => ({ scope, type, q, lang }),
[scope, type, q, lang],
);
const { items, isLoading, error, hasMore, loadMore, reset } =
usePostStream(params);
@@ -34,6 +39,10 @@ export function MessageStream({ scope }: MessageStreamProps) {
isLoadingRef.current = isLoading;
}, [isLoading]);
useEffect(() => {
if (q) postJSON("/api/search-log", { query: q }).catch(() => {});
}, [q]);
useEffect(() => {
const el = sentinelRef.current;
if (!el) return;