Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
🐛 Fix LightsController bug
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlevay committed Oct 7, 2023
1 parent 1bd70d1 commit e4084fd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 0 additions & 2 deletions frontend/components/Home/Widgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import EventSet from '../Calendar/UpcomingEventSet';
import Link from '../Link';
import ArticleSet from '../News/articleSet';
import DisplayMeeting from './DisplayMeeting';
import LightsController from '../LightsController';

export default function Widgets() {
const { t } = useTranslation(['homePage']);
Expand All @@ -21,7 +20,6 @@ export default function Widgets() {
<Typography variant="h4" color="secondary">{t('homePage:upcoming_events')}</Typography>
<EventSet perPage={4} small />
<Link href={routes.calendar}>{t('homePage:to_calendar')}</Link>
<LightsController />
</Stack>
<Stack width="100%" spacing={2}>
<Typography variant="h4" color="primary">{t('homePage:prev_meeting')}</Typography>
Expand Down
18 changes: 9 additions & 9 deletions frontend/components/LightsController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default function LightsController() {
const [hsva, setHsva] = useState({
h: 0, s: 0, v: 100, a: 1,
});
const [lightUp, setLightUp] = useState(DEFAULT_UP);
const [lightDown, setLightDown] = useState(DEFAULT_DOWN);
const [whiteUp, setWhiteUp] = useState(DEFAULT_UP);
const [whiteDown, setWhiteDown] = useState(DEFAULT_DOWN);
const [loaded, setLoaded] = useState(false);
const { hasAccess } = useApiAccess();

Expand All @@ -38,8 +38,8 @@ export default function LightsController() {
red,
green,
blue,
light_up: lightUp,
light_down: lightDown,
white_up: whiteUp,
white_down: whiteDown,
authToken: session?.accessToken,
};
const response = await fetch('/api/lights', {
Expand All @@ -51,7 +51,7 @@ export default function LightsController() {
setStatus(json.status);
setError(!json.sent);
}
}, [hsva, lightUp, lightDown, session?.accessToken]);
}, [hsva, whiteUp, whiteDown, session?.accessToken]);

const debouncedOnChange = useMemo(
() => debounce(onChange, 300),
Expand All @@ -65,7 +65,7 @@ export default function LightsController() {
setLoaded(true);
}
return debouncedOnChange.cancel;
}, [hsva, lightUp, lightDown]);
}, [hsva, whiteUp, whiteDown]);

Check warning on line 68 in frontend/components/LightsController.tsx

View workflow job for this annotation

GitHub Actions / linter_check

React Hook useEffect has missing dependencies: 'debouncedOnChange' and 'loaded'. Either include them or remove the dependency array

if (!hasAccess('lights:change')) {
return null;
Expand Down Expand Up @@ -96,8 +96,8 @@ export default function LightsController() {
>
<PageHeader>över baren</PageHeader>
<Slider
value={lightUp}
onChange={(e, value) => setLightUp(value as number)}
value={whiteUp}
onChange={(e, value) => setWhiteUp(value as number)}
aria-label="Default"
valueLabelDisplay="auto"
/>
Expand All @@ -112,7 +112,7 @@ export default function LightsController() {
defaultValue={DEFAULT_DOWN}
onChange={(e, value) => {
setTimeout(() => {
setLightDown(value as number);
setWhiteDown(value as number);
}, 100);
}}
orientation="vertical"
Expand Down
5 changes: 5 additions & 0 deletions frontend/pages/api/lights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (response.ok) {
status = 'Successfully updated lights';
sent = true;
} else {
status = 'Failed to update lights';
sent = false;
const text = await response.text();
console.error(text);
}
} else {
throw new Error('Not sending to blajt in development');
Expand Down

0 comments on commit e4084fd

Please sign in to comment.