2022-12-20 04:44:29 -08:00
|
|
|
import { Group } from '@mantine/core';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { openModal, closeAllModals } from '@mantine/modals';
|
2023-02-07 22:47:23 -08:00
|
|
|
import { RiLockLine, RiServerFill, RiEdit2Fill, RiSettings3Fill } from 'react-icons/ri';
|
2023-01-03 02:13:40 -08:00
|
|
|
import { useNavigate } from 'react-router';
|
2023-02-07 22:47:23 -08:00
|
|
|
import { DropdownMenu, Text } from '/@/renderer/components';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { ServerList } from '/@/renderer/features/servers';
|
|
|
|
|
import { EditServerForm } from '/@/renderer/features/servers/components/edit-server-form';
|
|
|
|
|
import { Settings } from '/@/renderer/features/settings';
|
2023-01-03 02:13:40 -08:00
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { useCurrentServer, useServerList, useAuthStoreActions } from '/@/renderer/store';
|
|
|
|
|
import { ServerListItem, ServerType } from '/@/renderer/types';
|
|
|
|
|
|
|
|
|
|
export const AppMenu = () => {
|
2023-01-03 02:13:40 -08:00
|
|
|
const navigate = useNavigate();
|
2022-12-19 15:59:14 -08:00
|
|
|
const currentServer = useCurrentServer();
|
|
|
|
|
const serverList = useServerList();
|
|
|
|
|
const { setCurrentServer } = useAuthStoreActions();
|
|
|
|
|
|
|
|
|
|
const handleSetCurrentServer = (server: ServerListItem) => {
|
2023-01-03 02:13:40 -08:00
|
|
|
navigate(AppRoute.HOME);
|
2022-12-19 15:59:14 -08:00
|
|
|
setCurrentServer(server);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleCredentialsModal = (server: ServerListItem) => {
|
|
|
|
|
openModal({
|
|
|
|
|
children: server && (
|
|
|
|
|
<EditServerForm
|
|
|
|
|
isUpdate
|
|
|
|
|
server={server}
|
|
|
|
|
onCancel={closeAllModals}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
size: 'sm',
|
|
|
|
|
title: `Update session for "${server.name}"`,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleManageServersModal = () => {
|
|
|
|
|
openModal({
|
|
|
|
|
children: <ServerList />,
|
|
|
|
|
title: 'Manage Servers',
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSettingsModal = () => {
|
|
|
|
|
openModal({
|
|
|
|
|
children: <Settings />,
|
|
|
|
|
size: 'xl',
|
|
|
|
|
title: (
|
|
|
|
|
<Group position="center">
|
2023-02-07 22:47:23 -08:00
|
|
|
<RiSettings3Fill size={20} />
|
2022-12-19 15:59:14 -08:00
|
|
|
<Text>Settings</Text>
|
|
|
|
|
</Group>
|
|
|
|
|
),
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2023-02-07 22:47:23 -08:00
|
|
|
<>
|
|
|
|
|
<DropdownMenu.Label>Select a server</DropdownMenu.Label>
|
|
|
|
|
{serverList.map((s) => {
|
|
|
|
|
const isNavidromeExpired = s.type === ServerType.NAVIDROME && !s.ndCredential;
|
|
|
|
|
const isJellyfinExpired = false;
|
|
|
|
|
const isSessionExpired = isNavidromeExpired || isJellyfinExpired;
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2023-02-07 22:47:23 -08:00
|
|
|
return (
|
|
|
|
|
<DropdownMenu.Item
|
|
|
|
|
key={`server-${s.id}`}
|
|
|
|
|
$isActive={s.id === currentServer?.id}
|
|
|
|
|
icon={isSessionExpired ? <RiLockLine color="var(--danger-color)" /> : <RiServerFill />}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (!isSessionExpired) return handleSetCurrentServer(s);
|
|
|
|
|
return handleCredentialsModal(s);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Group>{s.name}</Group>
|
|
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
<DropdownMenu.Divider />
|
|
|
|
|
<DropdownMenu.Item
|
|
|
|
|
icon={<RiEdit2Fill />}
|
|
|
|
|
onClick={handleManageServersModal}
|
|
|
|
|
>
|
|
|
|
|
Manage servers
|
|
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
<DropdownMenu.Item
|
|
|
|
|
icon={<RiSettings3Fill />}
|
|
|
|
|
onClick={handleSettingsModal}
|
|
|
|
|
>
|
|
|
|
|
Settings
|
|
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
</>
|
2022-12-19 15:59:14 -08:00
|
|
|
);
|
|
|
|
|
};
|