mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 23:45:48 +01:00
Use ID instead of only names
This commit is contained in:
committed by
ajnart
parent
9b440c0da3
commit
667322d14e
@@ -15,6 +15,7 @@ import {
|
|||||||
Title,
|
Title,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { useForm } from '@mantine/form';
|
import { useForm } from '@mantine/form';
|
||||||
|
import { time } from 'console';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Apps } from 'tabler-icons-react';
|
import { Apps } from 'tabler-icons-react';
|
||||||
@@ -126,6 +127,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
|
|||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
|
id: props.id ?? Date.now(),
|
||||||
type: props.type ?? 'Other',
|
type: props.type ?? 'Other',
|
||||||
name: props.name ?? '',
|
name: props.name ?? '',
|
||||||
icon: props.icon ?? '',
|
icon: props.icon ?? '',
|
||||||
@@ -166,11 +168,13 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
|
|||||||
<form
|
<form
|
||||||
onSubmit={form.onSubmit(() => {
|
onSubmit={form.onSubmit(() => {
|
||||||
// If service already exists, update it.
|
// If service already exists, update it.
|
||||||
if (config.services && config.services.find((s) => s.name === form.values.name)) {
|
if (config.services && config.services.find((s) => s.id === form.values.id)) {
|
||||||
|
console.log('found service with the same id (modify)');
|
||||||
setConfig({
|
setConfig({
|
||||||
...config,
|
...config,
|
||||||
|
// replace the found item by matching ID
|
||||||
services: config.services.map((s) => {
|
services: config.services.map((s) => {
|
||||||
if (s.name === form.values.name) {
|
if (s.id === form.values.id) {
|
||||||
return {
|
return {
|
||||||
...form.values,
|
...form.values,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ const AppShelf = (props: any) => {
|
|||||||
return (
|
return (
|
||||||
<Grid gutter="xl" align="center">
|
<Grid gutter="xl" align="center">
|
||||||
{config.services.map((service) => (
|
{config.services.map((service) => (
|
||||||
<Grid.Col key={service.name} span={6} xl={2} xs={4} sm={3} md={3}>
|
<Grid.Col key={service.id} span={6} xl={2} xs={4} sm={3} md={3}>
|
||||||
<AppShelfItem key={service.name} service={service} />
|
<AppShelfItem key={service.id} service={service} />
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export default function AppShelfMenu(props: any) {
|
|||||||
<AddAppShelfItemForm
|
<AddAppShelfItemForm
|
||||||
setOpened={setOpened}
|
setOpened={setOpened}
|
||||||
name={service.name}
|
name={service.name}
|
||||||
|
id={service.id}
|
||||||
type={service.type}
|
type={service.type}
|
||||||
url={service.url}
|
url={service.url}
|
||||||
icon={service.icon}
|
icon={service.icon}
|
||||||
@@ -54,7 +55,7 @@ export default function AppShelfMenu(props: any) {
|
|||||||
onClick={(e: any) => {
|
onClick={(e: any) => {
|
||||||
setConfig({
|
setConfig({
|
||||||
...config,
|
...config,
|
||||||
services: config.services.filter((s) => s.name !== service.name),
|
services: config.services.filter((s) => s.id !== service.id),
|
||||||
});
|
});
|
||||||
showNotification({
|
showNotification({
|
||||||
autoClose: 5000,
|
autoClose: 5000,
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export type ServiceType =
|
|||||||
| 'Emby';
|
| 'Emby';
|
||||||
|
|
||||||
export interface serviceItem {
|
export interface serviceItem {
|
||||||
[x: string]: any;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user