Skip to content
Snippets Groups Projects
Commit 836f5d35 authored by Wilson Chua's avatar Wilson Chua :rice_ball:
Browse files

ModuleResources: Support link resource type, but still missing banner for the card

parent a53f2c40
No related branches found
No related tags found
No related merge requests found
...@@ -6,14 +6,9 @@ import Row from "react-bootstrap/esm/Row"; ...@@ -6,14 +6,9 @@ import Row from "react-bootstrap/esm/Row";
import Col from "react-bootstrap/esm/Col"; import Col from "react-bootstrap/esm/Col";
import Badge from "react-bootstrap/Badge"; import Badge from "react-bootstrap/Badge";
import { faSquare, faCheckSquare } from "@fortawesome/free-regular-svg-icons"; import { faSquare, faCheckSquare } from "@fortawesome/free-regular-svg-icons";
import {
faFileAlt,
IconDefinition,
faFilePdf,
faFileVideo,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { SelectionProps } from "components/molecules/SelectionView"; import { SelectionProps } from "components/molecules/SelectionView";
import { resourceTypeToIcon } from "../../pages/ModuleResources"
const CategoryList: React.FC<{ select: SelectionProps }> = ({ const CategoryList: React.FC<{ select: SelectionProps }> = ({
select, select,
...@@ -21,25 +16,13 @@ const CategoryList: React.FC<{ select: SelectionProps }> = ({ ...@@ -21,25 +16,13 @@ const CategoryList: React.FC<{ select: SelectionProps }> = ({
return ( return (
<> <>
{select.selectionItems.map(({ title, type, tags, id }) => { {select.selectionItems.map(({ title, type, tags, id }) => {
let normalIcon: IconDefinition;
if (type === undefined || tags === undefined) return null; if (type === undefined || tags === undefined) return null;
switch (type) {
case "pdf":
normalIcon = faFilePdf;
break;
case "video":
normalIcon = faFileVideo;
break;
default:
normalIcon = faFileAlt;
break;
}
let icon = select.isAnySelected() || select.state.isHoveringOver[id] let icon = select.isAnySelected() || select.state.isHoveringOver[id]
? select.state.isSelected[id] ? select.state.isSelected[id]
? faCheckSquare ? faCheckSquare
: faSquare : faSquare
: normalIcon; : resourceTypeToIcon(type);
return ( return (
<Row <Row
......
...@@ -4,13 +4,8 @@ import Row from "react-bootstrap/esm/Row"; ...@@ -4,13 +4,8 @@ import Row from "react-bootstrap/esm/Row";
import Col from "react-bootstrap/esm/Col"; import Col from "react-bootstrap/esm/Col";
import FileCard from "components/atoms/FileCard"; import FileCard from "components/atoms/FileCard";
import { faSquare, faCheckSquare } from "@fortawesome/free-regular-svg-icons"; import { faSquare, faCheckSquare } from "@fortawesome/free-regular-svg-icons";
import {
faFileAlt,
IconDefinition,
faFilePdf,
faFileVideo,
} from "@fortawesome/free-solid-svg-icons";
import { SelectionProps } from "components/molecules/SelectionView"; import { SelectionProps } from "components/molecules/SelectionView";
import { resourceTypeToIcon } from "../../pages/ModuleResources"
const CurrentDirectoryRow: React.FC<{ select: SelectionProps }> = ({ const CurrentDirectoryRow: React.FC<{ select: SelectionProps }> = ({
select, select,
...@@ -20,19 +15,8 @@ const CurrentDirectoryRow: React.FC<{ select: SelectionProps }> = ({ ...@@ -20,19 +15,8 @@ const CurrentDirectoryRow: React.FC<{ select: SelectionProps }> = ({
style={{ marginTop: "10px", marginLeft: "-10px", marginRight: "-10px" }} style={{ marginTop: "10px", marginLeft: "-10px", marginRight: "-10px" }}
> >
{select.selectionItems.map(({ title, type, tags, id }) => { {select.selectionItems.map(({ title, type, tags, id }) => {
let normalIcon: IconDefinition;
if (type === undefined || tags === undefined) return null; if (type === undefined || tags === undefined) return null;
switch (type) {
case "pdf":
normalIcon = faFilePdf;
break;
case "video":
normalIcon = faFileVideo;
break;
default:
normalIcon = faFileAlt;
break;
}
return ( return (
<Col <Col
xs={6} xs={6}
...@@ -57,7 +41,7 @@ const CurrentDirectoryRow: React.FC<{ select: SelectionProps }> = ({ ...@@ -57,7 +41,7 @@ const CurrentDirectoryRow: React.FC<{ select: SelectionProps }> = ({
? select.state.isSelected[id] ? select.state.isSelected[id]
? faCheckSquare ? faCheckSquare
: faSquare : faSquare
: normalIcon : resourceTypeToIcon(type)
} }
onClick={() => select.handleCardClick(id)} onClick={() => select.handleCardClick(id)}
onIconClick={(e) => { onIconClick={(e) => {
......
...@@ -6,13 +6,8 @@ import Row from "react-bootstrap/esm/Row"; ...@@ -6,13 +6,8 @@ import Row from "react-bootstrap/esm/Row";
import Col from "react-bootstrap/esm/Col"; import Col from "react-bootstrap/esm/Col";
import FileCard from "components/atoms/FileCard"; import FileCard from "components/atoms/FileCard";
import { faSquare, faCheckSquare } from "@fortawesome/free-regular-svg-icons"; import { faSquare, faCheckSquare } from "@fortawesome/free-regular-svg-icons";
import {
faFileAlt,
IconDefinition,
faFilePdf,
faFileVideo,
} from "@fortawesome/free-solid-svg-icons";
import { SelectionProps } from "components/molecules/SelectionView"; import { SelectionProps } from "components/molecules/SelectionView";
import { resourceTypeToIcon } from "../../pages/ModuleResources"
const QuickAccessRow: React.FC<{ select: SelectionProps }> = ({ const QuickAccessRow: React.FC<{ select: SelectionProps }> = ({
select, select,
...@@ -27,19 +22,8 @@ const QuickAccessRow: React.FC<{ select: SelectionProps }> = ({ ...@@ -27,19 +22,8 @@ const QuickAccessRow: React.FC<{ select: SelectionProps }> = ({
)} )}
> >
{select.selectionItems.map(({ title, type, tags, id }) => { {select.selectionItems.map(({ title, type, tags, id }) => {
let normalIcon: IconDefinition;
if (type === undefined || tags === undefined) return null; if (type === undefined || tags === undefined) return null;
switch (type) {
case "pdf":
normalIcon = faFilePdf;
break;
case "video":
normalIcon = faFileVideo;
break;
default:
normalIcon = faFileAlt;
break;
}
return ( return (
<Col <Col
xs={7} xs={7}
...@@ -64,7 +48,7 @@ const QuickAccessRow: React.FC<{ select: SelectionProps }> = ({ ...@@ -64,7 +48,7 @@ const QuickAccessRow: React.FC<{ select: SelectionProps }> = ({
? select.state.isSelected[id] ? select.state.isSelected[id]
? faCheckSquare ? faCheckSquare
: faSquare : faSquare
: normalIcon : resourceTypeToIcon(type)
} }
onClick={() => select.handleCardClick(id)} onClick={() => select.handleCardClick(id)}
onIconClick={(e) => { onIconClick={(e) => {
......
...@@ -7,6 +7,13 @@ import CurrentDirectoryView from "./components/CurrentDirectoryView"; ...@@ -7,6 +7,13 @@ import CurrentDirectoryView from "./components/CurrentDirectoryView";
import FoldersView from "./components/FoldersView"; import FoldersView from "./components/FoldersView";
import ListView from "./components/ListView"; import ListView from "./components/ListView";
import TopSection from "./components/TopSection"; import TopSection from "./components/TopSection";
import {
faFileAlt,
faFilePdf,
faFileVideo,
faLink,
IconDefinition,
} from "@fortawesome/free-solid-svg-icons";
export interface Resource { export interface Resource {
title: string; title: string;
...@@ -14,6 +21,7 @@ export interface Resource { ...@@ -14,6 +21,7 @@ export interface Resource {
tags: string[]; tags: string[];
folder: string; folder: string;
id: number; id: number;
path?: string;
} }
export interface Folder { export interface Folder {
...@@ -35,6 +43,19 @@ export interface ResourceState { ...@@ -35,6 +43,19 @@ export interface ResourceState {
searchText: string; searchText: string;
} }
export function resourceTypeToIcon(type: string): IconDefinition {
switch (type) {
case "pdf":
return faFilePdf;
case "video":
return faFileVideo;
case "link":
return faLink;
default:
return faFileAlt;
}
}
class ModuleResources extends React.Component<ResourcesProps, ResourceState> { class ModuleResources extends React.Component<ResourcesProps, ResourceState> {
moduleCode = this.props.moduleID.startsWith("CO") moduleCode = this.props.moduleID.startsWith("CO")
? this.props.moduleID.slice(2) ? this.props.moduleID.slice(2)
...@@ -65,6 +86,7 @@ class ModuleResources extends React.Component<ResourcesProps, ResourceState> { ...@@ -65,6 +86,7 @@ class ModuleResources extends React.Component<ResourcesProps, ResourceState> {
tags: resource.tags, tags: resource.tags,
folder: resource.category, folder: resource.category,
id: resource.id, id: resource.id,
path: resource.path,
} as Resource); } as Resource);
} }
this.setState({ resources: resourceArr, isLoaded: true }); this.setState({ resources: resourceArr, isLoaded: true });
...@@ -128,7 +150,17 @@ class ModuleResources extends React.Component<ResourcesProps, ResourceState> { ...@@ -128,7 +150,17 @@ class ModuleResources extends React.Component<ResourcesProps, ResourceState> {
}); });
} }
handleFileClick(id: number) { handleResourceClick(id: number) {
let resource = this.state.resources.find(resource => resource.id === id);
if (resource === undefined) {
return;
}
if (resource.type === "link") {
window.open(resource.path, "_blank");
return;
}
// Resource is of file type, get from Materials
const onSuccess = (data: any) => { const onSuccess = (data: any) => {
// TODO: Try to navigate straight to the endpoint url instead of creating an object url // TODO: Try to navigate straight to the endpoint url instead of creating an object url
data.blob().then((blob: any) => { data.blob().then((blob: any) => {
...@@ -218,7 +250,7 @@ class ModuleResources extends React.Component<ResourcesProps, ResourceState> { ...@@ -218,7 +250,7 @@ class ModuleResources extends React.Component<ResourcesProps, ResourceState> {
scope={scope} scope={scope}
searchText={this.state.searchText} searchText={this.state.searchText}
onDownloadClick={(ids) => this.handleFileDownload(ids)} onDownloadClick={(ids) => this.handleFileDownload(ids)}
onItemClick={(id) => this.handleFileClick(id)} onItemClick={(id) => this.handleResourceClick(id)}
includeInSearchResult={this.includeInSearchResult} includeInSearchResult={this.includeInSearchResult}
/> />
...@@ -227,7 +259,7 @@ class ModuleResources extends React.Component<ResourcesProps, ResourceState> { ...@@ -227,7 +259,7 @@ class ModuleResources extends React.Component<ResourcesProps, ResourceState> {
scope={scope} scope={scope}
searchText={this.state.searchText} searchText={this.state.searchText}
onDownloadClick={(ids) => this.handleFileDownload(ids)} onDownloadClick={(ids) => this.handleFileDownload(ids)}
onItemClick={(id) => this.handleFileClick(id)} onItemClick={(id) => this.handleResourceClick(id)}
/> />
</> </>
); );
...@@ -239,7 +271,7 @@ class ModuleResources extends React.Component<ResourcesProps, ResourceState> { ...@@ -239,7 +271,7 @@ class ModuleResources extends React.Component<ResourcesProps, ResourceState> {
searchText={this.state.searchText} searchText={this.state.searchText}
onDownloadClick={(ids) => this.handleFileDownload(ids)} onDownloadClick={(ids) => this.handleFileDownload(ids)}
onSectionDownloadClick={(category) => this.handleSectionDownload(category)} onSectionDownloadClick={(category) => this.handleSectionDownload(category)}
onItemClick={(id) => this.handleFileClick(id)} onItemClick={(id) => this.handleResourceClick(id)}
includeInSearchResult={this.includeInSearchResult} includeInSearchResult={this.includeInSearchResult}
/> />
</> </>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment