From f32b04c0579bd63e0feca852c5e26cdcf7f8a353 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 22 Jun 2022 20:44:16 +0430 Subject: [PATCH] Fully added listing functionality. --- src/App.js | 33 +++++++++++++++++++++++---------- src/componets/SideBar.js | 30 +++++++++++++++++++++++++++++- src/routes/Lists.js | 24 ++++++++++++++++++++++++ src/routes/Tags.js | 3 ++- src/styles/SideBar.css | 2 +- 5 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 src/routes/Lists.js diff --git a/src/App.js b/src/App.js index 2dc7c0f..ec93a26 100644 --- a/src/App.js +++ b/src/App.js @@ -12,6 +12,7 @@ import NoResults from "./componets/NoResults"; import Loader from "./componets/Loader"; import SideBar from "./componets/SideBar"; import Tags from "./routes/Tags.js"; +import Lists from "./routes/Lists.js"; import { Route, Routes } from "react-router-dom"; function App() { @@ -58,10 +59,6 @@ function App() { const filteredData = filter(data, searchQuery, filterCheckbox); - const tags = concatTags(data); - - const lists = concatLists(data); - async function fetchData() { const res = await fetch(API_HOST + "/api"); const resJSON = await res.json(); @@ -98,7 +95,8 @@ function App() { return (
@@ -155,8 +153,8 @@ function App() { onExit={exitAdding} reFetch={fetchData} lightMode={lightMode} - tags={() => tags} - lists={() => lists} + tags={() => concatTags(data)} + lists={() => concatLists(data)} /> ) : null} @@ -174,8 +172,8 @@ function App() { lightMode={lightMode} SetLoader={SetLoader} data={filteredData} - tags={tags} - lists={lists} + tags={concatTags(data)} + lists={concatLists(data)} reFetch={fetchData} />
@@ -189,7 +187,22 @@ function App() { lightMode={lightMode} SetLoader={SetLoader} data={filteredData} - tags={tags} + tags={concatTags(data)} + lists={concatLists(data)} + reFetch={fetchData} + /> + } + /> + + } diff --git a/src/componets/SideBar.js b/src/componets/SideBar.js index c20a10e..cb6bcc5 100644 --- a/src/componets/SideBar.js +++ b/src/componets/SideBar.js @@ -11,7 +11,7 @@ import "react-pro-sidebar/dist/css/styles.css"; import "../styles/SideBar.css"; import { Link } from "react-router-dom"; -const SideBar = ({ tags, handleToggleSidebar, toggle }) => { +const SideBar = ({ tags, lists, handleToggleSidebar, toggle }) => { const sortedTags = tags.sort((a, b) => { const A = a.toLowerCase(), B = b.toLowerCase(); @@ -19,6 +19,19 @@ const SideBar = ({ tags, handleToggleSidebar, toggle }) => { if (A > B) return 1; return 0; }); + + const sortedLists = lists + .sort((a, b) => { + const A = a.toLowerCase(), + B = b.toLowerCase(); + if (A < B) return -1; + if (A > B) return 1; + return 0; + }) + .filter((e) => { + return e != "Unsorted"; + }); + return ( { + } + suffix={{sortedTags.length}} + title={

Lists

} + > + {sortedLists.map((e, i) => { + const path = `/lists/${e}`; + return ( + + {e} + + ); + })} +
+ } suffix={{sortedTags.length}} diff --git a/src/routes/Lists.js b/src/routes/Lists.js new file mode 100644 index 0000000..64366fd --- /dev/null +++ b/src/routes/Lists.js @@ -0,0 +1,24 @@ +import { useParams } from "react-router-dom"; +import List from "../componets/List"; + +const Lists = ({ data, tags, lists, SetLoader, lightMode, reFetch }) => { + const { listId } = useParams(); + const dataWithMatchingTag = data.filter((e) => { + return e.list.includes(listId); + }); + + return ( +
+ +
+ ); +}; + +export default Lists; diff --git a/src/routes/Tags.js b/src/routes/Tags.js index d2f8fee..e15288f 100644 --- a/src/routes/Tags.js +++ b/src/routes/Tags.js @@ -1,7 +1,7 @@ import { useParams } from "react-router-dom"; import List from "../componets/List"; -const Tags = ({ data, tags, SetLoader, lightMode, reFetch }) => { +const Tags = ({ data, tags, lists, SetLoader, lightMode, reFetch }) => { const { tagId } = useParams(); const dataWithMatchingTag = data.filter((e) => { return e.tag.includes(tagId); @@ -13,6 +13,7 @@ const Tags = ({ data, tags, SetLoader, lightMode, reFetch }) => { lightMode={lightMode} data={dataWithMatchingTag} tags={tags} + lists={lists} SetLoader={SetLoader} reFetch={reFetch} /> diff --git a/src/styles/SideBar.css b/src/styles/SideBar.css index 219396e..5e9dd4d 100644 --- a/src/styles/SideBar.css +++ b/src/styles/SideBar.css @@ -46,4 +46,4 @@ .pro-inner-item { margin-bottom: 10px; -} \ No newline at end of file +}