From 667322d14e878384936b014bf6504a8d7724677d Mon Sep 17 00:00:00 2001 From: "Thomas \"ajnart\" Camlong" Date: Thu, 19 May 2022 22:29:35 +0200 Subject: [PATCH] Use ID instead of only names --- src/components/AppShelf/AddAppShelfItem.tsx | 8 ++++++-- src/components/AppShelf/AppShelf.tsx | 4 ++-- src/components/AppShelf/AppShelfMenu.tsx | 3 ++- src/tools/types.ts | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/AppShelf/AddAppShelfItem.tsx b/src/components/AppShelf/AddAppShelfItem.tsx index ccc6569f2..50cabc968 100644 --- a/src/components/AppShelf/AddAppShelfItem.tsx +++ b/src/components/AppShelf/AddAppShelfItem.tsx @@ -15,6 +15,7 @@ import { Title, } from '@mantine/core'; import { useForm } from '@mantine/form'; +import { time } from 'console'; import { motion } from 'framer-motion'; import { useState } from 'react'; import { Apps } from 'tabler-icons-react'; @@ -126,6 +127,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & const form = useForm({ initialValues: { + id: props.id ?? Date.now(), type: props.type ?? 'Other', name: props.name ?? '', icon: props.icon ?? '', @@ -166,11 +168,13 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
{ // 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({ ...config, + // replace the found item by matching ID services: config.services.map((s) => { - if (s.name === form.values.name) { + if (s.id === form.values.id) { return { ...form.values, }; diff --git a/src/components/AppShelf/AppShelf.tsx b/src/components/AppShelf/AppShelf.tsx index 10cbee4ec..4d3fa553c 100644 --- a/src/components/AppShelf/AppShelf.tsx +++ b/src/components/AppShelf/AppShelf.tsx @@ -22,8 +22,8 @@ const AppShelf = (props: any) => { return ( {config.services.map((service) => ( - - + + ))} diff --git a/src/components/AppShelf/AppShelfMenu.tsx b/src/components/AppShelf/AppShelfMenu.tsx index 257d61629..0a491796d 100644 --- a/src/components/AppShelf/AppShelfMenu.tsx +++ b/src/components/AppShelf/AppShelfMenu.tsx @@ -22,6 +22,7 @@ export default function AppShelfMenu(props: any) { { setConfig({ ...config, - services: config.services.filter((s) => s.name !== service.name), + services: config.services.filter((s) => s.id !== service.id), }); showNotification({ autoClose: 5000, diff --git a/src/tools/types.ts b/src/tools/types.ts index 6465fc295..f22a3bb19 100644 --- a/src/tools/types.ts +++ b/src/tools/types.ts @@ -29,7 +29,7 @@ export type ServiceType = | 'Emby'; export interface serviceItem { - [x: string]: any; + id: number; name: string; type: string; url: string;