sidebar item dispatches
This commit is contained in:
@@ -97,7 +97,7 @@
|
|||||||
.sidebar {
|
.sidebar {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: 12rem;
|
width: 13.5rem;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
color: white;
|
color: white;
|
||||||
|
|||||||
@@ -20,6 +20,14 @@
|
|||||||
margin: 0.8rem 0;
|
margin: 0.8rem 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.individual-sub button {
|
||||||
|
margin-right: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.individual-sub label {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
.search-sub-input {
|
.search-sub-input {
|
||||||
margin-top: 2rem;
|
margin-top: 2rem;
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,17 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
// import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
// import { updateSubVisibility } from "../reddit/redditSlice";
|
import { updateSubVisibility } from "../reddit/redditSlice";
|
||||||
|
|
||||||
export default function SidebarItem({sub}) {
|
export default function SidebarItem({sub}) {
|
||||||
const [visible, setVisible] = useState('hide'); // dispatch will be used to dispatch updateSubVisibility on change in state
|
const dispatch = useDispatch();
|
||||||
// const dispatch = useDispatch(); // this will likely be within a useEffect hook
|
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
if (visible === 'hide') {
|
dispatch(updateSubVisibility(sub));
|
||||||
setVisible('show');
|
|
||||||
} else if (visible === 'show') {
|
|
||||||
setVisible('hide');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="individual-sub">
|
<div className="individual-sub">
|
||||||
{/* <input type="checkbox" id={sub} checked={checked} onChange={handleClick}></input> */}
|
<button id={sub} onClick={handleClick}>toggle</button>
|
||||||
<button id={sub} onClick={handleClick}>{visible}</button>
|
|
||||||
<label id={sub}>{sub}</label>
|
<label id={sub}>{sub}</label>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user