From 515738ae413c06fbe72e41c049189ffe5a90613e Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Tue, 8 Feb 2022 22:03:52 -0600 Subject: [PATCH] select first guild by default --- src/client/webapp/elements/require/atoms.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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]); }