Skip to content
Snippets Groups Projects
Commit d673d5ac authored by danieldeng2's avatar danieldeng2
Browse files

Reimplement folder redirection as router hooks

parent 8b4e8115
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import SelectionView, {
SelectionProps,
} from "components/molecules/SelectionView";
import FoldersRow from "components/molecules/FoldersRow";
import { useHistory, useLocation } from "react-router-dom";
export interface FoldersViewProps {
resources: Resource[];
......@@ -16,24 +17,31 @@ const FoldersView: React.FC<FoldersViewProps> = ({
scope,
searchText,
}) => {
let folders: { title: string; id: number }[] = Array.from(
new Set<string>(resources.map((res: Resource) => res.folder))
).map((title: string, id: number) => ({
title: title,
id: id,
}));
let history = useHistory();
let location = useLocation();
let folders: { title: string; id: number }[] = Array.from(
new Set<string>(resources.map((res: Resource) => res.folder))
).map((title: string, id: number) => ({
title: title,
id: id,
}));
if (searchText === "" && scope === "" && folders.length > 0) {
return (
<SelectionView
heading="Folders"
onDownloadClick={() => {}}
onItemClick={() => {}}
selectionItems={folders}
render={(select: SelectionProps) => <FoldersRow select={select} />}
/>
);
}
function handleFolderClick(foldersId: number) {
let title = folders.filter(({ id }) => id === foldersId)[0].title;
history.push(`${location.pathname}/${title}`);
}
if (searchText === "" && scope === "" && folders.length > 0) {
return (
<SelectionView
heading="Folders"
onDownloadClick={() => {}}
onItemClick={handleFolderClick}
selectionItems={folders}
render={(select: SelectionProps) => <FoldersRow select={select} />}
/>
);
}
return null;
};
......
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