From 26068ce5270ea724c875f5e2b377df5605e8f73c Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 19 Sep 2024 08:50:23 +0900 Subject: [PATCH 1/2] make search a write request --- src/libs/API/types.ts | 4 ++-- src/libs/Network/NetworkStore.ts | 4 ++-- src/libs/actions/Search.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 3c1348ed1c78..9b90d5020f5b 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -90,6 +90,7 @@ const WRITE_COMMANDS = { SIGN_IN_WITH_GOOGLE: 'SignInWithGoogle', SIGN_IN_USER: 'SigninUser', SIGN_IN_USER_WITH_LINK: 'SigninUserWithLink', + SEARCH: 'Search', REQUEST_UNLINK_VALIDATION_LINK: 'RequestUnlinkValidationLink', UNLINK_LOGIN: 'UnlinkLogin', ENABLE_TWO_FACTOR_AUTH: 'EnableTwoFactorAuth', @@ -626,6 +627,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.REMOVE_POLICY_CATEGORY_RECEIPTS_REQUIRED]: Parameters.RemovePolicyCategoryReceiptsRequiredParams; [WRITE_COMMANDS.SET_POLICY_CATEGORY_MAX_AMOUNT]: Parameters.SetPolicyCategoryMaxAmountParams; [WRITE_COMMANDS.SET_POLICY_CATEGORY_APPROVER]: Parameters.SetPolicyCategoryApproverParams; + [WRITE_COMMANDS.SEARCH]: Parameters.SearchParams; [WRITE_COMMANDS.SET_POLICY_CATEGORY_TAX]: Parameters.SetPolicyCategoryTaxParams; [WRITE_COMMANDS.JOIN_POLICY_VIA_INVITE_LINK]: Parameters.JoinPolicyInviteLinkParams; [WRITE_COMMANDS.ACCEPT_JOIN_REQUEST]: Parameters.AcceptJoinRequestParams; @@ -861,7 +863,6 @@ const READ_COMMANDS = { OPEN_POLICY_ACCOUNTING_PAGE: 'OpenPolicyAccountingPage', OPEN_POLICY_PROFILE_PAGE: 'OpenPolicyProfilePage', OPEN_POLICY_INITIAL_PAGE: 'OpenPolicyInitialPage', - SEARCH: 'Search', OPEN_SUBSCRIPTION_PAGE: 'OpenSubscriptionPage', OPEN_DRAFT_DISTANCE_EXPENSE: 'OpenDraftDistanceExpense', START_ISSUE_NEW_CARD_FLOW: 'StartIssueNewCardFlow', @@ -920,7 +921,6 @@ type ReadCommandParameters = { [READ_COMMANDS.OPEN_POLICY_EDIT_CARD_LIMIT_TYPE_PAGE]: Parameters.OpenPolicyEditCardLimitTypePageParams; [READ_COMMANDS.OPEN_POLICY_PROFILE_PAGE]: Parameters.OpenPolicyProfilePageParams; [READ_COMMANDS.OPEN_POLICY_INITIAL_PAGE]: Parameters.OpenPolicyInitialPageParams; - [READ_COMMANDS.SEARCH]: Parameters.SearchParams; [READ_COMMANDS.OPEN_SUBSCRIPTION_PAGE]: null; [READ_COMMANDS.OPEN_DRAFT_DISTANCE_EXPENSE]: null; [READ_COMMANDS.START_ISSUE_NEW_CARD_FLOW]: Parameters.StartIssueNewCardFlowParams; diff --git a/src/libs/Network/NetworkStore.ts b/src/libs/Network/NetworkStore.ts index 89b40e63834c..52a2bb8f488c 100644 --- a/src/libs/Network/NetworkStore.ts +++ b/src/libs/Network/NetworkStore.ts @@ -1,6 +1,6 @@ import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; -import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; +import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type Credentials from '@src/types/onyx/Credentials'; @@ -98,7 +98,7 @@ function getAuthToken(): string | null | undefined { } function isSupportRequest(command: string): boolean { - return [WRITE_COMMANDS.OPEN_APP, SIDE_EFFECT_REQUEST_COMMANDS.RECONNECT_APP, SIDE_EFFECT_REQUEST_COMMANDS.OPEN_REPORT, READ_COMMANDS.SEARCH].some((cmd) => cmd === command); + return [WRITE_COMMANDS.OPEN_APP, SIDE_EFFECT_REQUEST_COMMANDS.RECONNECT_APP, SIDE_EFFECT_REQUEST_COMMANDS.OPEN_REPORT, WRITE_COMMANDS.SEARCH].some((cmd) => cmd === command); } function isSupportAuthToken(): boolean { diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index a4f0e59ef976..c23103d45da1 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -5,7 +5,7 @@ import type {FormOnyxValues} from '@components/Form/types'; import type {SearchQueryJSON} from '@components/Search/types'; import * as API from '@libs/API'; import type {ExportSearchItemsToCSVParams} from '@libs/API/parameters'; -import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; +import {WRITE_COMMANDS} from '@libs/API/types'; import * as ApiUtils from '@libs/ApiUtils'; import fileDownload from '@libs/fileDownload'; import enhanceParameters from '@libs/Network/enhanceParameters'; @@ -71,7 +71,7 @@ function search({queryJSON, offset}: {queryJSON: SearchQueryJSON; offset?: numbe }; const jsonQuery = JSON.stringify(queryWithOffset); - API.read(READ_COMMANDS.SEARCH, {hash: queryJSON.hash, jsonQuery}, {optimisticData, finallyData}); + API.write(WRITE_COMMANDS.SEARCH, {hash: queryJSON.hash, jsonQuery}, {optimisticData, finallyData}); } /** From 41f34b4fbfcc44f8cfcbab39d4e86d5119469774 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 25 Sep 2024 09:51:55 +0900 Subject: [PATCH 2/2] fix style --- src/libs/Network/NetworkStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Network/NetworkStore.ts b/src/libs/Network/NetworkStore.ts index 51878a9cce5d..fe90aa87495e 100644 --- a/src/libs/Network/NetworkStore.ts +++ b/src/libs/Network/NetworkStore.ts @@ -1,6 +1,6 @@ import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; -import {SIDE_EFFECT_REQUEST_COMMANDS, READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; +import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type Credentials from '@src/types/onyx/Credentials';