diff --git a/src/screens/Hashtag.tsx b/src/screens/Hashtag.tsx index 5057f4a68d..e4f08291c9 100644 --- a/src/screens/Hashtag.tsx +++ b/src/screens/Hashtag.tsx @@ -121,7 +121,9 @@ export default function HashtagScreen({ {headerTitle} {author && ( - {_(msg`From @${sanitizedAuthor}`)} + {author.startsWith('did:') + ? _(msg`From ${sanitizedAuthor}`) + : _(msg`From @${sanitizedAuthor}`)} )} @@ -172,11 +174,9 @@ function HashtagScreenTab({ const isCashtag = fullTag.startsWith('$') const queryParam = useMemo(() => { - // Cashtags need # prefix for search: "#$BTC" or "#$BTC from:author" - const searchTag = isCashtag ? `#${fullTag}` : fullTag - if (!author) return searchTag - return `${searchTag} from:${author}` - }, [fullTag, author, isCashtag]) + // Cashtags need # prefix for search: "#$BTC" + return isCashtag ? `#${fullTag}` : fullTag + }, [fullTag, isCashtag]) const { data, @@ -188,7 +188,7 @@ function HashtagScreenTab({ refetch, fetchNextPage, hasNextPage, - } = useSearchPostsQuery({query: queryParam, sort, enabled: active}) + } = useSearchPostsQuery({query: queryParam, sort, enabled: active, author}) const posts = useMemo(() => { return data?.pages.flatMap(page => page.posts) || [] diff --git a/src/state/queries/search-posts.ts b/src/state/queries/search-posts.ts index 1fc8963caa..d951f67064 100644 --- a/src/state/queries/search-posts.ts +++ b/src/state/queries/search-posts.ts @@ -22,29 +22,35 @@ import { } from './util' const searchPostsQueryKeyRoot = 'search-posts' -const searchPostsQueryKey = ({query, sort}: {query: string; sort?: string}) => [ - searchPostsQueryKeyRoot, +const searchPostsQueryKey = ({ query, sort, -] + author, +}: { + query: string + sort?: string + author?: string +}) => [searchPostsQueryKeyRoot, query, sort, author] export function useSearchPostsQuery({ query, sort, enabled, + author, }: { query: string sort?: 'top' | 'latest' enabled?: boolean + author?: string }) { const agent = useAgent() const moderationOpts = useModerationOpts() const selectArgs = useMemo( () => ({ - isSearchingSpecificUser: /from:(\w+)/.test(query), + isSearchingSpecificUser: !!author || /from:(\w+)/.test(query), moderationOpts, }), - [query, moderationOpts], + [query, author, moderationOpts], ) const lastRun = useRef<{ data: InfiniteData @@ -59,13 +65,14 @@ export function useSearchPostsQuery({ QueryKey, string | undefined >({ - queryKey: searchPostsQueryKey({query, sort}), + queryKey: searchPostsQueryKey({query, sort, author}), queryFn: async ({pageParam}) => { const res = await agent.app.bsky.feed.searchPosts({ q: query, limit: 25, cursor: pageParam, sort, + author, }) return res.data },