| Conditions | 3 |
| Total Lines | 61 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import { useSelector } from 'react-redux'; |
||
| 12 | |||
| 13 | export default function Header() { |
||
| 14 | |||
| 15 | const {isLoggedIn, token, user, role} = useSelector((state: RootState) => state.auth); |
||
| 16 | |||
| 17 | |||
| 18 | const getAuthStatus = async () => { |
||
| 19 | const response = await axios.get(`${API_URL}/auth/status`, getHeader(token)); |
||
| 20 | console.log(response); |
||
| 21 | } |
||
| 22 | |||
| 23 | const getAuthMe = async () => { |
||
| 24 | const response = await axios.get(`${API_URL}/auth/me`, getHeader(token)); |
||
| 25 | console.log(response); |
||
| 26 | } |
||
| 27 | |||
| 28 | return ( |
||
| 29 | <> |
||
| 30 | <Navbar fluid rounded> |
||
| 31 | |||
| 32 | <Navbar.Brand as={Link} to="/"> |
||
| 33 | <img src={logo} className="h-8" alt="Logo" /> |
||
| 34 | <span className="self-center text-2xl font-semibold whitespace-nowrap dark:text-white">Hemåt</span> |
||
| 35 | </Navbar.Brand> |
||
| 36 | <Navbar.Toggle /> |
||
| 37 | |||
| 38 | <Navbar.Collapse> |
||
| 39 | <Navbar.Link as={Link} to="/"> |
||
| 40 | Home |
||
| 41 | </Navbar.Link> |
||
| 42 | { role =="admin" && <Navbar.Link as={Link} to="/adminstartpage">Adminsida</Navbar.Link>} |
||
| 43 | { isLoggedIn && |
||
| 44 | <> |
||
| 45 | <Navbar.Link as={Link} to="/customerstartpage">Kundsida</Navbar.Link> |
||
| 46 | <Logout className="px-1 py-0.5" size="xs"></Logout> |
||
| 47 | </> |
||
| 48 | } |
||
| 49 | { |
||
| 50 | !isLoggedIn && |
||
| 51 | <Login className="px-1 py-0.5" size="xs"/> |
||
| 52 | } |
||
| 53 | </Navbar.Collapse> |
||
| 54 | </Navbar> |
||
| 55 | |||
| 56 | <div className='flex justify-center items-center'> |
||
| 57 | <div className="text-xs block max-w-sm p-6 h-40 overflow-scroll bg-white border border-gray-200 rounded-lg shadow"> |
||
| 58 | |||
| 59 | <p className="text-gray-700 dark:text-gray-400">Logged In: <b>{isLoggedIn.toString()}</b></p> |
||
| 60 | <p className="text-gray-700 dark:text-gray-400">Role: <b>{role}</b></p> |
||
| 61 | <p className="text-gray-700 dark:text-gray-400">User: <b>{user ? JSON.stringify(user) : "No User"}</b></p> |
||
| 62 | <Popover aria-labelledby="default-popover" content={<p>{token ? token : "Empty"} </p>}> |
||
| 63 | <Button color="warning" size="xs" onClick={() => console.log(token)}>Klicka här för token</Button> |
||
| 64 | </Popover> |
||
| 65 | |||
| 66 | |||
| 67 | <Button color="warning" size="xs" onClick={getAuthStatus}>Prompt auth/status in console</Button> |
||
| 68 | <Button color="warning" size="xs" onClick={getAuthMe}>Prompt auth/me in console</Button> |
||
| 69 | </div> |
||
| 70 | </div> |
||
| 71 | |||
| 72 | </> |
||
| 73 | ) |
||
| 75 |