mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-26 23:50:52 +01:00
bill fix this again
This commit is contained in:
parent
5ad80cadca
commit
cf17d152d4
67
src/views/mod-tools/ModToolsMessageHandler.tsx
Normal file
67
src/views/mod-tools/ModToolsMessageHandler.tsx
Normal file
@ -0,0 +1,67 @@
|
||||
import { IssueInfoMessageEvent, ModeratorInitMessageEvent } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback } from 'react';
|
||||
import { CreateMessageHook } from '../../hooks';
|
||||
import { useModToolsContext } from './context/ModToolsContext';
|
||||
import { ModToolsActions } from './reducers/ModToolsReducer';
|
||||
|
||||
export const ModToolsMessageHandler: FC<{}> = props =>
|
||||
{
|
||||
const { modToolsState = null, dispatchModToolsState = null } = useModToolsContext();
|
||||
const { tickets= null } = modToolsState;
|
||||
|
||||
const onModeratorInitMessageEvent = useCallback((event: ModeratorInitMessageEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const data = parser.data;
|
||||
|
||||
dispatchModToolsState({
|
||||
type: ModToolsActions.SET_INIT_DATA,
|
||||
payload: {
|
||||
settings: data
|
||||
}
|
||||
});
|
||||
|
||||
dispatchModToolsState({
|
||||
type: ModToolsActions.SET_TICKETS,
|
||||
payload: {
|
||||
tickets: data.issues
|
||||
}
|
||||
});
|
||||
|
||||
console.log(parser);
|
||||
}, [dispatchModToolsState]);
|
||||
|
||||
const onIssueInfoMessageEvent = useCallback((event: IssueInfoMessageEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const newTickets = tickets ? Array.from(tickets) : [];
|
||||
const existingIndex = newTickets.findIndex( entry => entry.issueId === parser.issueData.issueId)
|
||||
|
||||
if(existingIndex > -1)
|
||||
{
|
||||
newTickets[existingIndex] = parser.issueData;
|
||||
}
|
||||
else
|
||||
{
|
||||
newTickets.push(parser.issueData);
|
||||
}
|
||||
|
||||
dispatchModToolsState({
|
||||
type: ModToolsActions.SET_TICKETS,
|
||||
payload: {
|
||||
tickets: newTickets
|
||||
}
|
||||
})
|
||||
}, [dispatchModToolsState, tickets]);
|
||||
|
||||
CreateMessageHook(ModeratorInitMessageEvent, onModeratorInitMessageEvent);
|
||||
CreateMessageHook(IssueInfoMessageEvent, onIssueInfoMessageEvent);
|
||||
|
||||
return null;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { ModeratorInitMessageEvent, RoomEngineEvent, RoomEngineObjectEvent, RoomObjectCategory } from '@nitrots/nitro-renderer';
|
||||
import { RoomEngineEvent, RoomEngineObjectEvent, RoomObjectCategory } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback, useReducer, useState } from 'react';
|
||||
import { GetRoomSession } from '../../api';
|
||||
import { ModToolsEvent } from '../../events/mod-tools/ModToolsEvent';
|
||||
@ -6,11 +6,11 @@ import { ModToolsOpenRoomChatlogEvent } from '../../events/mod-tools/ModToolsOpe
|
||||
import { ModToolsOpenRoomInfoEvent } from '../../events/mod-tools/ModToolsOpenRoomInfoEvent';
|
||||
import { ModToolsOpenUserChatlogEvent } from '../../events/mod-tools/ModToolsOpenUserChatlogEvent';
|
||||
import { ModToolsOpenUserInfoEvent } from '../../events/mod-tools/ModToolsOpenUserInfoEvent';
|
||||
import { CreateMessageHook } from '../../hooks';
|
||||
import { useRoomEngineEvent } from '../../hooks/events';
|
||||
import { dispatchUiEvent, useUiEvent } from '../../hooks/events/ui/ui-event';
|
||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../layout';
|
||||
import { ModToolsContextProvider } from './context/ModToolsContext';
|
||||
import { ModToolsMessageHandler } from './ModToolsMessageHandler';
|
||||
import { ModToolsViewProps } from './ModToolsView.types';
|
||||
import { initialModTools, ModToolsActions, ModToolsReducer } from './reducers/ModToolsReducer';
|
||||
import { ISelectedUser } from './utils/ISelectedUser';
|
||||
@ -24,7 +24,7 @@ export const ModToolsView: FC<ModToolsViewProps> = props =>
|
||||
{
|
||||
const [ isVisible, setIsVisible ] = useState(false);
|
||||
const [ modToolsState, dispatchModToolsState ] = useReducer(ModToolsReducer, initialModTools);
|
||||
const { currentRoomId = null, openRooms = null, openRoomChatlogs = null, openUserChatlogs = null, openUserInfo = null } = modToolsState;
|
||||
const { currentRoomId = null, openRooms = null, openRoomChatlogs = null, openUserChatlogs = null, openUserInfo = null, tickets = null } = modToolsState;
|
||||
const [ selectedUser, setSelectedUser] = useState<ISelectedUser>(null);
|
||||
const [ isTicketsVisible, setIsTicketsVisible ] = useState(false);
|
||||
|
||||
@ -155,25 +155,6 @@ export const ModToolsView: FC<ModToolsViewProps> = props =>
|
||||
|
||||
useRoomEngineEvent(RoomEngineObjectEvent.SELECTED, onRoomEngineObjectEvent);
|
||||
|
||||
const onModeratorInitMessageEvent = useCallback((event: ModeratorInitMessageEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const data = parser.data;
|
||||
|
||||
dispatchModToolsState({
|
||||
type: ModToolsActions.SET_INIT_DATA,
|
||||
payload: {
|
||||
settings: data
|
||||
}
|
||||
});
|
||||
console.log(parser);
|
||||
}, []);
|
||||
|
||||
CreateMessageHook(ModeratorInitMessageEvent, onModeratorInitMessageEvent);
|
||||
|
||||
const handleClick = useCallback((action: string, value?: string) =>
|
||||
{
|
||||
if(!action) return;
|
||||
@ -299,6 +280,7 @@ export const ModToolsView: FC<ModToolsViewProps> = props =>
|
||||
|
||||
return (
|
||||
<ModToolsContextProvider value={ { modToolsState, dispatchModToolsState } }>
|
||||
<ModToolsMessageHandler />
|
||||
{ isVisible &&
|
||||
<NitroCardView uniqueKey="mod-tools" className="nitro-mod-tools" simple={ false }>
|
||||
<NitroCardHeaderView headerText={ 'Mod Tools' } onCloseClick={ event => setIsVisible(false) } />
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ModeratorInitData } from '@nitrots/nitro-renderer';
|
||||
import { IssueMessageData, ModeratorInitData } from '@nitrots/nitro-renderer';
|
||||
import { Reducer } from 'react';
|
||||
|
||||
export interface IModToolsState
|
||||
@ -9,6 +9,7 @@ export interface IModToolsState
|
||||
openRoomChatlogs: number[];
|
||||
openUserInfo: number[];
|
||||
openUserChatlogs: number[];
|
||||
tickets: IssueMessageData[]
|
||||
}
|
||||
|
||||
export interface IModToolsAction
|
||||
@ -21,6 +22,7 @@ export interface IModToolsAction
|
||||
openRoomChatlogs?: number[];
|
||||
openUserInfo?: number[];
|
||||
openUserChatlogs?: number[];
|
||||
tickets?: IssueMessageData[];
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,6 +34,7 @@ export class ModToolsActions
|
||||
public static SET_OPEN_USERINFO: string = 'MTA_SET_OPEN_USERINFO';
|
||||
public static SET_OPEN_ROOM_CHATLOGS: string = 'MTA_SET_OPEN_CHATLOGS';
|
||||
public static SET_OPEN_USER_CHATLOGS: string = 'MTA_SET_OPEN_USER_CHATLOGS';
|
||||
public static SET_TICKETS: string = 'MTA_SET_TICKETS';
|
||||
public static RESET_STATE: string = 'MTA_RESET_STATE';
|
||||
}
|
||||
|
||||
@ -41,7 +44,8 @@ export const initialModTools: IModToolsState = {
|
||||
openRooms: null,
|
||||
openRoomChatlogs: null,
|
||||
openUserChatlogs: null,
|
||||
openUserInfo: null
|
||||
openUserInfo: null,
|
||||
tickets: null
|
||||
};
|
||||
|
||||
export const ModToolsReducer: Reducer<IModToolsState, IModToolsAction> = (state, action) =>
|
||||
@ -78,6 +82,11 @@ export const ModToolsReducer: Reducer<IModToolsState, IModToolsAction> = (state,
|
||||
|
||||
return { ...state, openUserChatlogs };
|
||||
}
|
||||
case ModToolsActions.SET_TICKETS: {
|
||||
const tickets = (action.payload.tickets || state.tickets || null);
|
||||
|
||||
return { ...state, tickets };
|
||||
}
|
||||
case ModToolsActions.RESET_STATE: {
|
||||
return { ...initialModTools };
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { IssueMessageData } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback, useMemo, useState } from 'react';
|
||||
import { GetSessionDataManager } from '../../../../api';
|
||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../../../layout';
|
||||
import { useModToolsContext } from '../../context/ModToolsContext';
|
||||
import { ModToolsTicketsViewProps } from './ModToolsTicketsView.types';
|
||||
@ -15,15 +16,29 @@ export const ModToolsTicketsView: FC<ModToolsTicketsViewProps> = props =>
|
||||
{
|
||||
const { onCloseClick = null } = props;
|
||||
const { modToolsState = null } = useModToolsContext();
|
||||
const { settings = null } = modToolsState;
|
||||
const { tickets= null } = modToolsState;
|
||||
const [ currentTab, setCurrentTab ] = useState<number>(0);
|
||||
|
||||
const openIssues = useMemo(() =>
|
||||
{
|
||||
if(!settings) return [];
|
||||
if(!tickets) return [];
|
||||
|
||||
return settings.issues.filter(issue => issue.state === IssueMessageData.STATE_OPEN)
|
||||
}, [settings]);
|
||||
return tickets.filter(issue => issue.state === IssueMessageData.STATE_OPEN);
|
||||
}, [tickets]);
|
||||
|
||||
const myIssues = useMemo(() =>
|
||||
{
|
||||
if(!tickets) return [];
|
||||
|
||||
return tickets.filter(issue => (issue.state === IssueMessageData.STATE_PICKED) && (issue.pickerUserId === GetSessionDataManager().userId));
|
||||
}, [tickets]);
|
||||
|
||||
const pickedIssues = useMemo(() =>
|
||||
{
|
||||
if(!tickets) return [];
|
||||
|
||||
return tickets.filter(issue => issue.state === IssueMessageData.STATE_PICKED);
|
||||
}, [tickets]);
|
||||
|
||||
const CurrentTabComponent = useCallback(() =>
|
||||
{
|
||||
@ -34,8 +49,6 @@ export const ModToolsTicketsView: FC<ModToolsTicketsViewProps> = props =>
|
||||
}
|
||||
}, [currentTab, openIssues]);
|
||||
|
||||
console.log(settings);
|
||||
|
||||
return (
|
||||
<NitroCardView className="nitro-mod-tools-tickets" simple={ false }>
|
||||
<NitroCardHeaderView headerText={ 'Tickets' } onCloseClick={ onCloseClick } />
|
||||
@ -49,7 +62,7 @@ export const ModToolsTicketsView: FC<ModToolsTicketsViewProps> = props =>
|
||||
}) }
|
||||
</NitroCardTabsView>
|
||||
<div className="p-2">
|
||||
{settings && <CurrentTabComponent /> }
|
||||
<CurrentTabComponent />
|
||||
</div>
|
||||
</NitroCardContentView>
|
||||
</NitroCardView>
|
||||
|
Loading…
Reference in New Issue
Block a user