Skip to content

Commit

Permalink
fixed frontend login authentication progress problem
Browse files Browse the repository at this point in the history
  • Loading branch information
euzu committed Jan 7, 2022
1 parent c9a754e commit 4915ae6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--- # config
log:
level: debug
file: 'hanectl.log'
Expand Down
1 change: 1 addition & 0 deletions config/devices.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--- # devices
devices:
- type: light
device_key: licht-arbeitszimmer
Expand Down
1 change: 1 addition & 0 deletions config/notifications.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--- # notifications
notifications:
- device_key: socket-washer
trigger: change
Expand Down
15 changes: 8 additions & 7 deletions frontend/src/component/auth/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function Authenticator(params: AuthenticatorParams) {
const services = useServices();
const [progress, setProgress] = useState(true);
const [authenticated, setAuthenticated] = useState(false);
const [children, setChildren] = useState(null);
const [content, setContent] = useState(null);

useEffect(() => {
const sub = services.auth().authenticated().subscribe({
Expand All @@ -23,24 +23,25 @@ export default function Authenticator(params: AuthenticatorParams) {
setProgress(val => false);
}
});
return sub.unsubscribe();
return () => sub.unsubscribe();
}, [services]);

useEffect(() => {
const subs = services.auth().isAuthenticated().subscribe((val: boolean) => {
setAuthenticated(() => val);
if(val && children === null) {
setChildren(() => factory());
if(val && content === null) {
setContent(() => factory());
}
setProgress(!val);
setAuthenticated(() => val);
});
return () => subs.unsubscribe();
}, [services, factory, children]);
}, [services, factory, content]);

if (progress) {
return <Spinner loading={progress}/>;
}
if (authenticated) {
return children;
return content;
}
return <Login/>
}
8 changes: 5 additions & 3 deletions frontend/src/component/devices/devices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export default function Devices(params: DevicesProperties) {
const setRoomsConfig = useMemo(() => (roomsCfg: IRoomConfig, devCfg: IDeviceConfig) => {
const newRooms = DevicesUtils.createRooms(roomsCfg, devCfg);
const tabsDef = DevicesUtils.createTabsetDef(newRooms);
let tabs: React.ReactNode;
let roomTabs: React.ReactNode;
if (tabsDef && tabsDef.length) {
tabs =
roomTabs =
<TabSet ref={tabsetRef} index={tabIndex} tabs={tabsDef} rolling={true} onChange={changeTabIndex}/>
}
setRooms(() => newRooms)
setTabs(() => tabs);
setTabs(() => roomTabs);
}, [changeTabIndex, tabIndex]);


Expand Down Expand Up @@ -117,6 +117,8 @@ export default function Devices(params: DevicesProperties) {
...DevicesUtils.swipeOptions,
});

console.log('dev', devicesConfig?.devices);

return <div className={"devices-container"} {...handlers}>
<div className={"tabs-panel"}>{tabs}</div>
<div className={"devices-panel"} {...handlers}>
Expand Down

0 comments on commit 4915ae6

Please sign in to comment.