2021-10-17 19:13:06 +02:00
|
|
|
import { faPlus as plusIcon, faServer as serverIcon } from '@fortawesome/free-solid-svg-icons';
|
2020-12-12 11:29:15 +01:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2023-02-18 11:11:01 +01:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import { DropdownItem, DropdownMenu, DropdownToggle, UncontrolledDropdown } from 'reactstrap';
|
2023-02-18 10:40:37 +01:00
|
|
|
import type { SelectedServer, ServersMap } from './data';
|
|
|
|
import { getServerId } from './data';
|
2020-08-29 20:20:45 +02:00
|
|
|
|
|
|
|
export interface ServersDropdownProps {
|
|
|
|
servers: ServersMap;
|
|
|
|
selectedServer: SelectedServer;
|
|
|
|
}
|
|
|
|
|
2022-05-17 22:31:02 +02:00
|
|
|
export const ServersDropdown = ({ servers, selectedServer }: ServersDropdownProps) => {
|
2023-11-01 10:03:09 +01:00
|
|
|
const serversList = Object.values(servers);
|
2020-08-29 20:20:45 +02:00
|
|
|
|
|
|
|
const renderServers = () => {
|
2023-11-01 10:03:09 +01:00
|
|
|
if (serversList.length === 0) {
|
2021-10-17 19:13:06 +02:00
|
|
|
return (
|
|
|
|
<DropdownItem tag={Link} to="/server/create">
|
2022-03-05 13:26:28 +01:00
|
|
|
<FontAwesomeIcon icon={plusIcon} /> <span className="ms-1">Add a server</span>
|
2021-10-17 19:13:06 +02:00
|
|
|
</DropdownItem>
|
|
|
|
);
|
2020-08-29 20:20:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-11-13 22:44:26 +01:00
|
|
|
<>
|
2020-08-29 20:20:45 +02:00
|
|
|
{serversList.map(({ name, id }) => (
|
2021-10-22 20:13:23 +02:00
|
|
|
<DropdownItem key={id} tag={Link} to={`/server/${id}`} active={getServerId(selectedServer) === id}>
|
2020-08-29 20:20:45 +02:00
|
|
|
{name}
|
|
|
|
</DropdownItem>
|
|
|
|
))}
|
2023-09-30 10:45:52 +02:00
|
|
|
<DropdownItem divider tag="hr" />
|
2021-10-17 19:13:06 +02:00
|
|
|
<DropdownItem tag={Link} to="/manage-servers">
|
2022-03-05 13:26:28 +01:00
|
|
|
<FontAwesomeIcon icon={serverIcon} /> <span className="ms-1">Manage servers</span>
|
2020-08-29 20:20:45 +02:00
|
|
|
</DropdownItem>
|
2020-11-13 22:44:26 +01:00
|
|
|
</>
|
2020-08-29 20:20:45 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<UncontrolledDropdown nav inNavbar>
|
2020-12-12 11:29:15 +01:00
|
|
|
<DropdownToggle nav caret>
|
2022-03-05 13:26:28 +01:00
|
|
|
<FontAwesomeIcon icon={serverIcon} /> <span className="ms-1">Servers</span>
|
2020-12-12 11:29:15 +01:00
|
|
|
</DropdownToggle>
|
2022-03-11 16:37:41 +01:00
|
|
|
<DropdownMenu end style={{ right: 0 }}>{renderServers()}</DropdownMenu>
|
2020-08-29 20:20:45 +02:00
|
|
|
</UncontrolledDropdown>
|
|
|
|
);
|
|
|
|
};
|