mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 15:35:55 +01:00
@@ -22,15 +22,6 @@ export default function AddItemShelfItem(props: any) {
|
|||||||
const { addService } = useConfig();
|
const { addService } = useConfig();
|
||||||
const [opened, setOpened] = useState(false);
|
const [opened, setOpened] = useState(false);
|
||||||
const theme = useMantineTheme();
|
const theme = useMantineTheme();
|
||||||
const form = useForm({
|
|
||||||
initialValues: {
|
|
||||||
type: 'Other',
|
|
||||||
name: '',
|
|
||||||
icon: '',
|
|
||||||
url: '',
|
|
||||||
apiKey: undefined as unknown as string,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Modal
|
<Modal
|
||||||
@@ -40,76 +31,7 @@ export default function AddItemShelfItem(props: any) {
|
|||||||
onClose={() => setOpened(false)}
|
onClose={() => setOpened(false)}
|
||||||
title="Add a service"
|
title="Add a service"
|
||||||
>
|
>
|
||||||
<Center>
|
<AddAppShelfItemForm setOpened={setOpened} />
|
||||||
<Image
|
|
||||||
height={120}
|
|
||||||
width={120}
|
|
||||||
src={form.values.icon}
|
|
||||||
alt="Placeholder"
|
|
||||||
withPlaceholder
|
|
||||||
/>
|
|
||||||
</Center>
|
|
||||||
<form
|
|
||||||
onSubmit={form.onSubmit(() => {
|
|
||||||
addService(form.values);
|
|
||||||
setOpened(false);
|
|
||||||
form.reset();
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<Group direction="column" grow>
|
|
||||||
<TextInput
|
|
||||||
required
|
|
||||||
label="Service name"
|
|
||||||
placeholder="Plex"
|
|
||||||
value={form.values.name}
|
|
||||||
onChange={(event) => form.setFieldValue('name', event.currentTarget.value)}
|
|
||||||
error={form.errors.name && 'Invalid name'}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextInput
|
|
||||||
required
|
|
||||||
label="Icon url"
|
|
||||||
placeholder="https://i.gifer.com/ANPC.gif"
|
|
||||||
value={form.values.icon}
|
|
||||||
onChange={(event) => {
|
|
||||||
form.setFieldValue('icon', event.currentTarget.value);
|
|
||||||
}}
|
|
||||||
error={form.errors.icon && 'Icon url is invalid'}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
required
|
|
||||||
label="Service url"
|
|
||||||
placeholder="http://localhost:8989"
|
|
||||||
value={form.values.url}
|
|
||||||
onChange={(event) => form.setFieldValue('url', event.currentTarget.value)}
|
|
||||||
error={form.errors.url && 'Service url is invalid'}
|
|
||||||
/>
|
|
||||||
<Select
|
|
||||||
label="Select the type of service (used for API calls)"
|
|
||||||
defaultValue="Other"
|
|
||||||
placeholder="Pick one"
|
|
||||||
value={form.values.type}
|
|
||||||
required
|
|
||||||
searchable
|
|
||||||
onChange={(value) => form.setFieldValue('type', value ?? 'Other')}
|
|
||||||
data={ServiceTypeList}
|
|
||||||
/>
|
|
||||||
{(form.values.type === 'Sonarr' || form.values.type === 'Radarr') && (
|
|
||||||
<TextInput
|
|
||||||
required
|
|
||||||
label="API key"
|
|
||||||
placeholder="Your API key"
|
|
||||||
value={form.values.apiKey}
|
|
||||||
onChange={(event) => form.setFieldValue('apiKey', event.currentTarget.value)}
|
|
||||||
error={form.errors.apiKey && 'Invalid API key'}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Group>
|
|
||||||
|
|
||||||
<Group grow position="center" mt="xl">
|
|
||||||
<Button type="submit">Add service</Button>
|
|
||||||
</Group>
|
|
||||||
</form>
|
|
||||||
</Modal>
|
</Modal>
|
||||||
<AspectRatio
|
<AspectRatio
|
||||||
style={{
|
style={{
|
||||||
@@ -138,3 +60,101 @@ export default function AddItemShelfItem(props: any) {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & any) {
|
||||||
|
const { setOpened } = props;
|
||||||
|
const { addService, config, setConfig } = useConfig();
|
||||||
|
const form = useForm({
|
||||||
|
initialValues: {
|
||||||
|
type: props.type ?? 'Other',
|
||||||
|
name: props.name ?? '',
|
||||||
|
icon: props.icon ?? '',
|
||||||
|
url: props.url ?? '',
|
||||||
|
apiKey: props.apiKey ?? (undefined as unknown as string),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Center>
|
||||||
|
<Image height={120} width={120} src={form.values.icon} alt="Placeholder" withPlaceholder />
|
||||||
|
</Center>
|
||||||
|
<form
|
||||||
|
onSubmit={form.onSubmit(() => {
|
||||||
|
// If service already exists, update it.
|
||||||
|
if (config.services && config.services.find((s) => s.name === form.values.name)) {
|
||||||
|
setConfig({
|
||||||
|
...config,
|
||||||
|
services: config.services.map((s) => {
|
||||||
|
if (s.name === form.values.name) {
|
||||||
|
return {
|
||||||
|
...form.values,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
addService(form.values);
|
||||||
|
}
|
||||||
|
setOpened(false);
|
||||||
|
form.reset();
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Group direction="column" grow>
|
||||||
|
<TextInput
|
||||||
|
required
|
||||||
|
label="Service name"
|
||||||
|
placeholder="Plex"
|
||||||
|
value={form.values.name}
|
||||||
|
onChange={(event) => form.setFieldValue('name', event.currentTarget.value)}
|
||||||
|
error={form.errors.name && 'Invalid name'}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextInput
|
||||||
|
required
|
||||||
|
label="Icon url"
|
||||||
|
placeholder="https://i.gifer.com/ANPC.gif"
|
||||||
|
value={form.values.icon}
|
||||||
|
onChange={(event) => {
|
||||||
|
form.setFieldValue('icon', event.currentTarget.value);
|
||||||
|
}}
|
||||||
|
error={form.errors.icon && 'Icon url is invalid'}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
required
|
||||||
|
label="Service url"
|
||||||
|
placeholder="http://localhost:8989"
|
||||||
|
value={form.values.url}
|
||||||
|
onChange={(event) => form.setFieldValue('url', event.currentTarget.value)}
|
||||||
|
error={form.errors.url && 'Service url is invalid'}
|
||||||
|
/>
|
||||||
|
<Select
|
||||||
|
label="Select the type of service (used for API calls)"
|
||||||
|
defaultValue="Other"
|
||||||
|
placeholder="Pick one"
|
||||||
|
value={form.values.type}
|
||||||
|
required
|
||||||
|
searchable
|
||||||
|
onChange={(value) => form.setFieldValue('type', value ?? 'Other')}
|
||||||
|
data={ServiceTypeList}
|
||||||
|
/>
|
||||||
|
{(form.values.type === 'Sonarr' || form.values.type === 'Radarr') && (
|
||||||
|
<TextInput
|
||||||
|
required
|
||||||
|
label="API key"
|
||||||
|
placeholder="Your API key"
|
||||||
|
value={form.values.apiKey}
|
||||||
|
onChange={(event) => form.setFieldValue('apiKey', event.currentTarget.value)}
|
||||||
|
error={form.errors.apiKey && 'Invalid API key'}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
<Group grow position="center" mt="xl">
|
||||||
|
<Button type="submit">{props.message ?? 'Add service'}</Button>
|
||||||
|
</Group>
|
||||||
|
</form>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export function AppShelfItem(props: any) {
|
|||||||
opacity: hovering ? 1 : 0,
|
opacity: hovering ? 1 : 0,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AppShelfMenu name={service.name} removeitem={removeService} />
|
<AppShelfMenu service={service} removeitem={removeService} />
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</Group>
|
</Group>
|
||||||
</Card.Section>
|
</Card.Section>
|
||||||
|
|||||||
@@ -1,47 +1,63 @@
|
|||||||
import { Menu, Text } from '@mantine/core';
|
import { Menu, Modal, Text } from '@mantine/core';
|
||||||
import { showNotification } from '@mantine/notifications';
|
import { showNotification } from '@mantine/notifications';
|
||||||
|
import { useState } from 'react';
|
||||||
import { Check, Edit, Trash } from 'tabler-icons-react';
|
import { Check, Edit, Trash } from 'tabler-icons-react';
|
||||||
|
import { AddAppShelfItemForm } from './AddAppShelfItem';
|
||||||
|
|
||||||
export default function AppShelfMenu(props: any) {
|
export default function AppShelfMenu(props: any) {
|
||||||
const { name, removeitem: removeItem } = props;
|
const { service, removeitem: removeItem } = props;
|
||||||
|
const [opened, setOpened] = useState(false);
|
||||||
return (
|
return (
|
||||||
<Menu position="right">
|
<>
|
||||||
<Menu.Label>Settings</Menu.Label>
|
<Modal
|
||||||
<Menu.Item
|
size="xl"
|
||||||
color="primary"
|
radius="lg"
|
||||||
icon={<Edit size={14} />}
|
opened={props.opened || opened}
|
||||||
// TODO: #2 Add the ability to edit the service.
|
onClose={() => setOpened(false)}
|
||||||
onClick={() => {
|
title="Modify a service"
|
||||||
showNotification({
|
|
||||||
color: 'red',
|
|
||||||
title: <Text>Feature not yet implemented</Text>,
|
|
||||||
message: `${name} could not be edited`,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Rename
|
<AddAppShelfItemForm
|
||||||
</Menu.Item>
|
setOpened={setOpened}
|
||||||
<Menu.Label>Danger zone</Menu.Label>
|
name={service.name}
|
||||||
<Menu.Item
|
type={service.type}
|
||||||
color="red"
|
url={service.url}
|
||||||
onClick={(e: any) => {
|
icon={service.icon}
|
||||||
removeItem(name);
|
apiKey={service.apiKey}
|
||||||
showNotification({
|
message="Save service"
|
||||||
autoClose: 5000,
|
/>
|
||||||
title: (
|
</Modal>
|
||||||
<Text>
|
<Menu position="right">
|
||||||
Service <b>{name}</b> removed successfully
|
<Menu.Label>Settings</Menu.Label>
|
||||||
</Text>
|
<Menu.Item
|
||||||
),
|
color="primary"
|
||||||
color: 'green',
|
icon={<Edit size={14} />}
|
||||||
icon: <Check />,
|
// TODO: #2 Add the ability to edit the service.
|
||||||
message: undefined,
|
onClick={() => setOpened(true)}
|
||||||
});
|
>
|
||||||
}}
|
Edit
|
||||||
icon={<Trash size={14} />}
|
</Menu.Item>
|
||||||
>
|
<Menu.Label>Danger zone</Menu.Label>
|
||||||
Delete
|
<Menu.Item
|
||||||
</Menu.Item>
|
color="red"
|
||||||
</Menu>
|
onClick={(e: any) => {
|
||||||
|
removeItem(service.name);
|
||||||
|
showNotification({
|
||||||
|
autoClose: 5000,
|
||||||
|
title: (
|
||||||
|
<Text>
|
||||||
|
Service <b>{service.name}</b> removed successfully
|
||||||
|
</Text>
|
||||||
|
),
|
||||||
|
color: 'green',
|
||||||
|
icon: <Check />,
|
||||||
|
message: undefined,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
icon={<Trash size={14} />}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</Menu.Item>
|
||||||
|
</Menu>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user