mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-30 08:50:51 +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 { FC, useCallback, useReducer, useState } from 'react';
|
||||||
import { GetRoomSession } from '../../api';
|
import { GetRoomSession } from '../../api';
|
||||||
import { ModToolsEvent } from '../../events/mod-tools/ModToolsEvent';
|
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 { ModToolsOpenRoomInfoEvent } from '../../events/mod-tools/ModToolsOpenRoomInfoEvent';
|
||||||
import { ModToolsOpenUserChatlogEvent } from '../../events/mod-tools/ModToolsOpenUserChatlogEvent';
|
import { ModToolsOpenUserChatlogEvent } from '../../events/mod-tools/ModToolsOpenUserChatlogEvent';
|
||||||
import { ModToolsOpenUserInfoEvent } from '../../events/mod-tools/ModToolsOpenUserInfoEvent';
|
import { ModToolsOpenUserInfoEvent } from '../../events/mod-tools/ModToolsOpenUserInfoEvent';
|
||||||
import { CreateMessageHook } from '../../hooks';
|
|
||||||
import { useRoomEngineEvent } from '../../hooks/events';
|
import { useRoomEngineEvent } from '../../hooks/events';
|
||||||
import { dispatchUiEvent, useUiEvent } from '../../hooks/events/ui/ui-event';
|
import { dispatchUiEvent, useUiEvent } from '../../hooks/events/ui/ui-event';
|
||||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../layout';
|
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../layout';
|
||||||
import { ModToolsContextProvider } from './context/ModToolsContext';
|
import { ModToolsContextProvider } from './context/ModToolsContext';
|
||||||
|
import { ModToolsMessageHandler } from './ModToolsMessageHandler';
|
||||||
import { ModToolsViewProps } from './ModToolsView.types';
|
import { ModToolsViewProps } from './ModToolsView.types';
|
||||||
import { initialModTools, ModToolsActions, ModToolsReducer } from './reducers/ModToolsReducer';
|
import { initialModTools, ModToolsActions, ModToolsReducer } from './reducers/ModToolsReducer';
|
||||||
import { ISelectedUser } from './utils/ISelectedUser';
|
import { ISelectedUser } from './utils/ISelectedUser';
|
||||||
@ -24,7 +24,7 @@ export const ModToolsView: FC<ModToolsViewProps> = props =>
|
|||||||
{
|
{
|
||||||
const [ isVisible, setIsVisible ] = useState(false);
|
const [ isVisible, setIsVisible ] = useState(false);
|
||||||
const [ modToolsState, dispatchModToolsState ] = useReducer(ModToolsReducer, initialModTools);
|
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 [ selectedUser, setSelectedUser] = useState<ISelectedUser>(null);
|
||||||
const [ isTicketsVisible, setIsTicketsVisible ] = useState(false);
|
const [ isTicketsVisible, setIsTicketsVisible ] = useState(false);
|
||||||
|
|
||||||
@ -155,25 +155,6 @@ export const ModToolsView: FC<ModToolsViewProps> = props =>
|
|||||||
|
|
||||||
useRoomEngineEvent(RoomEngineObjectEvent.SELECTED, onRoomEngineObjectEvent);
|
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) =>
|
const handleClick = useCallback((action: string, value?: string) =>
|
||||||
{
|
{
|
||||||
if(!action) return;
|
if(!action) return;
|
||||||
@ -299,6 +280,7 @@ export const ModToolsView: FC<ModToolsViewProps> = props =>
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ModToolsContextProvider value={ { modToolsState, dispatchModToolsState } }>
|
<ModToolsContextProvider value={ { modToolsState, dispatchModToolsState } }>
|
||||||
|
<ModToolsMessageHandler />
|
||||||
{ isVisible &&
|
{ isVisible &&
|
||||||
<NitroCardView uniqueKey="mod-tools" className="nitro-mod-tools" simple={ false }>
|
<NitroCardView uniqueKey="mod-tools" className="nitro-mod-tools" simple={ false }>
|
||||||
<NitroCardHeaderView headerText={ 'Mod Tools' } onCloseClick={ event => setIsVisible(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';
|
import { Reducer } from 'react';
|
||||||
|
|
||||||
export interface IModToolsState
|
export interface IModToolsState
|
||||||
@ -9,6 +9,7 @@ export interface IModToolsState
|
|||||||
openRoomChatlogs: number[];
|
openRoomChatlogs: number[];
|
||||||
openUserInfo: number[];
|
openUserInfo: number[];
|
||||||
openUserChatlogs: number[];
|
openUserChatlogs: number[];
|
||||||
|
tickets: IssueMessageData[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IModToolsAction
|
export interface IModToolsAction
|
||||||
@ -21,6 +22,7 @@ export interface IModToolsAction
|
|||||||
openRoomChatlogs?: number[];
|
openRoomChatlogs?: number[];
|
||||||
openUserInfo?: number[];
|
openUserInfo?: number[];
|
||||||
openUserChatlogs?: 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_USERINFO: string = 'MTA_SET_OPEN_USERINFO';
|
||||||
public static SET_OPEN_ROOM_CHATLOGS: string = 'MTA_SET_OPEN_CHATLOGS';
|
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_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';
|
public static RESET_STATE: string = 'MTA_RESET_STATE';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +44,8 @@ export const initialModTools: IModToolsState = {
|
|||||||
openRooms: null,
|
openRooms: null,
|
||||||
openRoomChatlogs: null,
|
openRoomChatlogs: null,
|
||||||
openUserChatlogs: null,
|
openUserChatlogs: null,
|
||||||
openUserInfo: null
|
openUserInfo: null,
|
||||||
|
tickets: null
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ModToolsReducer: Reducer<IModToolsState, IModToolsAction> = (state, action) =>
|
export const ModToolsReducer: Reducer<IModToolsState, IModToolsAction> = (state, action) =>
|
||||||
@ -78,6 +82,11 @@ export const ModToolsReducer: Reducer<IModToolsState, IModToolsAction> = (state,
|
|||||||
|
|
||||||
return { ...state, openUserChatlogs };
|
return { ...state, openUserChatlogs };
|
||||||
}
|
}
|
||||||
|
case ModToolsActions.SET_TICKETS: {
|
||||||
|
const tickets = (action.payload.tickets || state.tickets || null);
|
||||||
|
|
||||||
|
return { ...state, tickets };
|
||||||
|
}
|
||||||
case ModToolsActions.RESET_STATE: {
|
case ModToolsActions.RESET_STATE: {
|
||||||
return { ...initialModTools };
|
return { ...initialModTools };
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { IssueMessageData } from '@nitrots/nitro-renderer';
|
import { IssueMessageData } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useCallback, useMemo, useState } from 'react';
|
import { FC, useCallback, useMemo, useState } from 'react';
|
||||||
|
import { GetSessionDataManager } from '../../../../api';
|
||||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../../../layout';
|
import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../../../layout';
|
||||||
import { useModToolsContext } from '../../context/ModToolsContext';
|
import { useModToolsContext } from '../../context/ModToolsContext';
|
||||||
import { ModToolsTicketsViewProps } from './ModToolsTicketsView.types';
|
import { ModToolsTicketsViewProps } from './ModToolsTicketsView.types';
|
||||||
@ -15,15 +16,29 @@ export const ModToolsTicketsView: FC<ModToolsTicketsViewProps> = props =>
|
|||||||
{
|
{
|
||||||
const { onCloseClick = null } = props;
|
const { onCloseClick = null } = props;
|
||||||
const { modToolsState = null } = useModToolsContext();
|
const { modToolsState = null } = useModToolsContext();
|
||||||
const { settings = null } = modToolsState;
|
const { tickets= null } = modToolsState;
|
||||||
const [ currentTab, setCurrentTab ] = useState<number>(0);
|
const [ currentTab, setCurrentTab ] = useState<number>(0);
|
||||||
|
|
||||||
const openIssues = useMemo(() =>
|
const openIssues = useMemo(() =>
|
||||||
{
|
{
|
||||||
if(!settings) return [];
|
if(!tickets) return [];
|
||||||
|
|
||||||
return settings.issues.filter(issue => issue.state === IssueMessageData.STATE_OPEN)
|
return tickets.filter(issue => issue.state === IssueMessageData.STATE_OPEN);
|
||||||
}, [settings]);
|
}, [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(() =>
|
const CurrentTabComponent = useCallback(() =>
|
||||||
{
|
{
|
||||||
@ -34,8 +49,6 @@ export const ModToolsTicketsView: FC<ModToolsTicketsViewProps> = props =>
|
|||||||
}
|
}
|
||||||
}, [currentTab, openIssues]);
|
}, [currentTab, openIssues]);
|
||||||
|
|
||||||
console.log(settings);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NitroCardView className="nitro-mod-tools-tickets" simple={ false }>
|
<NitroCardView className="nitro-mod-tools-tickets" simple={ false }>
|
||||||
<NitroCardHeaderView headerText={ 'Tickets' } onCloseClick={ onCloseClick } />
|
<NitroCardHeaderView headerText={ 'Tickets' } onCloseClick={ onCloseClick } />
|
||||||
@ -49,7 +62,7 @@ export const ModToolsTicketsView: FC<ModToolsTicketsViewProps> = props =>
|
|||||||
}) }
|
}) }
|
||||||
</NitroCardTabsView>
|
</NitroCardTabsView>
|
||||||
<div className="p-2">
|
<div className="p-2">
|
||||||
{settings && <CurrentTabComponent /> }
|
<CurrentTabComponent />
|
||||||
</div>
|
</div>
|
||||||
</NitroCardContentView>
|
</NitroCardContentView>
|
||||||
</NitroCardView>
|
</NitroCardView>
|
||||||
|
Loading…
Reference in New Issue
Block a user