Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show empty search view when search API return error #54007

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4536,7 +4536,7 @@ const translations = {
searchResults: {
emptyResults: {
title: 'Nothing to show',
subtitle: 'Try creating something with the green + button.',
subtitle: 'Try adjusting your search criteria or creating something with the green + button.',
},
emptyExpenseResults: {
title: "You haven't created any expenses yet",
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4585,7 +4585,7 @@ const translations = {
searchResults: {
emptyResults: {
title: 'No hay nada que ver aquí',
subtitle: 'Por favor intenta crear algo con el botón verde.',
subtitle: 'Intenta ajustar tus criterios de búsqueda o crear algo con el botón verde +.',
},
emptyExpenseResults: {
title: 'Aún no has creado ningún gasto',
Expand Down
22 changes: 18 additions & 4 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function getPayActionCallback(hash: number, item: TransactionListItemType | Repo
goToItem();
}

function getOnyxLoadingData(hash: number): {optimisticData: OnyxUpdate[]; finallyData: OnyxUpdate[]} {
function getOnyxLoadingData(hash: number, queryJSON?: SearchQueryJSON): {optimisticData: OnyxUpdate[]; finallyData: OnyxUpdate[]; failureData: OnyxUpdate[]} {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -120,7 +120,21 @@ function getOnyxLoadingData(hash: number): {optimisticData: OnyxUpdate[]; finall
},
];

return {optimisticData, finallyData};
const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`,
value: {
data: [],
search: {
status: queryJSON?.status,
type: queryJSON?.type,
},
},
},
];

return {optimisticData, finallyData, failureData};
}

function saveSearch({queryJSON, newName}: {queryJSON: SearchQueryJSON; newName?: string}) {
Expand Down Expand Up @@ -202,15 +216,15 @@ function deleteSavedSearch(hash: number) {
}

function search({queryJSON, offset}: {queryJSON: SearchQueryJSON; offset?: number}) {
const {optimisticData, finallyData} = getOnyxLoadingData(queryJSON.hash);
const {optimisticData, finallyData, failureData} = getOnyxLoadingData(queryJSON.hash, queryJSON);
const {flatFilters, ...queryJSONWithoutFlatFilters} = queryJSON;
const queryWithOffset = {
...queryJSONWithoutFlatFilters,
offset,
};
const jsonQuery = JSON.stringify(queryWithOffset);

API.write(WRITE_COMMANDS.SEARCH, {hash: queryJSON.hash, jsonQuery}, {optimisticData, finallyData});
API.write(WRITE_COMMANDS.SEARCH, {hash: queryJSON.hash, jsonQuery}, {optimisticData, finallyData, failureData});
}

/**
Expand Down
Loading