From d6674075f134d77e9137a85b8c5f5d31679d771a Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 12 Dec 2024 11:47:10 +0700 Subject: [PATCH] fix: show empty search view when search API return error --- src/languages/en.ts | 2 +- src/languages/es.ts | 2 +- src/libs/actions/Search.ts | 22 ++++++++++++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 7088d9df8a51..551224805e09 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -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 try creating something with the green + button.', }, emptyExpenseResults: { title: "You haven't created any expenses yet", diff --git a/src/languages/es.ts b/src/languages/es.ts index 47e11bf716ac..40f9370089a1 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -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 intenta crear algo con el botón verde.', }, emptyExpenseResults: { title: 'Aún no has creado ningún gasto', diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index c08a83088180..390b7428ee00 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -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, @@ -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}) { @@ -202,7 +216,7 @@ 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, @@ -210,7 +224,7 @@ function search({queryJSON, offset}: {queryJSON: SearchQueryJSON; offset?: numbe }; 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}); } /**