From 4de23c36c4b45d859d8de6a2e40d232c1d301123 Mon Sep 17 00:00:00 2001 From: Aswin S Date: Tue, 20 Feb 2024 03:47:44 +0530 Subject: [PATCH 1/3] bump expensify-commons version --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index c366a2ccdca3..4a21c9c248d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,7 +52,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#a8ed0f8e1be3a1e09016e07a74cfd13c85bbc167", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#83ae6194b3e4feb363ea9d061085a7ab76e35ffb", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.10.1", @@ -31239,8 +31239,8 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#a8ed0f8e1be3a1e09016e07a74cfd13c85bbc167", - "integrity": "sha512-3d/JHWgeS+LFPRahCAXdLwnBYQk4XUYybtgCm7VsdmMDtCeGUTksLsEY7F1Zqm+ULqZjmCtYwAi8IPKy0fsSOw==", + "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#83ae6194b3e4feb363ea9d061085a7ab76e35ffb", + "integrity": "sha512-nAe0fPbfRn/VYHe6mCp/APmMbda/NiHE3aZq7q0kWhPmz1LVTukeaREmZ7SN8auyLOy9/mS0RIQLeV0AR8vsrA==", "license": "MIT", "dependencies": { "classnames": "2.4.0", diff --git a/package.json b/package.json index 887210b5f9bf..9defcf24ffbd 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#a8ed0f8e1be3a1e09016e07a74cfd13c85bbc167", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#83ae6194b3e4feb363ea9d061085a7ab76e35ffb", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.10.1", From 1a91eaa68dac0cedd6c4cca2983a783f57c5b014 Mon Sep 17 00:00:00 2001 From: Aswin S Date: Tue, 20 Feb 2024 03:59:47 +0530 Subject: [PATCH 2/3] fix: memoize task desciption default value --- src/pages/tasks/NewTaskDescriptionPage.js | 5 +++-- src/pages/tasks/NewTaskDetailsPage.js | 12 +++++++++--- src/pages/tasks/TaskDescriptionPage.js | 5 +++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pages/tasks/NewTaskDescriptionPage.js b/src/pages/tasks/NewTaskDescriptionPage.js index dbcb10d47f39..db02a99db067 100644 --- a/src/pages/tasks/NewTaskDescriptionPage.js +++ b/src/pages/tasks/NewTaskDescriptionPage.js @@ -1,6 +1,6 @@ import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import PropTypes from 'prop-types'; -import React from 'react'; +import React, {useMemo} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; @@ -42,6 +42,7 @@ const parser = new ExpensiMark(); function NewTaskDescriptionPage(props) { const styles = useThemeStyles(); const {inputCallbackRef} = useAutoFocusInput(); + const defaultDescriptionValue = useMemo(() => parser.htmlToMarkdown(parser.replace(props.task.description)), [props.task.description]); const onSubmit = (values) => { Task.setDescriptionValue(values.taskDescription); @@ -85,7 +86,7 @@ function NewTaskDescriptionPage(props) { parser.htmlToMarkdown(parser.replace(taskDescription)), [taskDescription]); useEffect(() => { + if (!isFocused) { + return; + } setTaskTitle(props.task.title); setTaskDescription(parser.htmlToMarkdown(parser.replace(props.task.description || ''))); - }, [props.task]); + }, [isFocused, props.task.title, props.task.description]); /** * @param {Object} values - form input values passed by the Form component @@ -118,7 +124,7 @@ function NewTaskDetailsPage(props) { autoGrowHeight shouldSubmitForm containerStyles={[styles.autoGrowHeightMultilineInput]} - defaultValue={parser.htmlToMarkdown(parser.replace(taskDescription))} + defaultValue={defaultDescriptionValue} value={taskDescription} onValueChange={(value) => setTaskDescription(value)} /> diff --git a/src/pages/tasks/TaskDescriptionPage.js b/src/pages/tasks/TaskDescriptionPage.js index b8b48abd09ff..23a52384af6d 100644 --- a/src/pages/tasks/TaskDescriptionPage.js +++ b/src/pages/tasks/TaskDescriptionPage.js @@ -1,6 +1,6 @@ import {useFocusEffect} from '@react-navigation/native'; import ExpensiMark from 'expensify-common/lib/ExpensiMark'; -import React, {useCallback, useRef} from 'react'; +import React, {useCallback, useMemo, useRef} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; @@ -80,6 +80,7 @@ function TaskDescriptionPage(props) { const isOpen = ReportUtils.isOpenTaskReport(props.report); const canModifyTask = Task.canModifyTask(props.report, props.currentUserPersonalDetails.accountID); const isTaskNonEditable = ReportUtils.isTaskReport(props.report) && (!canModifyTask || !isOpen); + const defaultDescriptionValue = useMemo(() => parser.htmlToMarkdown((props.report && parser.replace(props.report.description)) || ''), [props.report]); useFocusEffect( useCallback(() => { @@ -121,7 +122,7 @@ function TaskDescriptionPage(props) { name={INPUT_IDS.DESCRIPTION} label={props.translate('newTaskPage.descriptionOptional')} accessibilityLabel={props.translate('newTaskPage.descriptionOptional')} - defaultValue={parser.htmlToMarkdown((props.report && parser.replace(props.report.description)) || '')} + defaultValue={defaultDescriptionValue} ref={(el) => { if (!el) { return; From e100285e59a85b939446ccfd57d229fd19b4d699 Mon Sep 17 00:00:00 2001 From: Aswin S Date: Thu, 22 Feb 2024 07:58:06 +0530 Subject: [PATCH 3/3] fix: remove isFocused check --- src/pages/tasks/NewTaskDetailsPage.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/pages/tasks/NewTaskDetailsPage.js b/src/pages/tasks/NewTaskDetailsPage.js index bc03cc860692..796fbed77d18 100644 --- a/src/pages/tasks/NewTaskDetailsPage.js +++ b/src/pages/tasks/NewTaskDetailsPage.js @@ -1,4 +1,3 @@ -import {useIsFocused} from '@react-navigation/native'; import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import PropTypes from 'prop-types'; import React, {useEffect, useMemo, useState} from 'react'; @@ -39,7 +38,6 @@ const parser = new ExpensiMark(); function NewTaskDetailsPage(props) { const styles = useThemeStyles(); - const isFocused = useIsFocused(); const [taskTitle, setTaskTitle] = useState(props.task.title); const [taskDescription, setTaskDescription] = useState(props.task.description || ''); @@ -47,12 +45,9 @@ function NewTaskDetailsPage(props) { const defaultDescriptionValue = useMemo(() => parser.htmlToMarkdown(parser.replace(taskDescription)), [taskDescription]); useEffect(() => { - if (!isFocused) { - return; - } setTaskTitle(props.task.title); setTaskDescription(parser.htmlToMarkdown(parser.replace(props.task.description || ''))); - }, [isFocused, props.task.title, props.task.description]); + }, [props.task.title, props.task.description]); /** * @param {Object} values - form input values passed by the Form component