Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | 13x 106x 106x 106x 106x 2x 106x 31x 106x 10x 10x 10x 106x 10x 7x 10x | import { useState } from "react";
import { useStores } from "~/hooks/useStores";
import ArchivedDevicesModal from "./ArchivedDevicesModal";
import {
MdDarkMode,
MdLightMode,
MdOutlineZoomInMap,
MdOutlineZoomOutMap,
} from "react-icons/md";
import { IoIosArrowDropdownCircle } from "react-icons/io";
export const Sidebar = () => {
const { theme, fontScale, auth } = useStores();
const [isHiddenDevicesOpen, setIsHiddenDevicesOpen] = useState(false);
const [isPreferencesOpen, setIsPreferencesOpen] = useState(false);
const handleLogout = () => {
auth.revoke();
};
const handlePreferencesToggle = () => {
setIsPreferencesOpen(!isPreferencesOpen);
};
const handleKeyDown = (
event: React.KeyboardEvent<HTMLButtonElement>,
callback: () => void,
) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
callback();
}
};
return (
<div className="drawer-side z-30" data-cy="drawer-side">
<label
htmlFor="menu-drawer"
aria-label="close sidebar"
className="drawer-overlay w-full h-full z-20"
data-cy="drawer-overlay"
></label>
<nav
className="menu bg-base-100 text-base-content min-h-full w-80 px-8 gap-4 flex justify-center z-30"
data-cy="sidebar-menu"
role="navigation"
aria-label="Settings navigation"
>
{/* Settings Header */}
<div className="p-4 font-bold text-xl flex justify-center text-accent">
<h1 id="settings-heading">Settings</h1>
</div>
{/* Hidden Devices Section */}
<div role="group" aria-labelledby="settings-heading">
<button
className="btn btn-outline w-full text-base-content hover:bg-base-300 px-4"
onClick={() => setIsHiddenDevicesOpen(true)}
aria-describedby="hidden-devices-desc"
>
Hidden Devices
</button>
<div id="hidden-devices-desc" className="sr-only">
View and manage devices that have been hidden from the
main view
</div>
</div>
<ArchivedDevicesModal
isOpen={isHiddenDevicesOpen}
onClose={() => setIsHiddenDevicesOpen(false)}
/>
{/* Preferences Section */}
<div role="group" aria-labelledby="preferences-heading">
<button
className="btn btn-ghost flex justify-between items-center text-base-content hover:bg-base-300 w-full"
onClick={handlePreferencesToggle}
onKeyDown={(e) =>
handleKeyDown(e, handlePreferencesToggle)
}
aria-expanded={isPreferencesOpen}
aria-controls="preferences-content"
aria-describedby="preferences-desc"
>
<span className="flex items-center gap-1 justify-center min-w-[100%]">
<span id="preferences-heading">Preferences</span>
<IoIosArrowDropdownCircle
aria-hidden="true"
className={`transition-transform ${
isPreferencesOpen ? "rotate-180" : ""
}`}
/>
</span>
</button>
<div id="preferences-desc" className="sr-only">
Expand to access appearance and display preferences
</div>
{/* Preferences Content */}
{isPreferencesOpen && (
<div
id="preferences-content"
role="group"
aria-labelledby="preferences-heading"
className="mt-2"
>
{/* Theme Toggle */}
<button
onClick={theme.toggle}
onKeyDown={(e) =>
handleKeyDown(e, theme.toggle)
}
className="flex justify-between items-center p-2 rounded-md text-base-content hover:bg-base-300 w-full"
data-cy="theme-toggle"
aria-pressed={theme.isLight ? "false" : "true"}
aria-describedby="theme-desc"
>
<span>Appearance</span>
{theme.isLight ? (
<MdDarkMode
className="text-accent"
aria-label="Switch to dark mode"
/>
) : (
<MdLightMode
className="text-accent"
aria-label="Switch to light mode"
/>
)}
</button>
<div id="theme-desc" className="sr-only">
Currently using{" "}
{theme.isLight ? "light" : "dark"} theme. Click
to switch to {theme.isLight ? "dark" : "light"}{" "}
theme.
</div>
{/* Font Scale Toggle */}
<button
onClick={fontScale.toggle}
onKeyDown={(e) =>
handleKeyDown(e, fontScale.toggle)
}
className="flex justify-between items-center p-2 rounded-md text-base-content hover:bg-base-300 w-full"
data-cy="fontScale-toggle"
aria-pressed={
fontScale.isLargeFont ? "true" : "false"
}
aria-describedby="font-scale-desc"
>
<span>
{fontScale.isLargeFont
? "Zoom Out"
: "Zoom In"}
</span>
{fontScale.isLargeFont ? (
<MdOutlineZoomOutMap
className="text-accent"
aria-label="Decrease font size"
/>
) : (
<MdOutlineZoomInMap
className="text-accent"
aria-label="Increase font size"
/>
)}
</button>
<div id="font-scale-desc" className="sr-only">
Font size is currently{" "}
{fontScale.isLargeFont ? "large" : "normal"}.
Click to{" "}
{fontScale.isLargeFont
? "decrease"
: "increase"}{" "}
font size.
</div>
{/* Commented Dyslexic mode switch - maintaining original structure */}
{/**<button
onClick={toggleDyslexicMode}
onKeyDown={(e) => handleKeyDown(e, toggleDyslexicMode)}
className="flex justify-between items-center p-2 rounded-md text-base-content hover:bg-base-300 w-full"
data-cy="dyslexic-toggle"
aria-pressed={isDyslexic ? "true" : "false"}
aria-describedby="dyslexic-desc"
>
<span>Readability Mode</span>
{isDyslexic ? (
<FaBrain className="text-primary" aria-label="Disable readability mode" />
) : (
<RiFontSize className="text-primary" aria-label="Enable readability mode" />
)}
</button>
<div id="dyslexic-desc" className="sr-only">
Readability mode is currently {isDyslexic ? 'enabled' : 'disabled'}. Click to {isDyslexic ? 'disable' : 'enable'} readability mode for better text readability.
</div>**/}
</div>
)}
</div>
<div className="my-4" aria-hidden="true"></div>
{/* Logout Button */}
{auth && (
<div role="group" aria-label="Account actions">
<button
onClick={handleLogout}
onKeyDown={(e) => handleKeyDown(e, handleLogout)}
className="btn btn-outline btn-accent text-accent hover:bg-error hover:text-white w-[95%]"
aria-describedby="logout-desc"
>
Sign out
</button>
<div id="logout-desc" className="sr-only">
Sign out of your current session and return to the
login page
</div>
</div>
)}
</nav>
</div>
);
};
|