MediaGallery: Load only once with no attachments to show

This commit is contained in:
Scott Nonnenberg 2024-09-06 06:30:27 +10:00 committed by GitHub
parent 1d199cfff6
commit bc6831a1d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 5 deletions

View file

@ -160,12 +160,24 @@ export function MediaGallery({
}, []);
useEffect(() => {
if (media.length > 0 || documents.length > 0) {
if (
media.length > 0 ||
documents.length > 0 ||
haveOldestDocument ||
haveOldestMedia
) {
return;
}
initialLoad(conversationId);
loadingRef.current = true;
}, [conversationId, initialLoad, media, documents]);
}, [
conversationId,
haveOldestDocument,
haveOldestMedia,
initialLoad,
media,
documents,
]);
const previousLoading = usePrevious(loading, loading);
if (previousLoading && !loading) {

View file

@ -410,12 +410,14 @@ export function reducer(
}
if (action.type === INITIAL_LOAD) {
const { payload } = action;
return {
...state,
loading: false,
...action.payload,
haveOldestDocument: false,
haveOldestMedia: false,
...payload,
haveOldestMedia: payload.media.length === 0,
haveOldestDocument: payload.documents.length === 0,
};
}