select first guild by default
This commit is contained in:
parent
c1e669f697
commit
515738ae41
@ -4,7 +4,7 @@ import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { ReactNode, useEffect } from 'react';
|
||||
import { atom, atomFamily, GetRecoilValue, RecoilState, RecoilValue, RecoilValueReadOnly, selector, selectorFamily, useSetRecoilState } from 'recoil';
|
||||
import { atom, atomFamily, GetRecoilValue, RecoilState, RecoilValue, RecoilValueReadOnly, selector, selectorFamily, useRecoilState, useSetRecoilState } from 'recoil';
|
||||
import { Changes, Channel, GuildMetadata, Member, Message, Resource, ShouldNeverHappenError, Token } from '../../data-types';
|
||||
import CombinedGuild from '../../guild-combined';
|
||||
import GuildsManager from '../../guilds-manager';
|
||||
@ -449,17 +449,22 @@ export function useRecoilValueSoftImgSrc(recoilValue: RecoilValue<string>): stri
|
||||
export function useInitRecoil(guildsManager: GuildsManager) {
|
||||
const setGuildsManager = useSetRecoilState(guildsManagerState);
|
||||
const setGuilds = useSetRecoilState(allGuildsState);
|
||||
const [currGuildId, setCurrGuildId] = useRecoilState(currGuildIdState);
|
||||
useEffect(() => {
|
||||
setGuildsManager(guildsManager);
|
||||
}, [guildsManager, setGuildsManager]);
|
||||
useEffect(() => {
|
||||
const updateGuilds = () => {
|
||||
setGuilds(guildsManager.guilds.slice());
|
||||
if (guildsManager.guilds.length > 0 && currGuildId === null) {
|
||||
const firstGuild = guildsManager.guilds[0] as CombinedGuild;
|
||||
setCurrGuildId(firstGuild.id);
|
||||
}
|
||||
};
|
||||
updateGuilds();
|
||||
guildsManager.on('update-guilds', updateGuilds);
|
||||
return () => {
|
||||
guildsManager.off('update-guilds', updateGuilds);
|
||||
};
|
||||
}, [guildsManager, setGuilds]);
|
||||
}, [guildsManager, setGuilds, currGuildId, setCurrGuildId]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user