Repository navigation
[TS migration] Migrate AttachmentCarousel to typescript #36658
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
Merged
puneetlath
merged 36 commits into
Expensify:main
from
software-mansion-labs:@szymczak/AttachmentCarousel
Mar 25, 2024
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
a9315c4
migrate AttachmentView
SzymczakJ 0f696ce
migrate AttachmentCarousel
SzymczakJ de7619a
migrate attachmentCarousel
SzymczakJ 4146104
Merge branch 'main' into @szymczak/AttachmentCarousel
SzymczakJ e8ab36f
fix merge bugs
SzymczakJ b46b1c0
clean up code
SzymczakJ ca34bcc
Merge branch 'main' into @szymczak/AttachmentCarousel
SzymczakJ b51d1c9
fix AttachmentView memo
SzymczakJ e6d06bf
fix PR comments
SzymczakJ eba12a9
Merge branch 'main' into @szymczak/AttachmentCarousel
SzymczakJ d60d76b
fix ts errors
SzymczakJ 5a29704
Merge branch 'main' into @szymczak/AttachmentCarousel
SzymczakJ 7560f8b
fix AttachmentView crash
SzymczakJ adbfc65
Merge branch 'main' into @szymczak/AttachmentCarousel
SzymczakJ ca76ff6
fix lint error
SzymczakJ f188c8c
merge main
SzymczakJ 7a9853a
fix type errors
SzymczakJ a8b03df
fix lint
SzymczakJ b7ad3e2
fix comments
SzymczakJ f51a489
fix comments
SzymczakJ d69d776
Merge branch 'main' into @szymczak/AttachmentCarousel
SzymczakJ 8c8ddf3
fix pr comments
SzymczakJ d746b6c
fix pr comments
SzymczakJ 1f71572
fix PR comments
SzymczakJ eaef7fb
fix pr comments
SzymczakJ 8629609
fix pr comments
SzymczakJ 7c9015b
fix Pr commments
SzymczakJ 7805777
fix PR comments
SzymczakJ 8a5c9c5
fix type error
SzymczakJ efbdf5c
fix pr comments
SzymczakJ b8d4a61
fix type errors
SzymczakJ b63dcdc
Merge branch 'main' into @szymczak/AttachmentCarousel
SzymczakJ ad79213
Merge branch 'main' into @szymczak/AttachmentCarousel
SzymczakJ 40a3688
Merge branch 'main' into @szymczak/AttachmentCarousel
SzymczakJ 0844b82
fi pr comments
SzymczakJ f5a6712
Merge branch 'main' into @szymczak/AttachmentCarousel
SzymczakJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import PropTypes from 'prop-types'; | ||
| import React, {useContext, useState} from 'react'; | ||
| import type {StyleProp, ViewStyle} from 'react-native'; | ||
| import {View} from 'react-native'; | ||
| import AttachmentView from '@components/Attachments/AttachmentView'; | ||
| import * as AttachmentsPropTypes from '@components/Attachments/propTypes'; | ||
| import type {Attachment} from '@components/Attachments/types'; | ||
| import Button from '@components/Button'; | ||
| import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback'; | ||
| import SafeAreaConsumer from '@components/SafeAreaConsumer'; | ||
|
|
@@ -12,55 +12,27 @@ import useThemeStyles from '@hooks/useThemeStyles'; | |
| import ReportAttachmentsContext from '@pages/home/report/ReportAttachmentsContext'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| const propTypes = { | ||
| type CarouselItemProps = { | ||
| /** Attachment required information such as the source and file name */ | ||
| item: PropTypes.shape({ | ||
| /** Report action ID of the attachment */ | ||
| reportActionID: PropTypes.string, | ||
|
|
||
| /** Whether source URL requires authentication */ | ||
| isAuthTokenRequired: PropTypes.bool, | ||
|
|
||
| /** URL to full-sized attachment or SVG function */ | ||
| source: AttachmentsPropTypes.attachmentSourcePropType.isRequired, | ||
|
|
||
| /** Additional information about the attachment file */ | ||
| file: PropTypes.shape({ | ||
| /** File name of the attachment */ | ||
| name: PropTypes.string.isRequired, | ||
| }).isRequired, | ||
|
|
||
| /** Whether the attachment has been flagged */ | ||
| hasBeenFlagged: PropTypes.bool, | ||
|
|
||
| /** The id of the transaction related to the attachment */ | ||
| transactionID: PropTypes.string, | ||
|
|
||
| duration: PropTypes.number, | ||
| }).isRequired, | ||
| item: Attachment; | ||
|
|
||
| /** onPress callback */ | ||
| onPress: PropTypes.func, | ||
| onPress?: () => void; | ||
|
|
||
| isModalHovered: PropTypes.bool, | ||
| /** Whether attachment carousel modal is hovered over */ | ||
| isModalHovered?: boolean; | ||
|
SzymczakJ marked this conversation as resolved.
Resolved
|
||
|
|
||
| /** Whether the attachment is currently being viewed in the carousel */ | ||
| isFocused: PropTypes.bool.isRequired, | ||
| }; | ||
|
|
||
| const defaultProps = { | ||
| onPress: undefined, | ||
| isModalHovered: false, | ||
| isFocused: boolean; | ||
| }; | ||
|
|
||
| function CarouselItem({item, onPress, isFocused, isModalHovered}) { | ||
| function CarouselItem({item, onPress, isFocused, isModalHovered}: CarouselItemProps) { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const {isAttachmentHidden} = useContext(ReportAttachmentsContext); | ||
| // eslint-disable-next-line es/no-nullish-coalescing-operators | ||
| const [isHidden, setIsHidden] = useState(() => isAttachmentHidden(item.reportActionID) ?? item.hasBeenFlagged); | ||
| const [isHidden, setIsHidden] = useState(() => (item.reportActionID ? isAttachmentHidden(item.reportActionID) : item.hasBeenFlagged)); | ||
|
Contributor
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. This change has caused a regression in #58912, we should fall back to |
||
|
|
||
| const renderButton = (style) => ( | ||
| const renderButton = (style: StyleProp<ViewStyle>) => ( | ||
| <Button | ||
| small | ||
| style={style} | ||
|
|
@@ -87,7 +59,8 @@ function CarouselItem({item, onPress, isFocused, isModalHovered}) { | |
| style={[styles.attachmentRevealButtonContainer]} | ||
| onPress={onPress} | ||
| accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON} | ||
| accessibilityLabel={item.file.name || translate('attachmentView.unknownFilename')} | ||
| // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
| accessibilityLabel={item.file?.name || translate('attachmentView.unknownFilename')} | ||
| > | ||
| {children} | ||
| </PressableWithoutFeedback> | ||
|
|
@@ -108,7 +81,7 @@ function CarouselItem({item, onPress, isFocused, isModalHovered}) { | |
| reportActionID={item.reportActionID} | ||
| isHovered={isModalHovered} | ||
| isFocused={isFocused} | ||
| optionalVideoDuration={item.duration} | ||
| duration={item.duration} | ||
| /> | ||
| </View> | ||
|
|
||
|
|
@@ -121,8 +94,6 @@ function CarouselItem({item, onPress, isFocused, isModalHovered}) { | |
| ); | ||
| } | ||
|
|
||
| CarouselItem.propTypes = propTypes; | ||
| CarouselItem.defaultProps = defaultProps; | ||
| CarouselItem.displayName = 'CarouselItem'; | ||
|
|
||
| export default CarouselItem; | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.