Skip to content

Commit

Permalink
feat(Collections): custom collection urls
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeaturner committed Jul 30, 2024
1 parent ca49347 commit 44c96ee
Show file tree
Hide file tree
Showing 12 changed files with 661 additions and 1,117 deletions.
4 changes: 0 additions & 4 deletions client/src/Commons.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Suspense, useEffect, useState } from "react";
import { useLocation, Switch, Route } from "react-router-dom";
import axios from "axios";
import CommonsAuthor from "./screens/commons/Author";
import CommonsBook from "./screens/commons/Book";
import CommonsCatalog from "./components/commons/CommonsCatalog";
import CommonsCollection from "./screens/commons/Collection";
import CommonsCollections from "./components/commons/CommonsCollections";
import CommonsCollectionView from "./components/commons/CommonsCollectionView";
import CommonsFooter from "./components/commons/CommonsFooter";
import CommonsHomework from "./components/commons/CommonsHomework";
import CommonsJumbotron from "./components/commons/CommonsJumbotron";
Expand All @@ -19,7 +16,6 @@ import SystemAnnouncement from "./components/util/SystemAnnouncement";
import withUserStateDependency from "./enhancers/withUserStateDependency";
import "./components/commons/Commons.css";
import { useTypedSelector } from "./state/hooks";
import { Announcement } from "./types";
import LoadingSpinner from "./components/LoadingSpinner";
import useSystemAnnouncement from "./hooks/useSystemAnnouncement";

Expand Down
1 change: 1 addition & 0 deletions client/src/Platform.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const Platform = () => {
"/",
"/catalog",
"/collections",
"/collections/:id?",
"/collection/:id",
"/commons-project/:id",
"/author/:id",
Expand Down
73 changes: 44 additions & 29 deletions client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
ConductorSearchResponseFile,
CustomFilter,
} from "./types/Search";
import {CloudflareCaptionData, SortDirection} from "./types/Misc";
import { CloudflareCaptionData, SortDirection } from "./types/Misc";

/**
* @fileoverview
Expand Down Expand Up @@ -705,52 +705,67 @@ class API {

// Commons Collections
async getCollection(collectionIDOrTitle: string) {
return await axios.get<{
coll: Collection,
} & ConductorBaseResponse>(`/commons/collections/${encodeURIComponent(collectionIDOrTitle)}`);
return await axios.get<
{
collection: Collection;
} & ConductorBaseResponse
>(`/commons/collection/${encodeURIComponent(collectionIDOrTitle)}`);
}

async getCollectionResources({
collIDOrTitle,
limit,
page,
query,
sort
} : {
collIDOrTitle,
limit,
page,
query,
sort,
}: {
collIDOrTitle?: string;
limit?: number;
page?: number;
query?: string | null;
sort?: string;
}) {
return await axios.get<{
resources: CollectionResource[]
} & ConductorBaseResponse>(`/commons/collections/${encodeURIComponent(collIDOrTitle ?? '')}/resources`, {
params: {
page,
limit,
sort,
query,
},
});
return await axios.get<
{
resources: CollectionResource[];
total_items: number;
cursor?: number
} & ConductorBaseResponse
>(
`/commons/collection/${encodeURIComponent(
collIDOrTitle ?? ""
)}/resources`,
{
params: {
page,
limit,
sort,
query,
},
}
);
}

async getCommonsCollections({
limit,
page,
query,
sort,
sortDirection,
} : {
limit,
page,
query,
sort,
sortDirection,
}: {
limit?: number;
page?: number;
query?: string | null;
sort?: string;
sortDirection?: SortDirection;
}) {
return await axios.get<{
collections: Collection[]
} & ConductorBaseResponse>(`/commons/collections`, {
return await axios.get<
{
collections: Collection[];
total_items: number;
cursor?: number
} & ConductorBaseResponse
>(`/commons/collections`, {
params: {
limit,
page,
Expand Down
60 changes: 60 additions & 0 deletions client/src/components/Collections/CollectionCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Card, Image } from "semantic-ui-react";
import { Collection, CollectionResource } from "../../types";
import { Link } from "react-router-dom";
import { getLibGlyphURL, getLibraryName } from "../util/LibraryOptions";
import { isBook as checkIsBook } from "../../utils/typeHelpers";
import { getCollectionHref } from "../util/CollectionHelpers";

interface CollectionCardProps {
item: Collection | CollectionResource;
}

const CollectionCard: React.FC<CollectionCardProps> = ({ item }) => {
const getResourceData = () => {
if ("resourceData" in item) {
return item.resourceData;
} else {
return item;
}
};

const resourceData = getResourceData();
const isBook = checkIsBook(resourceData);

return (
<Card
as={Link}
to={getCollectionHref(item)}
className="commons-content-card"
>
<div
className="commons-content-card-img"
style={{
backgroundImage: `url(${
isBook ? resourceData.thumbnail : resourceData.coverPhoto
})`,
}}
/>
<Card.Content>
<Card.Header className="commons-content-card-header">
{resourceData.title}
</Card.Header>
<Card.Meta>
<Image
src={getLibGlyphURL(isBook ? resourceData.library : "")}
className="library-glyph"
/>
{getLibraryName(isBook ? resourceData.library : "")}
</Card.Meta>
<Card.Description>
<p>{isBook ? resourceData.author : ""}</p>
<p>
<em>{isBook ? resourceData.affiliation : ""}</em>
</p>
</Card.Description>
</Card.Content>
</Card>
);
};

export default CollectionCard;
99 changes: 99 additions & 0 deletions client/src/components/Collections/CollectionTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Header, Image, Table } from "semantic-ui-react";
import { Collection, CollectionResource } from "../../types";
import { getLibGlyphAltText, getLibGlyphURL } from "../util/LibraryOptions";
import { Link } from "react-router-dom";
import { isBook as checkIsBook } from "../../utils/typeHelpers";
import { getCollectionHref } from "../util/CollectionHelpers";

export interface CollectionTableProps {
data: Collection[] | CollectionResource[];
loading: boolean;
}

const CollectionTable: React.FC<CollectionTableProps> = ({ data, loading }) => {
const getItemData = (item: Collection | CollectionResource) => {
if ("resourceData" in item) {
return item.resourceData;
} else {
return item;
}
};

return (
<Table celled title="Collection Resources">
<Table.Header>
<Table.Row>
<Table.HeaderCell scope="col" role="columnheader">
<Image
centered
src={getLibGlyphURL("")}
className="commons-itemized-glyph"
alt={getLibGlyphAltText("")}
/>
</Table.HeaderCell>
<Table.HeaderCell scope="col">
<Header sub>Title</Header>
</Table.HeaderCell>
<Table.HeaderCell scope="col">
<Header sub>Subject</Header>
</Table.HeaderCell>
<Table.HeaderCell scope="col">
<Header sub>Author</Header>
</Table.HeaderCell>
<Table.HeaderCell scope="col">
<Header sub>Affiliation</Header>
</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
{!loading &&
data.length > 0 &&
data.map((i) => {
const item = getItemData(i);
const isBook = checkIsBook(item);
return (
<Table.Row key={crypto.randomUUID()}>
<Table.Cell>
<Image
centered
src={getLibGlyphURL(isBook ? item.library : "")}
className="commons-itemized-glyph"
alt={getLibGlyphAltText(isBook ? item.library : "")}
/>
</Table.Cell>
<Table.Cell>
<p>
<strong>
<Link to={getCollectionHref(i)}>{item.title}</Link>
</strong>
</p>
</Table.Cell>
<Table.Cell>
<p>{isBook ? item.subject : ""}</p>
</Table.Cell>
<Table.Cell>
<p>{isBook ? item.author : ""}</p>
</Table.Cell>
<Table.Cell>
<p>
<em>{isBook ? item.affiliation : ""}</em>
</p>
</Table.Cell>
</Table.Row>
);
})}
{!loading && data.length === 0 && (
<Table.Row>
<Table.Cell colSpan={4}>
<p className="text-center">
<em>No results found.</em>
</p>
</Table.Cell>
</Table.Row>
)}
</Table.Body>
</Table>
);
};

export default CollectionTable;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TabPane, TabPaneProps } from "semantic-ui-react";
import { cloneElement, useState } from "react";
import useInfiniteScroll from "../../../hooks/useInfiniteScroll";

interface CatalogTabProps extends TabPaneProps {
Expand Down
Loading

0 comments on commit 44c96ee

Please sign in to comment.