Skip to content

Commit

Permalink
[enhancement]: add server menu on Navidrome error page
Browse files Browse the repository at this point in the history
  • Loading branch information
kgarner7 committed Apr 1, 2024
1 parent e0e9673 commit 44fcc33
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Center, Group, Stack } from '@mantine/core';
import { useTranslation } from 'react-i18next';
import { RiCheckFill } from 'react-icons/ri';
import { RiCheckFill, RiEdit2Line, RiHome4Line } from 'react-icons/ri';
import { Link } from 'react-router-dom';
import { Button, PageHeader, Text } from '/@/renderer/components';
import { ActionRequiredContainer } from '/@/renderer/features/action-required/components/action-required-container';
Expand All @@ -9,6 +9,8 @@ import { ServerRequired } from '/@/renderer/features/action-required/components/
import { AnimatedPage } from '/@/renderer/features/shared';
import { AppRoute } from '/@/renderer/router/routes';
import { useCurrentServer } from '/@/renderer/store';
import { openModal } from '@mantine/modals';
import { ServerList } from '/@/renderer/features/servers';

const ActionRequiredRoute = () => {
const { t } = useTranslation();
Expand All @@ -32,6 +34,13 @@ const ActionRequiredRoute = () => {
const canReturnHome = checks.every((c) => c.valid);
const displayedCheck = checks.find((c) => !c.valid);

const handleManageServersModal = () => {
openModal({
children: <ServerList />,
title: 'Manage Servers',
});
};

return (
<AnimatedPage>
<PageHeader />
Expand Down Expand Up @@ -63,13 +72,27 @@ const ActionRequiredRoute = () => {
<Button
component={Link}
disabled={!canReturnHome}
leftIcon={<RiHome4Line />}
to={AppRoute.HOME}
variant="filled"
>
Go back
</Button>
</>
)}
<Group
noWrap
position="center"
>
<Button
fullWidth
leftIcon={<RiEdit2Line />}
variant="filled"
onClick={handleManageServersModal}
>
{t('page.appMenu.manageServers', { postProcess: 'sentenceCase' })}
</Button>
</Group>
</Stack>
</Stack>
</Center>
Expand Down
9 changes: 6 additions & 3 deletions src/renderer/features/servers/components/server-list.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { ChangeEvent } from 'react';
import { Divider, Group, Stack } from '@mantine/core';
import { Accordion, Button, ContextModalVars, Switch } from '/@/renderer/components';
import { Accordion, Button, ContextModalVars, Switch, Text } from '/@/renderer/components';
import { useLocalStorage } from '@mantine/hooks';
import { openContextModal } from '@mantine/modals';
import isElectron from 'is-electron';
import { useTranslation } from 'react-i18next';
import { RiAddFill, RiServerFill } from 'react-icons/ri';
import { AddServerForm } from '/@/renderer/features/servers/components/add-server-form';
import { ServerListItem } from '/@/renderer/features/servers/components/server-list-item';
import { useServerList } from '/@/renderer/store';
import { useCurrentServer, useServerList } from '/@/renderer/store';
import { titleCase } from '/@/renderer/utils';

const localSettings = isElectron() ? window.electron.localSettings : null;

export const ServerList = () => {
const { t } = useTranslation();
const currentServer = useCurrentServer();
const serverListQuery = useServerList();

const handleAddServerModal = () => {
Expand Down Expand Up @@ -90,7 +91,9 @@ export const ServerList = () => {
>
<Accordion.Control icon={<RiServerFill size={15} />}>
<Group position="apart">
{titleCase(server?.type)} - {server?.name}
<Text weight={server.id === currentServer?.id ? 800 : 400}>
{titleCase(server?.type)} - {server?.name}
</Text>
</Group>
</Accordion.Control>
<Accordion.Panel>
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/hooks/use-server-authenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AuthState, ServerListItem, ServerType } from '/@/renderer/types';
import { api } from '/@/renderer/api';
import { SongListSort, SortOrder } from '/@/renderer/api/types';
import { debounce } from 'lodash';
import { toast } from '/@/renderer/components';

export const useServerAuthenticated = () => {
const priorServerId = useRef<string>();
Expand All @@ -29,6 +30,7 @@ export const useServerAuthenticated = () => {

setReady(AuthState.VALID);
} catch (error) {
toast.error({ message: (error as Error).message });
setReady(AuthState.INVALID);
}
}, []);
Expand Down

0 comments on commit 44fcc33

Please sign in to comment.