diff --git a/frontend/components/Viewing/Sections/Attachments/AttachmentRows.js b/frontend/components/Viewing/Sections/Attachments/AttachmentRows.js index 9bfb74a0..adc378b1 100644 --- a/frontend/components/Viewing/Sections/Attachments/AttachmentRows.js +++ b/frontend/components/Viewing/Sections/Attachments/AttachmentRows.js @@ -29,17 +29,19 @@ export default function AttachmentRows(properties) { const dispatch = useDispatch(); const token = useSelector(state => state.user.token); const [attachmentInfo, setStateAttachments] = useState(); - const [attachments, setAttachments] = useState(properties.attachments.map(attachment => ({ + + const [attachments, setAttachments] = useState((properties.attachments || []).map(attachment => ({ ...attachment, processedTopLevel: attachment.topLevel // Initialize with topLevel }))); + //There are attachments from the parent but they haven't been added to the state yet. - if (attachmentInfo === undefined && properties.attachments.length > 0) + if (attachmentInfo === undefined && properties.attachments && properties.attachments.length > 0) setStateAttachments(properties.attachments); //There are no attachments to get. - if (properties.attachments.length === 0) return null; + if (properties.attachments && properties.attachments.length === 0) return null; // useEffect(() => { // async function processAttachments() { diff --git a/frontend/components/Viewing/Sections/Attachments/AttachmentsTable.js b/frontend/components/Viewing/Sections/Attachments/AttachmentsTable.js index f07af3c8..67c3077f 100644 --- a/frontend/components/Viewing/Sections/Attachments/AttachmentsTable.js +++ b/frontend/components/Viewing/Sections/Attachments/AttachmentsTable.js @@ -8,8 +8,8 @@ import styles from '../../../../styles/view.module.css'; */ export default function AttachmentsTable(properties) { const header = createHeader(properties.headers); - - if (properties.attachments.length === 0 && !properties.owner) return null; + console.log(properties); + if (properties.attachments && properties.attachments.length === 0 && !properties.owner) return null; return (