mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 07:26:19 +00:00
🆙 Init V3
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { AddLinkEventTracker, GroupPurchasedEvent, GroupSettingsComposer, ILinkEventTracker, RemoveLinkEventTracker } from '@nitrots/nitro-renderer';
|
||||
import { FC, useEffect, useState } from 'react';
|
||||
import { SendMessageComposer, TryVisitRoom } from '../../api';
|
||||
import { useGroup, useMessageEvent } from '../../hooks';
|
||||
import { GroupCreatorView } from './views/GroupCreatorView';
|
||||
import { GroupInformationStandaloneView } from './views/GroupInformationStandaloneView';
|
||||
import { GroupManagerView } from './views/GroupManagerView';
|
||||
import { GroupMembersView } from './views/GroupMembersView';
|
||||
|
||||
export const GroupsView: FC<{}> = props =>
|
||||
{
|
||||
const [ isCreatorVisible, setCreatorVisible ] = useState<boolean>(false);
|
||||
const {} = useGroup();
|
||||
|
||||
useMessageEvent<GroupPurchasedEvent>(GroupPurchasedEvent, event =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
setCreatorVisible(false);
|
||||
TryVisitRoom(parser.roomId);
|
||||
});
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
const linkTracker: ILinkEventTracker = {
|
||||
linkReceived: (url: string) =>
|
||||
{
|
||||
const parts = url.split('/');
|
||||
|
||||
if(parts.length < 2) return;
|
||||
|
||||
switch(parts[1])
|
||||
{
|
||||
case 'create':
|
||||
setCreatorVisible(true);
|
||||
return;
|
||||
case 'manage':
|
||||
if(!parts[2]) return;
|
||||
|
||||
setCreatorVisible(false);
|
||||
SendMessageComposer(new GroupSettingsComposer(Number(parts[2])));
|
||||
return;
|
||||
}
|
||||
},
|
||||
eventUrlPrefix: 'groups/'
|
||||
};
|
||||
|
||||
AddLinkEventTracker(linkTracker);
|
||||
|
||||
return () => RemoveLinkEventTracker(linkTracker);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{ isCreatorVisible &&
|
||||
<GroupCreatorView onClose={ () => setCreatorVisible(false) } /> }
|
||||
{ !isCreatorVisible &&
|
||||
<GroupManagerView /> }
|
||||
<GroupMembersView />
|
||||
<GroupInformationStandaloneView />
|
||||
</>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user