From be3c0023feff6a49abfec6b6808a2ff08c9d0198 Mon Sep 17 00:00:00 2001 From: codytseng Date: Fri, 5 Sep 2025 22:28:13 +0800 Subject: [PATCH] fix: some bugs --- src/components/PostEditor/PostContent.tsx | 2 -- src/layouts/PrimaryPageLayout/index.tsx | 2 +- src/pages/primary/SearchPage/index.tsx | 18 ++++++++++++++---- src/services/post-editor-cache.service.ts | 1 - 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/PostEditor/PostContent.tsx b/src/components/PostEditor/PostContent.tsx index 089061e4..031aa8bc 100644 --- a/src/components/PostEditor/PostContent.tsx +++ b/src/components/PostEditor/PostContent.tsx @@ -82,7 +82,6 @@ export default function PostContent({ relays: [] } ) - setSpecifiedRelayUrls(cachedSettings.specifiedRelayUrls) setAddClientTag(cachedSettings.addClientTag ?? false) } return @@ -93,7 +92,6 @@ export default function PostContent({ isNsfw, isPoll, pollCreateData, - specifiedRelayUrls, addClientTag } ) diff --git a/src/layouts/PrimaryPageLayout/index.tsx b/src/layouts/PrimaryPageLayout/index.tsx index 3ec745ed..7f63dad8 100644 --- a/src/layouts/PrimaryPageLayout/index.tsx +++ b/src/layouts/PrimaryPageLayout/index.tsx @@ -108,7 +108,7 @@ PrimaryPageLayout.displayName = 'PrimaryPageLayout' export default PrimaryPageLayout export type TPrimaryPageLayoutRef = { - scrollToTop: () => void + scrollToTop: (behavior?: ScrollBehavior) => void } function PrimaryPageTitlebar({ diff --git a/src/pages/primary/SearchPage/index.tsx b/src/pages/primary/SearchPage/index.tsx index 9e8659d8..d60c6d8f 100644 --- a/src/pages/primary/SearchPage/index.tsx +++ b/src/pages/primary/SearchPage/index.tsx @@ -1,16 +1,25 @@ import SearchBar, { TSearchBarRef } from '@/components/SearchBar' import SearchResult from '@/components/SearchResult' -import PrimaryPageLayout from '@/layouts/PrimaryPageLayout' +import PrimaryPageLayout, { TPrimaryPageLayoutRef } from '@/layouts/PrimaryPageLayout' import { usePrimaryPage } from '@/PageManager' import { TSearchParams } from '@/types' -import { forwardRef, useEffect, useMemo, useRef, useState } from 'react' +import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react' const SearchPage = forwardRef((_, ref) => { const { current, display } = usePrimaryPage() const [input, setInput] = useState('') const [searchParams, setSearchParams] = useState(null) - const searchBarRef = useRef(null) const isActive = useMemo(() => current === 'search' && display, [current, display]) + const searchBarRef = useRef(null) + const layoutRef = useRef(null) + + useImperativeHandle( + ref, + () => ({ + scrollToTop: (behavior: ScrollBehavior = 'smooth') => layoutRef.current?.scrollToTop(behavior) + }), + [] + ) useEffect(() => { if (isActive && !searchParams) { @@ -23,11 +32,12 @@ const SearchPage = forwardRef((_, ref) => { if (params?.input) { setInput(params.input) } + layoutRef.current?.scrollToTop('instant') } return ( diff --git a/src/services/post-editor-cache.service.ts b/src/services/post-editor-cache.service.ts index 5604d1ba..f2ac915e 100644 --- a/src/services/post-editor-cache.service.ts +++ b/src/services/post-editor-cache.service.ts @@ -6,7 +6,6 @@ type TPostSettings = { isNsfw?: boolean isPoll?: boolean pollCreateData?: TPollCreateData - specifiedRelayUrls?: string[] addClientTag?: boolean }