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

View File

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

View File

@@ -22,18 +22,7 @@ export default function AppShelfMenu(props: any) {
>
<AddAppShelfItemForm
setOpened={setOpened}
name={service.name}
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}
{...service}
message="Save service"
/>
</Modal>

View File

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

View File

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