diff --git a/src/servers/ManageServersRow.tsx b/src/servers/ManageServersRow.tsx index d3f70483..c881a5fe 100644 --- a/src/servers/ManageServersRow.tsx +++ b/src/servers/ManageServersRow.tsx @@ -1,19 +1,10 @@ import { FC } from 'react'; -import { DropdownItem, UncontrolledTooltip } from 'reactstrap'; +import { UncontrolledTooltip } from 'reactstrap'; import { Link } from 'react-router-dom'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { - faCheck as checkIcon, - faEdit as editIcon, - faMinusCircle as deleteIcon, - faPlug as connectIcon, - faBan as toggleOffIcon, -} from '@fortawesome/free-solid-svg-icons'; -import { faCircle as toggleOnIcon } from '@fortawesome/free-regular-svg-icons'; -import { DropdownBtnMenu } from '../utils/DropdownBtnMenu'; -import { useToggle } from '../utils/helpers/hooks'; +import { faCheck as checkIcon } from '@fortawesome/free-solid-svg-icons'; import { ServerWithId } from './data'; -import { DeleteServerModalProps } from './DeleteServerModal'; +import { ManageServersRowDropdownProps } from './ManageServersRowDropdown'; export interface ManageServersRowProps { server: ServerWithId; @@ -25,50 +16,27 @@ interface ManageServersRowPropsConnectProps extends ManageServersRowProps { } export const ManageServersRow = ( - DeleteServerModal: FC, -): FC => ({ server, hasAutoConnect, setAutoConnect }) => { - const [ isMenuOpen, toggleMenu ] = useToggle(); - const [ isModalOpen,, showModal, hideModal ] = useToggle(); - const serverUrl = `/server/${server.id}`; - const { autoConnect: isAutoConnect } = server; - const autoConnectIcon = isAutoConnect ? toggleOffIcon : toggleOnIcon; - - return ( - - {hasAutoConnect && ( - - {isAutoConnect && ( - <> - - - Auto-connect to this server - - - )} - - )} - - {server.name} - - {server.url} - - - - Connect - - - Edit server - - setAutoConnect(server, !server.autoConnect)}> - {isAutoConnect ? 'Do not a' : 'A'}uto-connect - - - - Remove server - - - + ManageServersRowDropdown: FC, +): FC => ({ server, hasAutoConnect }) => ( + + {hasAutoConnect && ( + + {server.autoConnect && ( + <> + + + Auto-connect to this server + + + )} - - ); -}; + )} + + {server.name} + + {server.url} + + + + +); diff --git a/src/servers/ManageServersRowDropdown.tsx b/src/servers/ManageServersRowDropdown.tsx new file mode 100644 index 00000000..7c85e49f --- /dev/null +++ b/src/servers/ManageServersRowDropdown.tsx @@ -0,0 +1,53 @@ +import { FC } from 'react'; +import { DropdownItem } from 'reactstrap'; +import { Link } from 'react-router-dom'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { + faBan as toggleOffIcon, + faEdit as editIcon, + faMinusCircle as deleteIcon, + faPlug as connectIcon, +} from '@fortawesome/free-solid-svg-icons'; +import { faCircle as toggleOnIcon } from '@fortawesome/free-regular-svg-icons'; +import { DropdownBtnMenu } from '../utils/DropdownBtnMenu'; +import { useToggle } from '../utils/helpers/hooks'; +import { DeleteServerModalProps } from './DeleteServerModal'; +import { ServerWithId } from './data'; + +export interface ManageServersRowDropdownProps { + server: ServerWithId; +} + +interface ManageServersRowDropdownConnectProps extends ManageServersRowDropdownProps { + setAutoConnect: (server: ServerWithId, autoConnect: boolean) => void; +} + +export const ManageServersRowDropdown = ( + DeleteServerModal: FC, +): FC => ({ server, setAutoConnect }) => { + const [ isMenuOpen, toggleMenu ] = useToggle(); + const [ isModalOpen,, showModal, hideModal ] = useToggle(); + const serverUrl = `/server/${server.id}`; + const { autoConnect: isAutoConnect } = server; + const autoConnectIcon = isAutoConnect ? toggleOffIcon : toggleOnIcon; + + return ( + + + Connect + + + Edit server + + setAutoConnect(server, !server.autoConnect)}> + {isAutoConnect ? 'Do not a' : 'A'}uto-connect + + + + Remove server + + + + + ); +}; diff --git a/src/servers/services/provideServices.ts b/src/servers/services/provideServices.ts index afa4cd76..07dd9361 100644 --- a/src/servers/services/provideServices.ts +++ b/src/servers/services/provideServices.ts @@ -16,6 +16,7 @@ import { withoutSelectedServer } from '../helpers/withoutSelectedServer'; import { Overview } from '../Overview'; import { ManageServers } from '../ManageServers'; import { ManageServersRow } from '../ManageServersRow'; +import { ManageServersRowDropdown } from '../ManageServersRowDropdown'; import ServersImporter from './ServersImporter'; import ServersExporter from './ServersExporter'; @@ -31,8 +32,10 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator, withRouter: ); bottle.decorator('ManageServers', connect([ 'servers' ])); - bottle.serviceFactory('ManageServersRow', ManageServersRow, 'DeleteServerModal'); - bottle.decorator('ManageServersRow', connect(null, [ 'setAutoConnect' ])); + bottle.serviceFactory('ManageServersRow', ManageServersRow, 'ManageServersRowDropdown'); + + bottle.serviceFactory('ManageServersRowDropdown', ManageServersRowDropdown, 'DeleteServerModal'); + bottle.decorator('ManageServersRowDropdown', connect(null, [ 'setAutoConnect' ])); bottle.serviceFactory('CreateServer', CreateServer, 'ImportServersBtn', 'useStateFlagTimeout'); bottle.decorator('CreateServer', withoutSelectedServer);