Skip to content

Commit

Permalink
add loading indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Nov 8, 2024
1 parent a321c54 commit 8d2222f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/components/SelectionList/Search/ActionCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ type ActionCellProps = {
goToItem: () => void;
isChildListItem?: boolean;
parentAction?: string;
isLoading?: boolean;
};

function ActionCell({action = CONST.SEARCH.ACTION_TYPES.VIEW, isLargeScreenWidth = true, isSelected = false, goToItem, isChildListItem = false, parentAction = ''}: ActionCellProps) {
function ActionCell({
action = CONST.SEARCH.ACTION_TYPES.VIEW,
isLargeScreenWidth = true,
isSelected = false,
goToItem,
isChildListItem = false,
parentAction = '',
isLoading = false,
}: ActionCellProps) {
const {translate} = useLocalize();
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -87,6 +96,7 @@ function ActionCell({action = CONST.SEARCH.ACTION_TYPES.VIEW, isLargeScreenWidth
small
style={[styles.w100]}
innerStyles={buttonInnerStyles}
isLoading={isLoading}
success
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ExpenseItemHeaderNarrowProps = {
isDisabled?: boolean | null;
isDisabledCheckbox?: boolean;
handleCheckboxPress?: () => void;
isLoading?: boolean;
};

function ExpenseItemHeaderNarrow({
Expand All @@ -44,6 +45,7 @@ function ExpenseItemHeaderNarrow({
isDisabled,
handleCheckboxPress,
text,
isLoading = false,
}: ExpenseItemHeaderNarrowProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down Expand Up @@ -102,6 +104,7 @@ function ExpenseItemHeaderNarrow({
goToItem={onButtonPress}
isLargeScreenWidth={false}
isSelected={isSelected}
isLoading={isLoading}
/>
</View>
</View>
Expand Down
1 change: 1 addition & 0 deletions src/components/SelectionList/Search/ReportListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ function ReportListItem<TItem extends ListItem>({
action={reportItem.action}
goToItem={handleOnButtonPress}
isSelected={item.isSelected}
isLoading={reportItem.isActionLoading}
/>
</View>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function TransactionListItem<TItem extends ListItem>({
canSelectMultiple={!!canSelectMultiple}
isButtonSelected={item.isSelected}
shouldShowTransactionCheckbox={false}
isLoading={false}
/>
</BaseListItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type TransactionListItemRowProps = {
isButtonSelected?: boolean;
parentAction?: string;
shouldShowTransactionCheckbox?: boolean;
isLoading?: boolean;
};

const getTypeIcon = (type?: SearchTransactionType) => {
Expand Down Expand Up @@ -257,6 +258,7 @@ function TransactionListItemRow({
isButtonSelected = false,
parentAction = '',
shouldShowTransactionCheckbox,
isLoading = false,
}: TransactionListItemRowProps) {
const styles = useThemeStyles();
const {isLargeScreenWidth} = useResponsiveLayout();
Expand Down Expand Up @@ -445,6 +447,7 @@ function TransactionListItemRow({
isChildListItem={isChildListItem}
parentAction={parentAction}
goToItem={onButtonPress}
isLoading={isLoading}
/>
</View>
</View>
Expand Down
15 changes: 13 additions & 2 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import FILTER_KEYS from '@src/types/form/SearchAdvancedFiltersForm';
import type {LastPaymentMethod} from '@src/types/onyx';
import type {SearchTransaction} from '@src/types/onyx/SearchResults';
import type {SearchReport, SearchTransaction} from '@src/types/onyx/SearchResults';
import * as Report from './Report';

let currentUserEmail: string;
Expand Down Expand Up @@ -189,7 +189,18 @@ function holdMoneyRequestOnSearch(hash: number, transactionIDList: string[], com
}

function approveMoneyRequestOnSearch(hash: number, reportIDList: string[]) {
const {optimisticData, finallyData} = getOnyxLoadingData(hash);
const createOnyxLoadingData = (isLoading: boolean): OnyxUpdate[] => [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`,
value: {
data: Object.fromEntries(reportIDList.map((reportID) => [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {isActionLoading: isLoading}])) as Partial<SearchReport>,
},
},
];

const optimisticData: OnyxUpdate[] = createOnyxLoadingData(true);
const finallyData: OnyxUpdate[] = createOnyxLoadingData(false);

API.write(WRITE_COMMANDS.APPROVE_MONEY_REQUEST_ON_SEARCH, {hash, reportIDList}, {optimisticData, finallyData});
}
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/SearchResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ type SearchReport = {
/** Whether the report is archived */
// eslint-disable-next-line @typescript-eslint/naming-convention
private_isArchived?: string;

/** Whether the action is loading */
isActionLoading?: boolean;
};

/** Model of report action search result */
Expand Down

0 comments on commit 8d2222f

Please sign in to comment.