🔧 Tweak UI and change the name of the settings

This commit is contained in:
ajnart
2022-06-20 09:52:05 +02:00
parent a8c0dfcd0c
commit 80d3f16473
5 changed files with 156 additions and 167 deletions

View File

@@ -15,6 +15,7 @@ import {
Tabs, Tabs,
MultiSelect, MultiSelect,
ScrollArea, ScrollArea,
Switch,
} from '@mantine/core'; } from '@mantine/core';
import { useForm } from '@mantine/form'; import { useForm } from '@mantine/form';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
@@ -22,7 +23,7 @@ import { IconApps as Apps } from '@tabler/icons';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { useDebouncedValue } from '@mantine/hooks'; import { useDebouncedValue } from '@mantine/hooks';
import { useConfig } from '../../tools/state'; import { useConfig } from '../../tools/state';
import { ServiceTypeList, StatusCodes, Targets } from '../../tools/types'; import { ServiceTypeList, StatusCodes } from '../../tools/types';
export function AddItemShelfButton(props: any) { export function AddItemShelfButton(props: any) {
const [opened, setOpened] = useState(false); const [opened, setOpened] = useState(false);
@@ -117,7 +118,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
password: props.password ?? (undefined as unknown as string), password: props.password ?? (undefined as unknown as string),
openedUrl: props.openedUrl ?? (undefined as unknown as string), openedUrl: props.openedUrl ?? (undefined as unknown as string),
status: props.status ?? ['200'], status: props.status ?? ['200'],
target: props.target ?? '_blank', newTab: props.newTab ?? true,
}, },
validate: { validate: {
apiKey: () => null, apiKey: () => null,
@@ -181,8 +182,8 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
if (JSON.stringify(form.values.status) === JSON.stringify(['200'])) { if (JSON.stringify(form.values.status) === JSON.stringify(['200'])) {
form.values.status = undefined; form.values.status = undefined;
} }
if (form.values.target === '_blank') { if (form.values.newTab === true) {
form.values.target = undefined; form.values.newTab = undefined;
} }
// If service already exists, update it. // If service already exists, update it.
if (config.services && config.services.find((s) => s.id === form.values.id)) { if (config.services && config.services.find((s) => s.id === form.values.id)) {
@@ -208,9 +209,9 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
form.reset(); form.reset();
})} })}
> >
<Tabs position="center"> <Tabs grow>
<Tabs.Tab label="Options"> <Tabs.Tab label="Options">
<ScrollArea style={{height:'42vh'}} scrollbarSize={4}> <ScrollArea style={{ height: 500 }} scrollbarSize={4}>
<Group direction="column" grow> <Group direction="column" grow>
<TextInput <TextInput
required required
@@ -350,13 +351,12 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
searchable searchable
{...form.getInputProps('status')} {...form.getInputProps('status')}
/> />
<Select <Switch
label="Open Tab in: " label="Open service in new tab"
data={Targets} defaultChecked={form.values.newTab}
defaultValue="_blank" {...form.getInputProps('newTab')}
placeholder="Pick one"
{...form.getInputProps('target')}
/> />
</Group>
</Tabs.Tab> </Tabs.Tab>
</Tabs> </Tabs>
<Group grow position="center" mt="xl"> <Group grow position="center" mt="xl">

View File

@@ -83,7 +83,7 @@ export function AppShelfItem(props: any) {
> >
<Card.Section> <Card.Section>
<Anchor <Anchor
target={service.target !== undefined ? service.target : '_blank'} target={service.newTab === false ? '_top' : '_blank'}
href={service.openedUrl ? service.openedUrl : service.url} href={service.openedUrl ? service.openedUrl : service.url}
style={{ color: 'inherit', fontStyle: 'inherit', fontSize: 'inherit' }} style={{ color: 'inherit', fontStyle: 'inherit', fontSize: 'inherit' }}
> >
@@ -127,13 +127,9 @@ export function AppShelfItem(props: any) {
src={service.icon} src={service.icon}
fit="contain" fit="contain"
onClick={() => { onClick={() => {
if (service.target === undefined || service.target === '_blank') { if (service.openedUrl) {
if (service.openedUrl) window.open(service.openedUrl, '_blank'); window.open(service.openedUrl, service.newTab === false ? '_top' : '_blank');
else window.open(service.url); } else window.open(service.url, service.newTab === false ? '_top' : '_blank');
} else {
if (service.openedUrl) window.location.href = service.openedUrl;
else window.location.href = service.url;
}
}} }}
/> />
</motion.i> </motion.i>

View File

@@ -22,18 +22,7 @@ export default function AppShelfMenu(props: any) {
> >
<AddAppShelfItemForm <AddAppShelfItemForm
setOpened={setOpened} setOpened={setOpened}
name={service.name} {...service}
id={service.id}
category={service.category}
type={service.type}
url={service.url}
icon={service.icon}
apiKey={service.apiKey}
username={service.username}
password={service.password}
openedUrl={service.openedUrl}
status={service.status}
target={service.target}
message="Save service" message="Save service"
/> />
</Modal> </Modal>

View File

@@ -10,7 +10,11 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
res.status(response.status).json(response.statusText); res.status(response.status).json(response.statusText);
}) })
.catch((error) => { .catch((error) => {
if (error.response) {
res.status(error.response.status).json(error.response.statusText); res.status(error.response.status).json(error.response.statusText);
} else {
res.status(500).json('Server Error');
}
}); });
// // Make a request to the URL // // Make a request to the URL
// const response = await axios.get(url); // const response = await axios.get(url);

View File

@@ -92,6 +92,6 @@ export interface serviceItem {
password?: string; password?: string;
username?: string; username?: string;
openedUrl?: string; openedUrl?: string;
status: string[]; newTab?: boolean;
target: string; status?: string[];
} }