diff --git a/src/components/Catalogue/cardComponent.jsx b/src/components/Catalogue/cardComponent.jsx index 9a67ce8..4dcb16a 100644 --- a/src/components/Catalogue/cardComponent.jsx +++ b/src/components/Catalogue/cardComponent.jsx @@ -14,13 +14,13 @@ const CardComponent = ({ imageSrc, itemTitle, itemDescription, expanded }) => { alt={itemTitle} loading={expanded ? "eager" : "lazy"} onLoad={() => setIsImageLoaded(true)} - height="180px" + height="180px" width="100%" /> - {itemTitle} + {itemTitle} {expanded && ( diff --git a/src/components/Catalogue/catalogueItemView.jsx b/src/components/Catalogue/catalogueItemView.jsx index 2afa607..2de7a53 100644 --- a/src/components/Catalogue/catalogueItemView.jsx +++ b/src/components/Catalogue/catalogueItemView.jsx @@ -356,7 +356,7 @@ const CatalogueItemView = ({ isOpen, onClose, title, sectionId, items, setDialog gap={2} > {item.title} @@ -491,8 +491,8 @@ const CatalogueItemView = ({ isOpen, onClose, title, sectionId, items, setDialog > + + + {/* Left: title & description */} + + + {associationData.name || "Untitled"} + + + {associationData.description} + + + + {/* Right: membership switch */} + + + + + + + ); +} + +export default AssociationCard; \ No newline at end of file diff --git a/src/components/DataStudio/associationSwitch.jsx b/src/components/DataStudio/associationSwitch.jsx new file mode 100644 index 0000000..75a9114 --- /dev/null +++ b/src/components/DataStudio/associationSwitch.jsx @@ -0,0 +1,26 @@ +import { Switch } from "@chakra-ui/react"; +import { HiCheck, HiX } from "react-icons/hi"; + +const AssociationSwitch = ({ isMember, onToggle }) => { + return ( + onToggle(details.checked)} + colorPalette={'green'} + > + + + + } + > + + + + + + ); +}; + +export default AssociationSwitch; \ No newline at end of file diff --git a/src/components/DataStudio/editorCard.jsx b/src/components/DataStudio/editorCard.jsx index 0b1e50b..013277d 100644 --- a/src/components/DataStudio/editorCard.jsx +++ b/src/components/DataStudio/editorCard.jsx @@ -6,6 +6,7 @@ import MetadataToggle from "./metadataToggle"; import ArtefactEditorActionBar from "./artefactEditorActionBar"; import ToastWizard from "../toastWizard"; import FigureDisplaySection from "./figureDisplay"; +import ManageAssociationsDialog from "./manageAssociationsDialog"; // Helper function to render text with labeled entities highlighted function renderHighlightedText(text, labels, hoveredIndex, setHoveredIndex) { @@ -91,6 +92,7 @@ function EditorCard({ metadata, artefactId, refreshArtefactData }) { const [isEditing, setIsEditing] = useState(false); const [hoveredIndex, setHoveredIndex] = useState(null); const hoverTimeoutRef = useRef(null); + const [isOpen, setIsOpen] = useState(false); // Change detection states const [originalArtefactData, setOriginalArtefactData] = useState({}); @@ -164,7 +166,7 @@ function EditorCard({ metadata, artefactId, refreshArtefactData }) { Artefact Details - + + + + + + + + + + + + ); +} + +export default ManageAssociationsDialog; \ No newline at end of file diff --git a/src/pages/GroupView.jsx b/src/pages/GroupView.jsx index f7dbc72..9eea4f1 100644 --- a/src/pages/GroupView.jsx +++ b/src/pages/GroupView.jsx @@ -13,97 +13,76 @@ function GroupView() { const [collection, setCollection] = useState(null); const [loading, setLoading] = useState(true); - useEffect(() => { - const fetchCollection = async () => { - try { - setLoading(true); - const response = await server.get(`/cdn/collection/${colID}`); - - if (response.data instanceof JSONResponse) { - if (response.data.isErrorStatus()) { - const errObject = { - response: { - data: response.data - } - }; - throw errObject; - } + const fetchCollection = async () => { + try { + setLoading(true); + const response = await server.get(`/cdn/collection/${colID}`); - // Success case - format the data - let formattedData; - const apiData = response.data.raw.data; + if (response.data instanceof JSONResponse) { + if (response.data.isErrorStatus()) { + const errObject = { + response: { + data: response.data + } + }; + throw errObject; + } - if (apiData.type === 'book') { - formattedData = { - type: 'book', - name: apiData.title, - description: apiData.subtitle || '', - items: apiData.mmArtefacts.map(art => ({ - id: art.id, - title: art.name, - description: art.description, - image: art.image || null - })) - }; - } else if (apiData.type === 'category') { - formattedData = { - type: 'category', - name: apiData.name, - description: apiData.description || '', - items: apiData.members.map(art => ({ - id: art.id, - title: art.name, - description: art.description, - image: art.image - })) - }; - } else if (apiData.type === 'batch') { - formattedData = { - type: 'batch', - name: apiData.name || `Batch ${apiData.id}`, - description: apiData.description || '', - items: apiData.artefacts.map(art => ({ - id: art.id, - title: art.name, - description: art.description, - image: art.image || null - })) - }; - } else { - throw new Error('Unknown collection type'); - } + // Success case - format the data + let formattedData; + const apiData = response.data.raw.data; - setCollection(formattedData); + if (apiData.type === 'book') { + formattedData = { + type: 'book', + name: apiData.title, + description: apiData.subtitle || '', + items: apiData.mmArtefacts.map(art => ({ + id: art.id, + title: art.name, + description: art.description, + image: art.image || null + })) + }; + } else if (apiData.type === 'category') { + formattedData = { + type: 'category', + name: apiData.name, + description: apiData.description || '', + items: apiData.members.map(art => ({ + id: art.id, + title: art.name, + description: art.description, + image: art.image + })) + }; + } else if (apiData.type === 'batch') { + formattedData = { + type: 'batch', + name: apiData.name || `Batch ${apiData.id}`, + description: apiData.description || '', + items: apiData.artefacts.map(art => ({ + id: art.id, + title: art.name, + description: art.description, + image: art.image || null + })) + }; } else { - throw new Error("Unexpected response format"); + throw new Error('Unknown collection type'); } - } catch (err) { - if (err.response && err.response.data instanceof JSONResponse) { - console.log("Error response in collection request:", err.response.data.fullMessage()); - - if (err.response.data.userErrorType()) { - ToastWizard.standard( - "error", - "An Error Occured", - "We could not fetch the collection data. Please try again later.", - 3000, - true, - fetchCollection, - 'Retry' - ); - } else { - ToastWizard.standard( - "error", - "An Error Occured", - "We could not fetch the collection data. Please try again later.", - 3000, - true, - fetchCollection, - 'Retry' - ); - } + + setCollection(formattedData); + } else { + throw new Error("Unexpected response format"); + } + } catch (err) { + if (err.response && err.response.data instanceof JSONResponse) { + console.log("Error response in collection request:", err.response.data.fullMessage()); + + if (err.response.data.userErrorType()) { + ToastWizard.standard("error", "Error fetching data.", err.response.data.message); } else { - console.log("Unexpected error in collection request:", err); ToastWizard.standard( "error", "An Error Occured", @@ -114,11 +93,24 @@ function GroupView() { 'Retry' ); } - } finally { - setLoading(false); + } else { + console.log("Unexpected error in collection request:", err); + ToastWizard.standard( + "error", + "An Error Occured", + "We could not fetch the collection data. Please try again later.", + 3000, + true, + fetchCollection, + 'Retry' + ); } - }; + } finally { + setLoading(false); + } + }; + useEffect(() => { fetchCollection(); }, [colID]); @@ -161,9 +153,9 @@ function GroupView() { {collection.items.map(item => ( ))}