-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix Opened offline attachment directed to conversation page on online #49832
Merged
rlinoz
merged 34 commits into
Expensify:main
from
wildan-m:wildan/fix/48173-dismiss-when-no-attachment-with-same-page-index
Oct 3, 2024
Merged
Changes from 18 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
48af2f2
change attachment target to prevInitialPageRef when current viewed at…
wildan-m 6ece814
don't dismiss only when the prev attachment with the same initialPage…
wildan-m 19db64e
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m 34ba2c7
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m 2f21ca5
remove unnecessary code
wildan-m 67c1f2b
adjust comment
wildan-m f95d459
fix lint, replace deprecated withOnyx
wildan-m de935c4
implement for native
wildan-m ce69418
lint fix, replace deprecate withOnyx
wildan-m 613d8f3
typecheck fix
wildan-m f458e85
remove unused code
wildan-m 15ac1ed
Update src/components/Attachments/AttachmentCarousel/index.tsx
wildan-m b42d3cd
refactor
wildan-m 8ef2085
refactor for native
wildan-m e30a878
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m ed960b1
remove unnecessary comment
wildan-m ca1e6d5
access the array directly instead of checking -1 in index
wildan-m 4167773
adjust comment position
wildan-m 6741ab6
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m 3e2e8d4
resolve issue incorrect newIndex on onPageSelected event
wildan-m fbd028f
refine comment
wildan-m 9a844fa
refactor
wildan-m 3c10da9
fix issue attachment briefly changed before dismiss
wildan-m aaea3ba
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m 04d8e9f
Refactor
wildan-m 78a920e
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m d76d54d
revert pager key solution
wildan-m aebb27f
fix lint
wildan-m 8e34c56
fix lint
wildan-m 7bb7bb2
revert compare with -1 after new eslint rule
wildan-m eb33707
sync web code with native
wildan-m 2f7068a
-1 check for array access using .at
wildan-m f104033
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m 33cd212
Refine comment, add why point
wildan-m 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import type {ListRenderItemInfo} from 'react-native'; | |
import {Keyboard, PixelRatio, View} from 'react-native'; | ||
import type {GestureType} from 'react-native-gesture-handler'; | ||
import {Gesture, GestureDetector} from 'react-native-gesture-handler'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import Animated, {scrollTo, useAnimatedRef, useSharedValue} from 'react-native-reanimated'; | ||
import type {Attachment, AttachmentSource} from '@components/Attachments/types'; | ||
import BlockingView from '@components/BlockingViews/BlockingView'; | ||
|
@@ -26,7 +26,7 @@ import CarouselButtons from './CarouselButtons'; | |
import CarouselItem from './CarouselItem'; | ||
import extractAttachments from './extractAttachments'; | ||
import AttachmentCarouselPagerContext from './Pager/AttachmentCarouselPagerContext'; | ||
import type {AttachmentCaraouselOnyxProps, AttachmentCarouselProps, UpdatePageProps} from './types'; | ||
import type {AttachmentCarouselProps, UpdatePageProps} from './types'; | ||
import useCarouselArrows from './useCarouselArrows'; | ||
import useCarouselContextEvents from './useCarouselContextEvents'; | ||
|
||
|
@@ -38,7 +38,7 @@ const viewabilityConfig = { | |
|
||
const MIN_FLING_VELOCITY = 500; | ||
|
||
function AttachmentCarousel({report, reportActions, parentReportActions, source, onNavigate, setDownloadButtonVisibility, type, accountID, onClose}: AttachmentCarouselProps) { | ||
function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibility, type, accountID, onClose}: AttachmentCarouselProps) { | ||
const theme = useTheme(); | ||
const {translate} = useLocalize(); | ||
const {windowWidth} = useWindowDimensions(); | ||
|
@@ -48,7 +48,8 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source, | |
const scrollRef = useAnimatedRef<Animated.FlatList<ListRenderItemInfo<Attachment>>>(); | ||
const nope = useSharedValue(false); | ||
const pagerRef = useRef<GestureType>(null); | ||
|
||
const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, {canEvict: false}); | ||
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canEvict: false}); | ||
const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen(); | ||
|
||
const modalStyles = styles.centeredModalStyles(shouldUseNarrowLayout, true); | ||
|
@@ -88,23 +89,28 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source, | |
return; | ||
} | ||
|
||
const initialPage = targetAttachments.findIndex(compareImage); | ||
let attachmentIndex = targetAttachments.findIndex(compareImage); | ||
const prevAttachmentIndex = attachments.findIndex(compareImage); | ||
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. Can you do same refactor on the names on this file too 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. done |
||
|
||
// If no matching attachment with the same index, dismiss the modal | ||
rlinoz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!targetAttachments[attachmentIndex] && targetAttachments[prevAttachmentIndex]) { | ||
attachmentIndex = prevAttachmentIndex; | ||
} | ||
|
||
// Dismiss the modal when deleting an attachment during its display in preview. | ||
if (initialPage === -1 && attachments.find(compareImage)) { | ||
if (!targetAttachments[attachmentIndex] && attachments[prevAttachmentIndex]) { | ||
Navigation.dismissModal(); | ||
} else { | ||
setPage(initialPage); | ||
setPage(attachmentIndex); | ||
setAttachments(targetAttachments); | ||
|
||
// Update the download button visibility in the parent modal | ||
if (setDownloadButtonVisibility) { | ||
setDownloadButtonVisibility(initialPage !== -1); | ||
setDownloadButtonVisibility(attachmentIndex !== -1); | ||
} | ||
|
||
// Update the parent modal's state with the source and name from the mapped attachments | ||
if (targetAttachments[initialPage] !== undefined && onNavigate) { | ||
onNavigate(targetAttachments[initialPage]); | ||
if (targetAttachments[attachmentIndex] !== undefined && onNavigate) { | ||
onNavigate(targetAttachments[attachmentIndex]); | ||
} | ||
} | ||
}, [report.privateNotes, reportActions, parentReportActions, compareImage, report.parentReportActionID, attachments, setDownloadButtonVisibility, onNavigate, accountID, type]); | ||
|
@@ -306,13 +312,4 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source, | |
|
||
AttachmentCarousel.displayName = 'AttachmentCarousel'; | ||
|
||
export default withOnyx<AttachmentCarouselProps, AttachmentCaraouselOnyxProps>({ | ||
parentReportActions: { | ||
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, | ||
canEvict: false, | ||
}, | ||
reportActions: { | ||
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, | ||
canEvict: false, | ||
}, | ||
})(AttachmentCarousel); | ||
export default AttachmentCarousel; |
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.
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.
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.
NAB. Another naming clarity.
targetAttachments
is confusing.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.
done