Skip to content

Commit

Permalink
[ADD] chat command to navigate to dms
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekkmer committed Oct 8, 2023
1 parent 4167ec3 commit a5bc8c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pandora-client-web/src/components/chatroom/chatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useDirectoryConnector } from '../gameContext/directoryConnectorContextP
import { Select } from '../common/select/select';
import settingsIcon from '../../assets/icons/setting.svg';
import { z } from 'zod';
import { useNavigate } from 'react-router';

type Editing = {
target: number;
Expand Down Expand Up @@ -209,6 +210,7 @@ function TextAreaImpl({ messagesDiv, scrollMessagesView }: {

const directoryConnector = useDirectoryConnector();
const shardConnector = useShardConnector();
const navigate = useNavigate();
AssertNotNullable(shardConnector);

/**
Expand All @@ -227,7 +229,8 @@ function TextAreaImpl({ messagesDiv, scrollMessagesView }: {
chatRoom,
messageSender: sender,
inputHandlerContext: chatInput,
}), [chatInput, chatRoom, directoryConnector, sender, shardConnector]);
navigate,
}), [chatInput, chatRoom, directoryConnector, navigate, sender, shardConnector]);

const inputEnd = useEvent(() => {
if (timeout.current) {
Expand Down Expand Up @@ -596,6 +599,7 @@ function AutoCompleteHint(): ReactElement | null {

const directoryConnector = useDirectoryConnector();
const shardConnector = useShardConnector();
const navigate = useNavigate();
AssertNotNullable(shardConnector);
if (!autocompleteHint?.result || !allowCommands)
return null;
Expand Down Expand Up @@ -645,6 +649,7 @@ function AutoCompleteHint(): ReactElement | null {
chatRoom,
messageSender: sender,
inputHandlerContext: chatInput,
navigate,
});

setAutocompleteHint({
Expand Down
13 changes: 13 additions & 0 deletions pandora-client-web/src/components/chatroom/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ export const COMMANDS: readonly IClientCommand[] = [
// return target ? { status: 'whisper', target } : { status: 'none' };
// },
},
{
key: ['dm'],
description: 'Switches to direct message screen',
longDescription: 'Switches to direct message screen with the selected <target> character.' + LONGDESC_THIRD_PERSON,
usage: '<target>',
handler: CreateClientCommand()
.argument('target', CommandSelectorCharacter({ allowSelf: 'none' }))
.handler(({ directoryConnector, navigate }, { target }) => {
directoryConnector.directMessageHandler.setSelected(target.data.accountId);
navigate('/relationships/DMs');
return true;
}),
},
{
key: ['turn', 't'],
description: 'Turns yourself around',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ShardConnector } from '../../networking/shardConnector';
import type { ChatRoom, IChatRoomMessageSender } from '../gameContext/chatRoomContextProvider';
import type { IChatInputHandler } from './chatInput';
import { COMMANDS } from './commands';
import type { useNavigate } from 'react-router';

export const COMMAND_KEY = '/';

Expand All @@ -13,6 +14,7 @@ export interface ICommandExecutionContextClient extends ICommandExecutionContext
chatRoom: ChatRoom;
messageSender: IChatRoomMessageSender;
inputHandlerContext: IChatInputHandler;
navigate: ReturnType<typeof useNavigate>;
}

export type IClientCommand = {
Expand Down

0 comments on commit a5bc8c0

Please sign in to comment.