forked from Ivasoft/mattermost-mobile
* Improve loading display name of direct channels * Improve team switching * Improve perceived performance when opening the app with an active session * Fix upgrade path from v1 * Set moment locale while formatting date * feedback review
34 lines
973 B
TypeScript
34 lines
973 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), 0);
|
|
}
|
|
});
|
|
return () => {
|
|
l.remove();
|
|
if (time) {
|
|
clearTimeout(time);
|
|
}
|
|
};
|
|
}, []);
|
|
|
|
return loading;
|
|
};
|