Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Convert sidebar/header/actions #25581

Merged
merged 4 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Box, Sidebar, Dropdown } from '@rocket.chat/fuselage';
import { useAtLeastOnePermission } from '@rocket.chat/ui-contexts';
import React, { useRef } from 'react';
import React, { HTMLAttributes, useRef, VFC } from 'react';
import { createPortal } from 'react-dom';

import { useDropdownVisibility } from '../hooks/useDropdownVisibility';
import CreateRoomList from './CreateRoomList';

const CREATE_ROOM_PERMISSIONS = ['create-c', 'create-p', 'create-d', 'start-discussion', 'start-discussion-other-user'];

const CreateRoom = (props) => {
const CreateRoom: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const reference = useRef(null);
const target = useRef(null);
const { isVisible, toggle } = useDropdownVisibility({ reference, target });
Expand All @@ -19,13 +19,13 @@ const CreateRoom = (props) => {
<>
{showCreate && (
<Box ref={reference}>
<Sidebar.TopBar.Action {...props} icon='edit-rounded' onClick={toggle} />
<Sidebar.TopBar.Action {...props} icon='edit-rounded' onClick={(): void => toggle()} />
</Box>
)}
{isVisible &&
createPortal(
<Dropdown reference={reference} ref={target}>
<CreateRoomList closeList={() => toggle(false)} />
<CreateRoomList closeList={(): void => toggle(false)} />
</Dropdown>,
document.body,
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OptionTitle } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useSetModal, useSetting, useAtLeastOnePermission, useTranslation } from '@rocket.chat/ui-contexts';
import React from 'react';
import React, { FC } from 'react';

import { popover } from '../../../../app/ui-utils/client';
import CreateDiscussion from '../../../components/CreateDiscussion';
Expand All @@ -19,23 +19,27 @@ const style = {
textTransform: 'uppercase',
};

const useReactModal = (Component) => {
type CreateRoomListProps = {
closeList: () => void;
};

const useReactModal = (Component: FC<any>): ((e: React.MouseEvent<HTMLElement>) => void) => {
const setModal = useSetModal();

return useMutableCallback((e) => {
popover.close();

e.preventDefault();

const handleClose = () => {
const handleClose = (): void => {
setModal(null);
};

setModal(() => <Component onClose={handleClose} />);
});
};

function CreateRoomList({ closeList }) {
const CreateRoomList: FC<CreateRoomListProps> = ({ closeList }) => {
const t = useTranslation();

const canCreateChannel = useAtLeastOnePermission(CREATE_CHANNEL_PERMISSIONS);
Expand All @@ -52,15 +56,15 @@ function CreateRoomList({ closeList }) {

return (
<>
<OptionTitle pb='x8' style={style}>
<OptionTitle pb='x8' {...({ style } as any)}>
{t('Create_new')}
</OptionTitle>
<ul className='rc-popover__list'>
{canCreateChannel && (
<ListItem
icon='hashtag'
text={t('Channel')}
action={(e) => {
action={(e: React.MouseEvent<HTMLElement>): void => {
createChannel(e);
closeList();
}}
Expand All @@ -70,7 +74,7 @@ function CreateRoomList({ closeList }) {
<ListItem
icon='team'
text={t('Team')}
action={(e) => {
action={(e: React.MouseEvent<HTMLElement>): void => {
createTeam(e);
closeList();
}}
Expand All @@ -80,7 +84,7 @@ function CreateRoomList({ closeList }) {
<ListItem
icon='balloon'
text={t('Direct_Messages')}
action={(e) => {
action={(e: React.MouseEvent<HTMLElement>): void => {
createDirectMessage(e);
closeList();
}}
Expand All @@ -90,7 +94,7 @@ function CreateRoomList({ closeList }) {
<ListItem
icon='discussion'
text={t('Discussion')}
action={(e) => {
action={(e: React.MouseEvent<HTMLElement>): void => {
createDiscussion(e);
closeList();
}}
Expand All @@ -99,6 +103,6 @@ function CreateRoomList({ closeList }) {
</ul>
</>
);
}
};

export default CreateRoomList;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Sidebar } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useLayout, useRoute } from '@rocket.chat/ui-contexts';
import React from 'react';
import React, { HTMLAttributes, VFC } from 'react';

const Directory = (props) => {
const Directory: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const directoryRoute = useRoute('directory');
const { sidebar } = useLayout();
const handleDirectory = useMutableCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Sidebar } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useLayout, useRoute, useSetting } from '@rocket.chat/ui-contexts';
import React from 'react';
import React, { HTMLAttributes, VFC } from 'react';

const Home = (props) => {
const SidebarHeaderActionHome: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const homeRoute = useRoute('home');
const { sidebar } = useLayout();
const showHome = useSetting('Layout_Show_Home_Button');
Expand All @@ -15,4 +15,4 @@ const Home = (props) => {
return showHome ? <Sidebar.TopBar.Action {...props} icon='home' onClick={handleHome} /> : null;
};

export default Home;
export default SidebarHeaderActionHome;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Sidebar } from '@rocket.chat/fuselage';
import { useSessionDispatch, useTranslation } from '@rocket.chat/ui-contexts';
import React from 'react';
import React, { HTMLAttributes, VFC } from 'react';

const Login = (props) => {
const Login: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const setForceLogin = useSessionDispatch('forceLogin');
const t = useTranslation();

Expand All @@ -13,7 +13,7 @@ const Login = (props) => {
ghost={false}
icon='login'
title={t('Sign_in_to_start_talking')}
onClick={() => setForceLogin(true)}
onClick={(): void => setForceLogin(true)}
/>
);
};
Expand Down
6 changes: 2 additions & 4 deletions apps/meteor/client/sidebar/header/actions/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Sidebar } from '@rocket.chat/fuselage';
import { useMutableCallback, useOutsideClick } from '@rocket.chat/fuselage-hooks';
import React, { useState, useEffect, useRef, ReactElement, ComponentProps } from 'react';
import React, { useState, useEffect, useRef, VFC, HTMLAttributes } from 'react';
import tinykeys from 'tinykeys';

import SearchList from '../../search/SearchList';

type SearchProps = Omit<ComponentProps<typeof Sidebar.TopBar.Action>, 'icon'>;

const Search = (props: SearchProps): ReactElement => {
const Search: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const [searchOpen, setSearchOpen] = useState(false);

const ref = useRef<HTMLElement>(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Box, Sidebar, Dropdown } from '@rocket.chat/fuselage';
import React, { useRef } from 'react';
import React, { VFC, useRef, HTMLAttributes } from 'react';
import { createPortal } from 'react-dom';

import SortList from '../../../components/SortList';
import { useDropdownVisibility } from '../hooks/useDropdownVisibility';

const Sort = (props) => {
const Sort: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const reference = useRef(null);
const target = useRef(null);
const { isVisible, toggle } = useDropdownVisibility({ reference, target });

return (
<>
<Box ref={reference}>
<Sidebar.TopBar.Action {...props} icon='sort' onClick={toggle} />
<Sidebar.TopBar.Action {...props} icon='sort' onClick={(): void => toggle()} />
</Box>
{isVisible &&
createPortal(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Sidebar } from '@rocket.chat/fuselage';
import { useUser, useTranslation } from '@rocket.chat/ui-contexts';
import React, { memo } from 'react';
import React, { memo, VFC } from 'react';

import { useSidebarPaletteColor } from '../hooks/useSidebarPaletteColor';
import UserAvatarButton from './UserAvatarButton';
Expand All @@ -11,15 +11,15 @@ import Login from './actions/Login';
import Search from './actions/Search';
import Sort from './actions/Sort';

const HeaderWithData = () => {
const HeaderWithData: VFC = () => {
const user = useUser();
const t = useTranslation();
useSidebarPaletteColor();

return (
<>
<Sidebar.TopBar.Section className='sidebar--custom-colors'>
<UserAvatarButton user={user} />
<UserAvatarButton />
<Sidebar.TopBar.Actions>
<Home title={t('Home')} />
<Search title={t('Search')} data-qa='sidebar-search' />
Expand Down