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

Update with changes from materials test resources

parent 10486ce1
No related branches found
No related tags found
No related merge requests found
...@@ -15,43 +15,73 @@ import ResourcesFolderView from "components/molecules/ResourcesFolderView"; ...@@ -15,43 +15,73 @@ import ResourcesFolderView from "components/molecules/ResourcesFolderView";
import CurrentDirectoryView from "components/molecules/CurrentDirectoryView"; import CurrentDirectoryView from "components/molecules/CurrentDirectoryView";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
export interface Resource {
title: string;
type: string;
tags: string[];
folder: string;
id: number;
}
const ModuleResources: React.FC<{ year: string}> = ({year}) => { const ModuleResources: React.FC<{ year: string}> = ({year}) => {
let {id, scope } = useParams(); let {id, scope } = useParams();
scope = scope === undefined ? "" : scope; scope = scope === undefined ? "" : scope;
const module_code = id.startsWith("CO") ? id.slice(2) : id;
//maybe refactor into class?
const [error, setError] = useState(null);
const [isLoaded, setIsLoaded] = useState(false);
const [resources, setResources] = useState<Resource[]>([]);
const quickAccessItems = resourceItems.filter( const quickAccessItems = resources.filter(
({ tags, folder }) => ({ tags, folder }) =>
tags.includes("new") && (scope === "" || scope === folder) tags.includes("new") && (scope === "" || scope === folder)
); );
const currentDirectoryFiles = resourceItems.filter( const currentDirectoryFiles = resources.filter(
({ folder }) => folder === scope ({ folder }) => folder === scope
); );
const module_code = id.startsWith("CO") ? id : id.slice(2);
//maybe refactor into class? let folders: { title: string; id: number;}[] = Array.from(new Set<string>(resources.map((res: Resource) => {
// const [error, setError] = useState(null); return res.folder; }))).map((title: string) => {
// const [isLoaded, setIsLoaded] = useState(false); return {
// const [resources, setResources] = useState([]); title: title,
id: 0,
};
})
// useEffect(() => { useEffect(() => {
// setIsLoaded(false); setIsLoaded(false);
// const onSuccess = (data: any) => { const onSuccess = (data: { json: () => any[]; }) => {
// setIsLoaded(true); var resourceArr = [];
// setResources(data.json()); var json = data.json()
// } for (const key in json) {
// const onFailure = (error: any) => { let resource = json[key]
// setIsLoaded(true); resourceArr.push({
// setError(error); title: resource.title,
// } type: resource.type,
tags: resource.tags,
folder: resource.category,
id: resource.id,
} as Resource);
}
setResources(resourceArr);
console.log(resources);
setIsLoaded(true);
}
const onFailure = (error: any) => {
setError(error);
setIsLoaded(true);
}
// request(api.MATERIALS_RESOURCES, "GET", onSuccess, onFailure, { request(api.MATERIALS_RESOURCES, "GET", onSuccess, onFailure, {
// "year": year, "year": year,
// "course": module_code "course": module_code
// }) })
// }, [year, module_code]); }, [year, module_code]);
return ( return (
<> <>
<MyBreadcrumbs /> <MyBreadcrumbs />
...@@ -68,7 +98,7 @@ const ModuleResources: React.FC<{ year: string}> = ({year}) => { ...@@ -68,7 +98,7 @@ const ModuleResources: React.FC<{ year: string}> = ({year}) => {
</InputGroup.Append> </InputGroup.Append>
</InputGroup> </InputGroup>
{scope === "" && folderItems.length > 0 ? <ResourcesFolderView folderItems={folderItems} /> : null} {scope === "" && folders.length > 0 ? <ResourcesFolderView folderItems={folders} /> : null}
{scope !== "" && currentDirectoryFiles.length > 0 ? <CurrentDirectoryView documentItems={currentDirectoryFiles} /> : null} {scope !== "" && currentDirectoryFiles.length > 0 ? <CurrentDirectoryView documentItems={currentDirectoryFiles} /> : null}
{scope === "" && quickAccessItems.length > 0 ? <QuickAccessView quickAccessItems={quickAccessItems} /> : null} {scope === "" && quickAccessItems.length > 0 ? <QuickAccessView quickAccessItems={quickAccessItems} /> : null}
...@@ -77,130 +107,3 @@ const ModuleResources: React.FC<{ year: string}> = ({year}) => { ...@@ -77,130 +107,3 @@ const ModuleResources: React.FC<{ year: string}> = ({year}) => {
}; };
export default ModuleResources; export default ModuleResources;
let folderItems = [
{
title: "Lecture Notes",
id: 0,
},
{
title: "Logic Exercise",
id: 1,
},
{
title: "Pandora Lab",
id: 2,
},
{
title: "Extra",
id: 3,
},
];
let resourceItems = [
{
title: "How To Use Pandora",
type: "video",
tags: ["new", "WATCHME"],
folder: "Pandora Lab",
id: 14,
},
{
title: "Logic Exercise 1",
type: "File",
tags: ["Week 1"],
folder: "Logic Exercise",
id: 8,
},
{
title: "Logic Exercise 2",
type: "File",
tags: ["Week 2"],
folder: "Logic Exercise",
id: 9,
},
{
title: "Logic Exercise 3",
type: "File",
tags: ["new", "Week 3"],
folder: "Logic Exercise",
id: 10,
},
{
title: "Syntax Semantics Propositional Logic",
type: "pdf",
tags: ["Slides"],
folder: "Lecture Notes",
id: 0,
},
{
title: "Classical First-Order Predicate Logic",
type: "pdf",
tags: ["Slides"],
folder: "Lecture Notes",
id: 1,
},
{
title: "Translation Validity",
type: "pdf",
tags: ["new", "Slides"],
folder: "Lecture Notes",
id: 2,
},
{
title: "validityPL-part1",
type: "pdf",
tags: ["Slides"],
folder: "Lecture Notes",
id: 3,
},
{
title: "validityPL-part2",
type: "pdf",
tags: ["Slides"],
folder: "Lecture Notes",
id: 4,
},
{
title: "validityPL-part3",
type: "pdf",
tags: ["new", "Slides"],
folder: "Lecture Notes",
id: 5,
},
{
title: "validityFOL-part1",
type: "pdf",
tags: ["Slides"],
folder: "Lecture Notes",
id: 6,
},
{
title: "validityFOL-part2",
type: "pdf",
tags: ["new", "Slides"],
folder: "Lecture Notes",
id: 7,
},
{
title: "Pandora Lab",
type: "File",
tags: [],
folder: "Pandora Lab",
id: 11,
},
{
title: "Propositional Logic Exercises",
type: "pdf",
tags: ["new", "Revision"],
folder: "Extra",
id: 12,
},
{
title: "Extra Logic Exercises",
type: "pdf",
tags: ["new", "Revision"],
folder: "Extra",
id: 13,
},
];
...@@ -76,7 +76,7 @@ const StandardView: React.FC<StandardViewProps> = ({ ...@@ -76,7 +76,7 @@ const StandardView: React.FC<StandardViewProps> = ({
</Route> </Route>
<Route path="/modules/:id/resources/:scope?"> <Route path="/modules/:id/resources/:scope?">
<ModuleResources year="1819"/> <ModuleResources year="2021"/>
</Route> </Route>
<Route path="/modules/:id/feedback" component={ModuleFeedback} /> <Route path="/modules/:id/feedback" component={ModuleFeedback} />
......
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