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);
|
const LOG = Logger.create(__filename, electronConsole);
|
||||||
|
|
||||||
import { ReactNode, useEffect } from 'react';
|
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 { Changes, Channel, GuildMetadata, Member, Message, Resource, ShouldNeverHappenError, Token } from '../../data-types';
|
||||||
import CombinedGuild from '../../guild-combined';
|
import CombinedGuild from '../../guild-combined';
|
||||||
import GuildsManager from '../../guilds-manager';
|
import GuildsManager from '../../guilds-manager';
|
||||||
@ -449,17 +449,22 @@ export function useRecoilValueSoftImgSrc(recoilValue: RecoilValue<string>): stri
|
|||||||
export function useInitRecoil(guildsManager: GuildsManager) {
|
export function useInitRecoil(guildsManager: GuildsManager) {
|
||||||
const setGuildsManager = useSetRecoilState(guildsManagerState);
|
const setGuildsManager = useSetRecoilState(guildsManagerState);
|
||||||
const setGuilds = useSetRecoilState(allGuildsState);
|
const setGuilds = useSetRecoilState(allGuildsState);
|
||||||
|
const [currGuildId, setCurrGuildId] = useRecoilState(currGuildIdState);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setGuildsManager(guildsManager);
|
setGuildsManager(guildsManager);
|
||||||
}, [guildsManager, setGuildsManager]);
|
}, [guildsManager, setGuildsManager]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateGuilds = () => {
|
const updateGuilds = () => {
|
||||||
setGuilds(guildsManager.guilds.slice());
|
setGuilds(guildsManager.guilds.slice());
|
||||||
|
if (guildsManager.guilds.length > 0 && currGuildId === null) {
|
||||||
|
const firstGuild = guildsManager.guilds[0] as CombinedGuild;
|
||||||
|
setCurrGuildId(firstGuild.id);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
updateGuilds();
|
updateGuilds();
|
||||||
guildsManager.on('update-guilds', updateGuilds);
|
guildsManager.on('update-guilds', updateGuilds);
|
||||||
return () => {
|
return () => {
|
||||||
guildsManager.off('update-guilds', updateGuilds);
|
guildsManager.off('update-guilds', updateGuilds);
|
||||||
};
|
};
|
||||||
}, [guildsManager, setGuilds]);
|
}, [guildsManager, setGuilds, currGuildId, setCurrGuildId]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user