feat: unify search with browse page
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user