From 75119ef7bae1082ec02fee523bb464cd2b13a3e2 Mon Sep 17 00:00:00 2001 From: Ken-ichi Ueda Date: Tue, 5 Dec 2023 14:32:15 -0800 Subject: [PATCH] More workarounds for invalidated Realm objects I'm no wiser about why these started happening recently. These are basically hacks. --- .../ObsDetails/ActivityTab/ActivityHeader.js | 13 ++++++----- .../ObsDetails/PhotoDisplayContainer.js | 23 ++++++++++++++----- .../SharedComponents/PhotoScroll.js | 2 +- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/components/ObsDetails/ActivityTab/ActivityHeader.js b/src/components/ObsDetails/ActivityTab/ActivityHeader.js index 5a3baa81a..5f3bae6ca 100644 --- a/src/components/ObsDetails/ActivityTab/ActivityHeader.js +++ b/src/components/ObsDetails/ActivityTab/ActivityHeader.js @@ -44,6 +44,7 @@ const ActivityHeader = ( { const [showDeleteCommentSheet, setShowDeleteCommentSheet] = useState( false ); const [showWithdrawIDSheet, setShowWithdrawIDSheet] = useState( false ); const { user } = item; + const { vision, category } = user || {}; const itemType = item.category ? "Identification" @@ -57,13 +58,13 @@ const ActivityHeader = ( { ); } - if ( item.vision ) return ; + if ( vision ) return ; if ( flagged ) return ; return null; }, [ flagged, idWithdrawn, - item + vision ] ); const renderStatus = useCallback( () => { @@ -81,10 +82,10 @@ const ActivityHeader = ( { ); } - if ( item.category ) { + if ( category ) { return ( - { t( `Category-${item.category}` )} + { t( `Category-${category}` )} ); } @@ -92,9 +93,9 @@ const ActivityHeader = ( { ); }, [ + category, flagged, - idWithdrawn, - item + idWithdrawn ] ); return ( diff --git a/src/components/ObsDetails/PhotoDisplayContainer.js b/src/components/ObsDetails/PhotoDisplayContainer.js index e5121a919..6f6f36216 100644 --- a/src/components/ObsDetails/PhotoDisplayContainer.js +++ b/src/components/ObsDetails/PhotoDisplayContainer.js @@ -82,13 +82,24 @@ const PhotoDisplayContainer = ( { } }, [createFaveMutation, createUnfaveMutation, userFav, uuid] ); - const observationPhotos = useMemo( - ( ) => observation?.observationPhotos || observation?.observation_photos || [], - [observation] - ); const photos = useMemo( - ( ) => _.compact( Array.from( observationPhotos ).map( op => op.photo ) ), - [observationPhotos] + ( ) => _.compact( + Array.from( + observation?.observationPhotos || observation?.observation_photos || [] + ).map( + // TODO replace this hack. Without this you get errors about the + // photo objects being invalidated down in PhotoScroll, but the + // questions remains, why are these objects getting invalidated in + // the first place? We are not deleting them, so what's happening + // to them and why? + op => ( + op.photo.toJSON + ? op.photo.toJSON( ) + : op.photo + ) + ) + ), + [observation] ); return ( diff --git a/src/components/SharedComponents/PhotoScroll.js b/src/components/SharedComponents/PhotoScroll.js index 37dd1fd69..89a59f8d9 100644 --- a/src/components/SharedComponents/PhotoScroll.js +++ b/src/components/SharedComponents/PhotoScroll.js @@ -13,7 +13,7 @@ type Props = { const CarouselImage = ( { item: photo } ) => { // check for local file path for unuploaded photos - const photoUrl = ( photo && photo.url ) + const photoUrl = photo?.url ? photo.url.replace( "square", "large" ) : photo.localFilePath;