wrench-project / eduwrench

eduWRENCH Pedagogic Modules - Parallel and Distributed Computing Courseware
https://eduwrench.org
GNU General Public License v3.0
6 stars 3 forks source link

Make it easy/clean to hide content when a user is not logged on #112

Closed henricasanova closed 2 years ago

henricasanova commented 2 years ago

Implement a simple "hide if not logged on" component.

derrickluyen commented 2 years ago

auth: bool returning true / false depending on if user is logged in or not

data: the content to be hidden

content: the type of content being hidden, passed as a string (e.g. "simulator", "practice questions", etc...)

Import:

import SigninCheck from '../../../components/signin_check'

To include at beginning of class / component (check if user is logged in):

    const [auth, setAuth] = useState("false")

    useEffect(() => {
      setAuth(localStorage.getItem("login"))
    })

Two ways to use component:

  1. pass in data as giant "div" so that it is essentially treated as one item (square bracket inside data is not necessary in this case)
<SigninCheck data={[
            <>
              <x
                ...
              />

              <y
                ...
              />

              <z
                ...
              />
            </>
            ]} auth={auth} content="practice questions"></SigninCheck>
  1. pass in data as array of components (square bracket inside data is necessary in this case)
<SigninCheck data={[
              <x
                ...
              />,

              <y
                ...
              />,

              <z
                ...
              />
            ]} auth={auth} content="practice questions"></SigninCheck>
henricasanova commented 2 years ago

Used throughout the whole site successfully.