handle escape and introducing shortcuts slowly
This commit is contained in:
@@ -23,9 +23,10 @@ import {
|
|||||||
getConversationById,
|
getConversationById,
|
||||||
getConversations,
|
getConversations,
|
||||||
} from '../api/NirvanaApi';
|
} from '../api/NirvanaApi';
|
||||||
import { useAsyncFn, useEffectOnce, useUnmount } from 'react-use';
|
import { useAsyncFn, useEffectOnce, useKeyPressEvent, useUnmount } from 'react-use';
|
||||||
|
|
||||||
import CreateConversationRequest from '@nirvana/core/requests/CreateConversationRequest.request';
|
import CreateConversationRequest from '@nirvana/core/requests/CreateConversationRequest.request';
|
||||||
|
import { KeyboardShortcuts } from '../util/keyboard';
|
||||||
import Peer from 'simple-peer';
|
import Peer from 'simple-peer';
|
||||||
import { Typography } from '@mui/material';
|
import { Typography } from '@mui/material';
|
||||||
import User from '@nirvana/core/models/user.model';
|
import User from '@nirvana/core/models/user.model';
|
||||||
@@ -72,6 +73,8 @@ interface IConversationContext {
|
|||||||
selectConversation?: (conversationId: string, temporaryOverrideSort?: boolean) => Promise<void>;
|
selectConversation?: (conversationId: string, temporaryOverrideSort?: boolean) => Promise<void>;
|
||||||
|
|
||||||
handleStartConversation?: (otherUsers: User[], conversationName?: string) => Promise<boolean>;
|
handleStartConversation?: (otherUsers: User[], conversationName?: string) => Promise<boolean>;
|
||||||
|
|
||||||
|
handleEscape?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConversationContext = React.createContext<IConversationContext>({
|
const ConversationContext = React.createContext<IConversationContext>({
|
||||||
@@ -382,6 +385,12 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
|
|||||||
return [priorityConversations, inboxConversations];
|
return [priorityConversations, inboxConversations];
|
||||||
}, [conversationMap, user]);
|
}, [conversationMap, user]);
|
||||||
|
|
||||||
|
const handleEscape = useCallback(() => {
|
||||||
|
selectConversation(undefined);
|
||||||
|
}, [selectConversation]);
|
||||||
|
|
||||||
|
useKeyPressEvent(KeyboardShortcuts.escape.shortcutKey, handleEscape);
|
||||||
|
|
||||||
if (fetchState.error) {
|
if (fetchState.error) {
|
||||||
return (
|
return (
|
||||||
<Typography variant={'h6'} color={'danger'}>
|
<Typography variant={'h6'} color={'danger'}>
|
||||||
@@ -399,6 +408,7 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
|
|||||||
selectConversation,
|
selectConversation,
|
||||||
priorityConversations: masterConversations[0],
|
priorityConversations: masterConversations[0],
|
||||||
inboxConversations: masterConversations[1],
|
inboxConversations: masterConversations[1],
|
||||||
|
handleEscape,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export function ConversationList() {
|
|||||||
>
|
>
|
||||||
<Stack direction={'column'} alignItems="center">
|
<Stack direction={'column'} alignItems="center">
|
||||||
<Typography align="center" variant="caption">
|
<Typography align="center" variant="caption">
|
||||||
Have your favorites here for quick dialing
|
Add your favorites here for quick dialing
|
||||||
</Typography>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
</List>
|
</List>
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ function OverlayConversation({
|
|||||||
masterConversation: MasterConversation;
|
masterConversation: MasterConversation;
|
||||||
isSelected?: boolean;
|
isSelected?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const { selectConversation } = useConversations();
|
const { selectConversation, handleEscape } = useConversations();
|
||||||
|
|
||||||
const handleSelectConversation = useCallback(() => {
|
const handleSelectConversation = useCallback(() => {
|
||||||
selectConversation(masterConversation._id.toString(), false);
|
selectConversation(masterConversation._id.toString(), false);
|
||||||
@@ -271,6 +271,7 @@ function OverlayConversation({
|
|||||||
color: 'GrayText',
|
color: 'GrayText',
|
||||||
}}
|
}}
|
||||||
size="small"
|
size="small"
|
||||||
|
onClick={handleEscape}
|
||||||
>
|
>
|
||||||
<FiX />
|
<FiX />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|||||||
Reference in New Issue
Block a user