Skip to content

Commit

Permalink
Memorize functions, fix types and rename variable
Browse files Browse the repository at this point in the history
  • Loading branch information
s77rt committed Jun 4, 2024
1 parent 1d5f83d commit 0c56310
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ type SettingsNavigatorParamList = {

type NewChatNavigatorParamList = {
[SCREENS.NEW_CHAT.ROOT]: undefined;
[SCREENS.NEW_CHAT.NEW_CHAT_CONFIRM]: undefined;
[SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME]: undefined;
};

Expand Down
39 changes: 21 additions & 18 deletions src/pages/NewChatConfirmPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useMemo, useRef} from 'react';
import React, {useCallback, useMemo, useRef} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -35,6 +35,14 @@ type NewChatConfirmPageOnyxProps = {

type NewChatConfirmPageProps = NewChatConfirmPageOnyxProps;

function navigateBack() {
Navigation.goBack(ROUTES.NEW_CHAT);
}

function navigateToEditChatName() {
Navigation.navigate(ROUTES.NEW_CHAT_EDIT_NAME);
}

function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmPageProps) {
const optimisticReportID = useRef<string>(ReportUtils.generateReportID());
const fileRef = useRef<File | CustomRNImageManipulatorResult | undefined>();
Expand Down Expand Up @@ -79,30 +87,25 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
/**
* Removes a selected option from list if already selected.
*/
const unselectOption = (option: ListItem) => {
if (!newGroupDraft) {
return;
}
const newSelectedParticipants = (newGroupDraft.participants ?? []).filter((participant) => participant.login !== option.login);
Report.setGroupDraft({participants: newSelectedParticipants});
};
const unselectOption = useCallback(
(option: ListItem) => {
if (!newGroupDraft) {
return;
}
const newSelectedParticipants = (newGroupDraft.participants ?? []).filter((participant) => participant.login !== option.login);
Report.setGroupDraft({participants: newSelectedParticipants});
},
[newGroupDraft],
);

const createGroup = () => {
const createGroup = useCallback(() => {
if (!newGroupDraft) {
return;
}

const logins: string[] = (newGroupDraft.participants ?? []).map((participant) => participant.login);
Report.navigateToAndOpenReport(logins, true, newGroupDraft.reportName ?? '', newGroupDraft.avatarUri ?? '', fileRef.current, optimisticReportID.current, true);
};

const navigateBack = () => {
Navigation.goBack(ROUTES.NEW_CHAT);
};

const navigateToEditChatName = () => {
Navigation.navigate(ROUTES.NEW_CHAT_EDIT_NAME);
};
}, [newGroupDraft]);

const stashedLocalAvatarImage = newGroupDraft?.avatarUri;
return (
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
/>
) : null;

const renderAvatar = useMemo(() => {
const renderedAvatar = useMemo(() => {
if (isMoneyRequestReport || isInvoiceReport) {
return (
<View style={styles.mb3}>
Expand Down Expand Up @@ -318,7 +318,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
/>
<ScrollView style={[styles.flex1]}>
<View style={styles.reportDetailsTitleContainer}>
{renderAvatar}
{renderedAvatar}
<View style={[styles.reportDetailsRoomInfo, styles.mw100]}>
<View style={[styles.alignSelfCenter, styles.w100, styles.mt1]}>
<DisplayNames
Expand Down

0 comments on commit 0c56310

Please sign in to comment.