-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix attachment modal for broken images #61459
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
mountiny
merged 9 commits into
Expensify:main
from
software-mansion-labs:korytko/broken-video-attachment-fix
May 14, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a4f9ae0
Remove attachment download button on broken ones
JakubKorytko a9d76db
Fix code according to Blazej comments
JakubKorytko 8d947b1
Merge branch 'main' into korytko/broken-video-attachment-fix
JakubKorytko 1c360aa
Change logic related to context values manipulation
JakubKorytko 7722b98
Correct unknown source handling
JakubKorytko dd13cca
Merge branch 'main' into korytko/broken-video-attachment-fix
JakubKorytko a897042
Merge branch 'main' into korytko/broken-video-attachment-fix
JakubKorytko ff9a59e
Move onAttachmentError to useEffect
JakubKorytko 56ded50
Merge branch 'main' into korytko/broken-video-attachment-fix
JakubKorytko 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
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
48 changes: 48 additions & 0 deletions
48
src/components/Attachments/AttachmentView/useAttachmentErrors.ts
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {useCallback, useState} from 'react'; | ||
import type {AttachmentSource} from '@components/Attachments/types'; | ||
|
||
function convertSourceToString(source: AttachmentSource) { | ||
if (typeof source === 'string' || typeof source === 'number') { | ||
return source.toString(); | ||
} | ||
if (source instanceof Array) { | ||
return source.map((src) => src.uri).join(', '); | ||
} | ||
if ('uri' in source) { | ||
return source.uri ?? ''; | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
/** | ||
* A custom React hook that provides functionalities to manage attachment errors. | ||
* - `setAttachmentError(key)`: Sets or unsets an error for a given key. | ||
* - `clearAttachmentErrors()`: Clears all errors. | ||
* - `isErrorInAttachment(key)`: Checks if there is an error associated with a specific key. | ||
* Errors are indexed by a serialized key - for example url or source object. | ||
*/ | ||
function useAttachmentErrors() { | ||
const [attachmentErrors, setAttachmentErrors] = useState<Record<string, boolean>>({}); | ||
|
||
const setAttachmentError = useCallback((key: AttachmentSource, state = true) => { | ||
const url = convertSourceToString(key); | ||
if (!url) { | ||
return; | ||
} | ||
setAttachmentErrors((prevState) => ({ | ||
...prevState, | ||
[url]: state, | ||
})); | ||
}, []); | ||
|
||
const clearAttachmentErrors = useCallback(() => { | ||
setAttachmentErrors({}); | ||
}, []); | ||
|
||
const isErrorInAttachment = useCallback((key: AttachmentSource) => attachmentErrors?.[convertSourceToString(key)], [attachmentErrors]); | ||
|
||
return {setAttachmentError, clearAttachmentErrors, isErrorInAttachment}; | ||
} | ||
|
||
export default useAttachmentErrors; |
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.