-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37281 from callstack-internal/audit/implementatio…
…n/hasDraft-replacement [Audit][Implementation] hasDraft replacement
- Loading branch information
Showing
25 changed files
with
134 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; | ||
import Onyx from 'react-native-onyx'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
let draftCommentCollection: OnyxCollection<string> = {}; | ||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, | ||
callback: (nextVal) => { | ||
draftCommentCollection = nextVal; | ||
}, | ||
waitForCollectionCallback: true, | ||
}); | ||
|
||
/** | ||
* Returns a draft comment from the onyx collection for given reportID. | ||
* Note: You should use the HOCs/hooks to get onyx data, instead of using this directly. | ||
* A valid use-case of this function is outside React components, like in utility functions. | ||
*/ | ||
function getDraftComment(reportID: string): OnyxEntry<string> | null | undefined { | ||
return draftCommentCollection?.[ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT + reportID]; | ||
} | ||
|
||
/** | ||
* Returns true if the report has a valid draft comment. | ||
* A valid draft comment is a non-empty string. | ||
*/ | ||
function isValidDraftComment(comment?: string | null): boolean { | ||
return !!comment?.trim(); | ||
} | ||
|
||
/** | ||
* Returns true if the report has a valid draft comment. | ||
*/ | ||
function hasValidDraftComment(reportID: string): boolean { | ||
return isValidDraftComment(getDraftComment(reportID)); | ||
} | ||
|
||
/** | ||
* Prepares a draft comment by trimming it and returning null if it's empty. | ||
*/ | ||
function prepareDraftComment(comment: string | null) { | ||
// logical OR is used to convert empty string to null | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
return comment?.trim() || null; | ||
} | ||
|
||
export {getDraftComment, isValidDraftComment, hasValidDraftComment, prepareDraftComment}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.