-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance: chat input #25758
Performance: chat input #25758
Changes from all commits
17d4889
91b7d91
9f1cac2
12405c3
0cab4a4
9a8201b
ea26c2c
b002f08
5042b4b
1bf0177
3ab1ca4
9ec7169
cfc7b25
e7d3a95
1156d61
eb2892c
a7a489a
e247161
9739c08
eb9baf8
6673ba4
730f4c9
b846cbe
33b8e4b
45a8842
ba38175
433d616
3e957a3
74bd410
ff18a4f
575046d
cdefcc6
e820194
dca3df8
7f73769
1a5454f
0bfc0b7
3d4403e
ad4b571
3ee30c9
557c8d0
3f591e2
52fc6e8
040688c
ef17bab
7edceee
0b5f770
5b9336d
b175eae
46a252a
5b61e12
af6d104
45947dd
eaa3440
1641dc0
d76106b
f174b04
066f980
8b2c37f
baa5e8b
893b7e2
6870d17
f1398ce
ea6f00b
905c9b5
10c55b3
f4b9079
448d358
4968fb1
a3ea498
7081e15
91d210c
8596920
9d05dab
0b987fa
8e8d5c4
6a7b82e
c02fdac
72e2bbf
cf5d835
ebd8e74
28426ce
95a0193
3e3c6ed
cf6cf7a
6ab1ccf
0dd4773
b4936ec
f2f397e
c3792d6
9826f49
9b7c07b
893137a
faf1e15
ad30918
bd22c57
5e93ecf
1e97af0
0ccd7ae
89b569d
e64a5d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import _ from 'underscore'; | ||
import * as Report from '../actions/Report'; | ||
|
||
/** | ||
* Save draft report comment. Debounced to happen at most once per second. | ||
* @param {String} reportID | ||
* @param {String} comment | ||
*/ | ||
const debouncedSaveReportComment = _.debounce((reportID, comment) => { | ||
Report.saveReportComment(reportID, comment || ''); | ||
}, 1000); | ||
|
||
export default debouncedSaveReportComment; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
|
||
const draftCommentMap = {}; | ||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, | ||
callback: (value, key) => { | ||
if (!key) return; | ||
|
||
const reportID = key.replace(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, ''); | ||
draftCommentMap[reportID] = value; | ||
}, | ||
}); | ||
|
||
/** | ||
* Returns a draft comment from the onyx collection. | ||
* Note: You should use the HOCs/hooks to get onyx data, instead of using this directly. | ||
* A valid use case to use this is if the value is only needed once for an initial value. | ||
* @param {String} reportID | ||
* @returns {String|undefined} | ||
*/ | ||
export default function getDraftComment(reportID) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we using onyx connect to get initial draft value? Why not just use the HOC? Is this some optimization to get all draft comments for all reports on app start? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to explain this in the comment above. The use case here is, that we only need the value for the initial value of a state variable. If we'd use the HOC the component would re-render every time the value (draft comment) changes, which is something we specifically want to avoid for performance reasons. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue was discussed here: https://expensify.slack.com/archives/C01GTK53T8Q/p1692620941376059 |
||
return draftCommentMap[reportID]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import CONST from '../CONST'; | ||
|
||
/** | ||
* Return the max available index for arrow manager. | ||
* @param {Number} numRows | ||
* @param {Boolean} isAutoSuggestionPickerLarge | ||
* @returns {Number} | ||
*/ | ||
function getMaxArrowIndex(numRows, isAutoSuggestionPickerLarge) { | ||
// rowCount is number of emoji/mention suggestions. For small screen we can fit 3 items | ||
// and for large we show up to 20 items for mentions/emojis | ||
const rowCount = isAutoSuggestionPickerLarge | ||
? Math.min(numRows, CONST.AUTO_COMPLETE_SUGGESTER.MAX_AMOUNT_OF_SUGGESTIONS) | ||
: Math.min(numRows, CONST.AUTO_COMPLETE_SUGGESTER.MIN_AMOUNT_OF_SUGGESTIONS); | ||
|
||
// -1 because we start at 0 | ||
return rowCount - 1; | ||
} | ||
|
||
/** | ||
* Trims first character of the string if it is a space | ||
* @param {String} str | ||
* @returns {String} | ||
*/ | ||
function trimLeadingSpace(str) { | ||
return str.slice(0, 1) === ' ' ? str.slice(1) : str; | ||
} | ||
|
||
export {getMaxArrowIndex, trimLeadingSpace}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import ONYXKEYS from '../ONYXKEYS'; | ||
|
||
let modalState = {}; | ||
|
||
Onyx.connect({ | ||
key: ONYXKEYS.MODAL, | ||
callback: (val) => { | ||
modalState = val; | ||
}, | ||
}); | ||
|
||
/** | ||
* Returns the modal state from onyx. | ||
* Note: You should use the HOCs/hooks to get onyx data, instead of using this directly. | ||
* A valid use case to use this is if the value is only needed once for an initial value. | ||
* @returns {Object} | ||
*/ | ||
export default function getModalState() { | ||
return modalState; | ||
hannojg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caused a regression of showing draft icon - more information here - #27362 (comment)