* handle client boot error in loading screen * use sync state hook in client root * add loading screen options * removed extra condition in loading finish * add sync connection status bar
31 lines
827 B
JavaScript
31 lines
827 B
JavaScript
/* eslint-disable import/prefer-default-export */
|
|
import { useState, useEffect } from 'react';
|
|
import { useMatrixClient } from './useMatrixClient';
|
|
|
|
export function useDeviceList() {
|
|
const mx = useMatrixClient();
|
|
const [deviceList, setDeviceList] = useState(null);
|
|
|
|
useEffect(() => {
|
|
let isMounted = true;
|
|
|
|
const updateDevices = () => mx.getDevices().then((data) => {
|
|
if (!isMounted) return;
|
|
setDeviceList(data.devices || []);
|
|
});
|
|
updateDevices();
|
|
|
|
const handleDevicesUpdate = (users) => {
|
|
if (users.includes(mx.getUserId())) {
|
|
updateDevices();
|
|
}
|
|
};
|
|
|
|
mx.on('crypto.devicesUpdated', handleDevicesUpdate);
|
|
return () => {
|
|
mx.removeListener('crypto.devicesUpdated', handleDevicesUpdate);
|
|
isMounted = false;
|
|
};
|
|
}, [mx]);
|
|
return deviceList;
|
|
}
|