Handled ESC to go from stories to chats

This commit is contained in:
Alvaro 2022-09-26 14:28:40 -06:00 committed by GitHub
parent 5ed5483dd7
commit ec454a9419
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View file

@ -24,6 +24,7 @@ import { MyStories } from './MyStories';
import { StoriesPane } from './StoriesPane';
import { Theme, themeClassName } from '../util/theme';
import { getWidthFromPreferredWidth } from '../util/leftPaneWidth';
import { useEscapeHandling } from '../hooks/useEscapeHandling';
export type PropsType = {
deleteStoryForEveryone: (story: StoryViewType) => unknown;
@ -45,6 +46,8 @@ export type PropsType = {
toggleStoriesView: () => unknown;
viewUserStories: ViewUserStoriesActionCreatorType;
viewStory: ViewStoryActionCreatorType;
isViewingStory: boolean;
isStoriesSettingsVisible: boolean;
};
type AddStoryType =
@ -75,6 +78,8 @@ export const Stories = ({
toggleStoriesView,
viewUserStories,
viewStory,
isViewingStory,
isStoriesSettingsVisible,
}: PropsType): JSX.Element => {
const width = getWidthFromPreferredWidth(preferredWidthFromStorage, {
requiresFullWidth: true,
@ -83,6 +88,15 @@ export const Stories = ({
const [addStoryData, setAddStoryData] = useState<AddStoryType>();
const [isMyStories, setIsMyStories] = useState(false);
// only handle ESC if not showing a child that handles their own ESC
useEscapeHandling(
(isMyStories && myStories.length) ||
isViewingStory ||
isStoriesSettingsVisible
? undefined
: toggleStoriesView
);
return (
<div className={classNames('Stories', themeClassName(Theme.Dark))}>
{addStoryData &&