From 7136fbfb0b86f5e9036137e7991412ccc1d136c5 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Mon, 27 Dec 2021 22:40:58 -0600 Subject: [PATCH] minor bugs in new guild stuff --- .../webapp/elements/sections/guild-title.tsx | 22 +++++++++++++++++-- src/client/webapp/elements/sections/guild.tsx | 5 +++++ src/client/webapp/preload.ts | 14 +----------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/client/webapp/elements/sections/guild-title.tsx b/src/client/webapp/elements/sections/guild-title.tsx index bd0b7a9..c54e1fa 100644 --- a/src/client/webapp/elements/sections/guild-title.tsx +++ b/src/client/webapp/elements/sections/guild-title.tsx @@ -1,4 +1,4 @@ -import React, { FC, useRef } from 'react'; +import React, { FC, useMemo, useRef } from 'react'; import { GuildMetadata, Member } from '../../data-types'; import CombinedGuild from '../../guild-combined'; import GuildTitleContextMenu from '../contexts/context-menu-guild-title'; @@ -15,6 +15,16 @@ const GuildTitle: FC = (props: GuildTitleProps) => { const rootRef = useRef(null); + const hasContextMenu = useMemo(() => { + return ( + selfMember && + ( + selfMember.privileges.includes('modify_profile') || + selfMember.privileges.includes('modify_channels') + ) + ); + }, [ selfMember ]); + const [ contextMenu, toggleContextMenu ] = ReactHelper.useContextMenu((close: () => void) => { if (!guildMeta) return null; if (!selfMember) return null; @@ -26,9 +36,17 @@ const GuildTitle: FC = (props: GuildTitleProps) => { ); }, [ guild, guildMeta, selfMember, rootRef ]); + const nameStyle = useMemo(() => { + if (hasContextMenu) { + return { cursor: 'pointer' }; + } else { + return undefined; + } + }, [ hasContextMenu ]); + return (
-
+
{guildMeta?.name ?? null}
{contextMenu} diff --git a/src/client/webapp/elements/sections/guild.tsx b/src/client/webapp/elements/sections/guild.tsx index b11b2e9..d8cd09c 100644 --- a/src/client/webapp/elements/sections/guild.tsx +++ b/src/client/webapp/elements/sections/guild.tsx @@ -20,6 +20,7 @@ const GuildElement: FC = (props: GuildElementProps) => { // TODO: Handle fetch errors by allowing for retry // TODO: Handle fetch errors in message list // TODO: React set hasMessagesAbove and hasMessagesBelow when re-verified? + // TODO: React jump messages to bottom when the current user sent a message const [ selfMember ] = GuildSubscriptions.useSelfMemberSubscription(guild); const [ guildMeta, guildMetaFetchError ] = GuildSubscriptions.useGuildMetadataSubscription(guild); @@ -30,9 +31,13 @@ const GuildElement: FC = (props: GuildElementProps) => { useEffect(() => { if (activeChannel === null) { + // initial active channel is the first one in the list if (channels && channels.length > 0) { setActiveChannel(channels[0] as Channel); } + } else if (channels && activeChannel) { + // in the active channel was updated + setActiveChannel(channels.find(channel => channel.id === activeChannel.id) ?? null); } }, [ channels, activeChannel ]); diff --git a/src/client/webapp/preload.ts b/src/client/webapp/preload.ts index c542bd9..6fad0d8 100644 --- a/src/client/webapp/preload.ts +++ b/src/client/webapp/preload.ts @@ -13,7 +13,7 @@ import GuildsManager from './guilds-manager'; import Globals from './globals'; import UI from './ui'; -import { Changes, GuildMetadata, Member, Resource, Token } from './data-types'; +import { Changes, GuildMetadata, Resource, Token } from './data-types'; import Q from './q-module'; import bindWindowButtonEvents from './elements/events-window-buttons'; import bindAddGuildEvents from './elements/events-add-guild'; @@ -99,8 +99,6 @@ window.addEventListener('DOMContentLoaded', () => { } }); - // TODO: React jump messages to bottom when the current user sent a message - // Conflict Events guildsManager.on('conflict-metadata', async (guild: CombinedGuild, changesType: AutoVerifierChangesType, oldGuildMeta: GuildMetadata, newGuildMeta: GuildMetadata) => { @@ -110,16 +108,6 @@ window.addEventListener('DOMContentLoaded', () => { await ui.updateGuildIcon(guild, icon.data); })(); }); - - guildsManager.on('conflict-tokens', async (guild: CombinedGuild, changesType: AutoVerifierChangesType, changes: Changes) => { - LOG.debug('tokens conflict', { changes }); - // TODO - }); - - guildsManager.on('conflict-resource', async (guild: CombinedGuild, query: IDQuery, changesType: AutoVerifierChangesType, oldResource: Resource, newResource: Resource) => { - LOG.debug('resource conflict', { oldResource, newResource }); - // TODO (these changes should not happen often if at all) - }); })(); });