Skip to content

Commit 07e5510

Browse files
Improved search UX by eliminating content flashing in ActivityPub
Fixed flashing between no result and suggested accounts
1 parent 371ec43 commit 07e5510

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

apps/activitypub/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tryghost/activitypub",
3-
"version": "3.0.2",
3+
"version": "3.0.3",
44
"license": "MIT",
55
"repository": {
66
"type": "git",

apps/activitypub/src/components/modals/Search.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ const Search: React.FC<SearchProps> = ({onOpenChange, query, setQuery}) => {
181181
const {data: topicsData} = topicsQuery;
182182

183183
const [displayResults, setDisplayResults] = useState<AccountSearchResult[]>([]);
184+
const [lastResultState, setLastResultState] = useState<'results' | 'none' | null>(null);
184185

185186
// Filter topics client-side (no additional API call needed)
186187
const matchingTopics = useMemo(() => {
@@ -204,18 +205,29 @@ const Search: React.FC<SearchProps> = ({onOpenChange, query, setQuery}) => {
204205
}, [query, shouldSearch, topicsData?.topics]);
205206

206207
useEffect(() => {
208+
if (!shouldSearch) {
209+
setDisplayResults([]);
210+
setLastResultState(null);
211+
return;
212+
}
213+
214+
if (!isFetched) {
215+
return;
216+
}
217+
207218
if (data?.accounts && data.accounts.length > 0) {
208219
setDisplayResults(data.accounts);
209-
} else if (!isFetching && shouldSearch) {
220+
setLastResultState('results');
221+
} else {
210222
setDisplayResults([]);
223+
setLastResultState('none');
211224
}
212-
}, [data?.accounts, isFetching, shouldSearch]);
225+
}, [data?.accounts, isFetched, shouldSearch]);
213226

214227
const showLoading = isFetching && shouldSearch;
215-
const hasAnyResults = matchingTopics.length > 0 || displayResults.length > 0;
216-
const showNoResults = !isFetching && isFetched && !hasAnyResults && shouldSearch && debouncedQuery === query;
217-
const showSuggested = query.length < 2 || (showLoading && !hasAnyResults);
218-
const showSearchResults = shouldSearch && hasAnyResults;
228+
const showSuggested = query.length < 2 || (!lastResultState && shouldSearch && matchingTopics.length === 0);
229+
const showNoResults = !showSuggested && lastResultState === 'none' && matchingTopics.length === 0;
230+
const showSearchResults = !showSuggested && (displayResults.length > 0 || matchingTopics.length > 0);
219231

220232
// Focus the query input on initial render
221233
useEffect(() => {

0 commit comments

Comments
 (0)