posted at {time ? (localTime + ' on ' + localDate) : '...?'}
{comments ? comments : 'no'} comments
+
>
);
diff --git a/src/features/posts/postsSlice.js b/src/features/posts/postsSlice.js
index e5edaae..2ef0e54 100644
--- a/src/features/posts/postsSlice.js
+++ b/src/features/posts/postsSlice.js
@@ -52,5 +52,4 @@ export const postsSlice = createSlice({
export default postsSlice.reducer;
export const selectPosts = state => state.postsSlice.posts;
export const { filterPosts, updatePosts } = postsSlice.actions;
-// exports also includes fetchBySub (takes argument of a sub)
-// exports also includes fetchFromAll (takes argument of an array of subs)
\ No newline at end of file
+// exports also includes fetchBySub (takes argument of a sub)
\ No newline at end of file
diff --git a/src/features/reddit/redditSlice.js b/src/features/reddit/redditSlice.js
index 6ea3ab4..adc9cba 100644
--- a/src/features/reddit/redditSlice.js
+++ b/src/features/reddit/redditSlice.js
@@ -64,9 +64,8 @@ export const redditSlice = createSlice({
},
},
reducers: {
- updateSubVisibility(state,action) {
- // reads state of buttons in Sidebar component to determine whether each is active
- // connects with post rendering, filtering out posts belonging to inactive subreddits
+ updateSubVisibility(state,action) { // receives a subreddit name as action.payload
+ state.subreddits[action.payload].isSelected = !state.subreddits[action.payload].isSelected;
}
},
extraReducers: {},
@@ -74,4 +73,15 @@ export const redditSlice = createSlice({
export default redditSlice.reducer;
export const selectAllSubs = state => state.redditSlice.subreddits;
+export const selectActiveSubs = state => {
+ let activeSubs = [];
+ for (let it in state.redditSlice.subreddits) {
+ if (it.isSelected) {
+ activeSubs.push(it);
+ } else {
+ continue;
+ }
+ }
+ return activeSubs;
+}
export const { updateSubVisibility } = redditSlice.actions;
\ No newline at end of file
diff --git a/src/features/sidebar/Sidebar.js b/src/features/sidebar/Sidebar.js
index 48ba589..0bb5e8e 100644
--- a/src/features/sidebar/Sidebar.js
+++ b/src/features/sidebar/Sidebar.js
@@ -1,9 +1,11 @@
import React, { useRef, useState } from "react";
-import { useSelector } from "react-redux";
+import { useSelector, useDispatch } from "react-redux";
import { selectAllSubs } from "../reddit/redditSlice";
+import SidebarItem from "./SidebarItem";
import './Sidebar.css';
export default function Sidebar({isCollapsed}) {
+ const dispatch = useDispatch();
const allSubs = useSelector(selectAllSubs);
let arrayOfSubs = Object.keys(allSubs);
@@ -24,16 +26,17 @@ export default function Sidebar({isCollapsed}) {
}
}
+ const handleClick = (e) => {
+
+ }
+
return (
<>
{/* Is collapsed is passed from the parent component, and is mutable within the navbar */}
{
subs.map((sub) => { // Maps each sub to its own line within the sidebar, along with a button that toggles its "isSelected" property
return (
-
- {/* This button will dispatch an action to change the state of this specific subreddit */}
-