Skip to content

Commit

Permalink
fix: show empty search view when search API return error
Browse files Browse the repository at this point in the history
  • Loading branch information
daledah committed Dec 12, 2024
1 parent dac90e1 commit d667407
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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 try 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 intenta 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

0 comments on commit d667407

Please sign in to comment.