forked from Ivasoft/mattermost-mobile
* Improvements on channel switch performance * Revert removal from channel observables * Fix team switch dependancies * Fix lint * Use events to signal channel switch * Add check for hasMembership * Address feedback * add useTeamSwitch hook * Fix team switch perceived performance on tablets * align custom status in channel list Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
34 lines
975 B
TypeScript
34 lines
975 B
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {useEffect, useState} from 'react';
|
|
import {DeviceEventEmitter} from 'react-native';
|
|
|
|
import {Events} from '@constants';
|
|
|
|
export const useTeamSwitch = () => {
|
|
const [loading, setLoading] = useState(false);
|
|
useEffect(() => {
|
|
let time: NodeJS.Timeout | undefined;
|
|
const l = DeviceEventEmitter.addListener(Events.TEAM_SWITCH, (switching: boolean) => {
|
|
if (time) {
|
|
clearTimeout(time);
|
|
}
|
|
if (switching) {
|
|
setLoading(true);
|
|
} else {
|
|
// eslint-disable-next-line max-nested-callbacks
|
|
time = setTimeout(() => setLoading(false), 200);
|
|
}
|
|
});
|
|
return () => {
|
|
l.remove();
|
|
if (time) {
|
|
clearTimeout(time);
|
|
}
|
|
};
|
|
}, []);
|
|
|
|
return loading;
|
|
};
|