From 7cc5dea31a333bb12ffb2b5ef6b13046c305b2e9 Mon Sep 17 00:00:00 2001 From: Albertus Andito Date: Sun, 30 May 2021 15:34:32 +0100 Subject: [PATCH] tree structure --- src/routes.js | 18 +++++ src/views/thesis-bank/components/Thesis.js | 62 ++++++++++++++ .../thesis-bank/layouts/PublicLayout/index.js | 46 +++++++++++ src/views/thesis-bank/public-root/index.js | 80 +++++++++++++++++++ src/views/thesis-bank/public-thesis/index.js | 20 +++++ 5 files changed, 226 insertions(+) create mode 100644 src/views/thesis-bank/components/Thesis.js create mode 100644 src/views/thesis-bank/layouts/PublicLayout/index.js create mode 100644 src/views/thesis-bank/public-root/index.js create mode 100644 src/views/thesis-bank/public-thesis/index.js diff --git a/src/routes.js b/src/routes.js index e8051dd..042d8dd 100644 --- a/src/routes.js +++ b/src/routes.js @@ -25,6 +25,9 @@ import IsicSciEssaySubmissionView from './views/isic-sci-essay/IsicSciEssaySubmi import ThesisSubmissionView from './views/thesis-bank/submission'; import ThesisMySubmissionsView from './views/thesis-bank/me'; import ThesisSearchView from './views/thesis-bank/search'; +import PublicThesesView from './views/thesis-bank/public-root'; +import PublicLayout from './views/thesis-bank/layouts/PublicLayout'; +import PublicThesisView from './views/thesis-bank/public-thesis'; const routes = [ { @@ -118,6 +121,21 @@ const routes = [ { path: '*', element: }, ], }, + + { + path: 'thesis', + element: , + children: [ + { + path: '/:id', + element: , + }, + { + path: '/', + element: , + }, + ], + }, { path: 'essay-isic-sci-2021/:id/submitted', element: , diff --git a/src/views/thesis-bank/components/Thesis.js b/src/views/thesis-bank/components/Thesis.js new file mode 100644 index 0000000..24cadd0 --- /dev/null +++ b/src/views/thesis-bank/components/Thesis.js @@ -0,0 +1,62 @@ +import React, { useEffect, useState } from 'react'; +import { Typography } from 'antd'; +import { DownloadOutlined } from '@ant-design/icons'; + +import axios from 'axios'; +import { Link } from 'react-router-dom'; + +const baseURL = + process.env.NODE_ENV == 'production' + ? 'https://portal.ppiuk.org' + : 'http://localhost:3000'; + +export default function Thesis({ id }) { + const [thesis, setThesis] = useState(null); + + useEffect(() => { + axios.get(`/api/thesis/${id}`).then((res) => { + const data = res.data.data; + setThesis(data); + }); + }, []); + + return ( + thesis && ( +
+ + {thesis.title} + + Abstract + {thesis.abstract} +
+ Item type: {thesis.itemType} + + Contributor/Contact Person:{' '} + {thesis.correspondingAuthor._id === undefined ? ( + thesis.correspondingAuthor.fullName + ) : ( + + {thesis.correspondingAuthor.fullName} + + )} + + University: {thesis.university} + {thesis.link && ( + + URL: {thesis.link} + + )} + {thesis.fileId && ( + + Download File{' '} + + + + + )} +
+ ) + ); +} diff --git a/src/views/thesis-bank/layouts/PublicLayout/index.js b/src/views/thesis-bank/layouts/PublicLayout/index.js new file mode 100644 index 0000000..896b30d --- /dev/null +++ b/src/views/thesis-bank/layouts/PublicLayout/index.js @@ -0,0 +1,46 @@ +import React from 'react'; +import { Card, Layout, Space, Typography } from 'antd'; +import { Link } from 'react-router-dom'; +import { Outlet } from 'react-router'; + +const { Content } = Layout; + +export default function PublicLayout() { + return ( + + + + + + + + + PPI UK Thesis Bank + + + + + + + ); +} diff --git a/src/views/thesis-bank/public-root/index.js b/src/views/thesis-bank/public-root/index.js new file mode 100644 index 0000000..b1639d5 --- /dev/null +++ b/src/views/thesis-bank/public-root/index.js @@ -0,0 +1,80 @@ +import React, { useEffect, useState } from 'react'; + +import axios from 'axios'; +import { Tree } from 'antd'; +import { Link } from 'react-router-dom'; + +export default function PublicThesesView() { + const initTreeData = [ + { + title: 'Clusters', + key: 'clusters', + children: [ + { + title: 'Economics and Business', + key: 'Economics and Business', + }, + { + title: 'Education', + key: 'Education', + }, + { + title: 'Energy', + key: 'Energy', + }, + { + title: 'Health', + key: 'Health', + }, + { + title: 'Infrastructure and Built Environment', + key: 'Infrastructure and Built Environment', + }, + { + title: 'Politics and Law', + key: 'Politics and Law', + }, + { + title: 'Social Development, Arts and Humanity', + key: 'Social Development, Arts and Humanity', + }, + { + title: 'STEM', + key: 'STEM', + }, + ], + }, + ]; + + const [theses, setTheses] = useState(initTreeData); + + useEffect(() => { + axios.get('/api/thesis/').then((res) => { + let clusters = theses.find((item) => { + return item.key === 'clusters'; + }); + for (const cluster of clusters.children) { + let clusteredTheses = res.data.theses.filter((item) => { + return item.cluster === cluster.key; + }); + cluster.children = clusteredTheses.map((item) => { + return { + title: ( + {item.title} + ), + key: item._id, + }; + }); + } + setTheses([clusters]); + }); + }, []); + + return ( + + ); +} diff --git a/src/views/thesis-bank/public-thesis/index.js b/src/views/thesis-bank/public-thesis/index.js new file mode 100644 index 0000000..9526f91 --- /dev/null +++ b/src/views/thesis-bank/public-thesis/index.js @@ -0,0 +1,20 @@ +import React from 'react'; +import { useParams } from 'react-router'; +import { Link } from 'react-router-dom'; +import { RollbackOutlined } from '@ant-design/icons'; + +import Thesis from '../components/Thesis'; + +export default function PublicThesisView() { + const { id } = useParams(); + return ( +
+ + + Go back to thesis directory + + + +
+ ); +}