Skip to content

Commit

Permalink
attachments can be uploaded and removed now, just refreshes the page
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfang97 committed Jun 14, 2024
1 parent 66ba89e commit 188cf7a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export default function AttachmentRows(properties) {
type: attachment.format.split('/').pop(),
status: 'downloading'
};
console.log(item);
dispatch(downloadFiles([item]));
}
}}
Expand All @@ -138,10 +137,8 @@ export default function AttachmentRows(properties) {
<div
type="button"
onClick={async () => {
console.log("reached onclick");
const copy = [...attachments];
const deletedAttachment = copy.splice(key, 1);
console.log(copy);
setAttachments(copy);
await getQueryResponse(
dispatch,
Expand All @@ -150,6 +147,7 @@ export default function AttachmentRows(properties) {
token,
true
);
window.location.reload();
}}
>
<FontAwesomeIcon
Expand Down
24 changes: 23 additions & 1 deletion frontend/components/Viewing/Sections/Attachments/Attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export default function Attachments(properties) {
const graphUri = useSelector(state => state.user.graphUri);
const attachments = useSelector(state => state.attachments.attachments);

const [refreshMembers, setRefreshMembers] = useState(false);

const handleSetRefreshMembers = (value) => {
setRefreshMembers(value);
};

useEffect(() => {
if (owner == undefined) {
//The attachments in the store should be reset, a new page has been loaded.
Expand Down Expand Up @@ -51,15 +57,31 @@ export default function Attachments(properties) {
}
}, [owner]);

useEffect(() => {
if (refreshMembers) {
// Fetch attachments again and update the state
getQueryResponse(dispatch, getAttachments, { uri: properties.uri }).then(
attachments => {
if (attachments.length > 0) {
dispatch(setAttachments(attachments));
}
// Reset refreshMembers to false after refreshing
setRefreshMembers(false);
}
);
window.location.reload();
}
}, [refreshMembers, dispatch, properties.uri]);

if (!owner) return <Loading />;

return (
<AttachmentsTable
owner={isOwner}
uri={properties.uri}
setRefreshMembers={handleSetRefreshMembers}
headers={['Type', 'Name', 'Size']}
attachments={attachments}
setRefreshMembers={properties.setRefreshMembers}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export default function UploadAttachments(properties) {
const uriToUse = processedUriData.urlReplacedForBackend || processedUriData.original;
attachFromFile(selectedFiles, uriToUse).then(() => {
dispatch(setUploadStatus(''));
properties.setRefreshMembers(true);
});

//Query all the attachments so the store can be updated.
Expand Down Expand Up @@ -287,7 +288,9 @@ export default function UploadAttachments(properties) {
uri: uriToUse
};

attachFromURL(attachment);
attachFromURL(attachment).then(() => {
properties.setRefreshMembers(true); // Ensure refresh after URL attachment
});
});

const convertedUrl = uri.slice(
Expand All @@ -306,6 +309,7 @@ export default function UploadAttachments(properties) {
dispatch(
setAttachments([...properties.attachments, newAttachment])
);
properties.setRefreshMembers(true);

//Resets all the values to their default.
setSelectedOption('Attachment type...');
Expand Down

0 comments on commit 188cf7a

Please sign in to comment.