Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function RecipientListEdit({
searchMinLength,
handleSearchInputChange,
handleSearchInputKeyUp,
resetSearchValue,
} = useSearchRecipients({
recipientType,
});
Expand Down Expand Up @@ -183,6 +184,7 @@ export function RecipientListEdit({
setLoadingBookmarkIndex(index);
await handleSelectRecipient(recipient);
setLoadingBookmarkIndex(undefined);
resetSearchValue();
Comment on lines 185 to +187
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleRecipientClick updates loadingBookmarkIndex (and now resets the search) only on the success path. If handleSelectRecipient() rejects (e.g., getBookmarkById query fails), loadingBookmarkIndex will stay set and the error will be unhandled. Wrap the await in try/catch/finally so the loading state is always cleared, and decide whether resetSearchValue() should run only on success.

Suggested change
await handleSelectRecipient(recipient);
setLoadingBookmarkIndex(undefined);
resetSearchValue();
try {
await handleSelectRecipient(recipient);
resetSearchValue();
} catch (error) {
// eslint-disable-next-line no-console
console.error('Failed to select recipient', error);
} finally {
setLoadingBookmarkIndex(undefined);
}

Copilot uses AI. Check for mistakes.
};
return (
<Fragment key={index}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type State = {
};

type Action =
| { type: 'resetSearch' }
| { type: 'onChange'; payload: string }
| { type: 'isSearching'; payload: boolean }
| { type: 'addResult'; payload: OptionListItemType[] }
Expand All @@ -29,6 +30,13 @@ const initialState = {

function reducer(state: State, action: Action) {
switch (action.type) {
case 'resetSearch':
return {
...state,
searchInputValue: '',
searchResults: [],
searchAPIResults: [],
};
case 'onChange':
return { ...state, searchInputValue: action.payload };
case 'isSearching':
Expand Down Expand Up @@ -138,6 +146,12 @@ export const useSearchRecipients = ({
});
};

const resetSearchValue = () => {
dispatch({
type: 'resetSearch',
});
};

const searchMinLength = 1;

const hasSearchNoResults =
Expand All @@ -153,5 +167,6 @@ export const useSearchRecipients = ({
hasSearchNoResults,
handleSearchInputChange,
handleSearchInputKeyUp,
resetSearchValue,
};
};
Loading