diff --git a/src/client/webapp/elements/require/atoms.ts b/src/client/webapp/elements/require/atoms.ts index 7982e80..d04f47b 100644 --- a/src/client/webapp/elements/require/atoms.ts +++ b/src/client/webapp/elements/require/atoms.ts @@ -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): 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]); }