minor bugs in new guild stuff

This commit is contained in:
Michael Peters 2021-12-27 22:40:58 -06:00
parent 579050e867
commit 7136fbfb0b
3 changed files with 26 additions and 15 deletions

View File

@ -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<GuildTitleProps> = (props: GuildTitleProps) => {
const rootRef = useRef<HTMLDivElement>(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<GuildTitleProps> = (props: GuildTitleProps) => {
);
}, [ guild, guildMeta, selfMember, rootRef ]);
const nameStyle = useMemo(() => {
if (hasContextMenu) {
return { cursor: 'pointer' };
} else {
return undefined;
}
}, [ hasContextMenu ]);
return (
<div className="guild-title" ref={rootRef}>
<div className="guild-name-container" onClick={toggleContextMenu}>
<div className="guild-name-container" style={nameStyle} onClick={hasContextMenu ? toggleContextMenu : undefined}>
<span className="guild-name">{guildMeta?.name ?? null}</span>
</div>
{contextMenu}

View File

@ -20,6 +20,7 @@ const GuildElement: FC<GuildElementProps> = (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<GuildElementProps> = (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 ]);

View File

@ -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<Token>) => {
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)
});
})();
});