diff --git a/src/components/Docker/ContainerActionBar.tsx b/src/components/Docker/ContainerActionBar.tsx index 2c933cdb4..9342c9085 100644 --- a/src/components/Docker/ContainerActionBar.tsx +++ b/src/components/Docker/ContainerActionBar.tsx @@ -1,8 +1,8 @@ -import { Button, Group } from '@mantine/core'; +import { Button, Group, Modal, Text, Title } from '@mantine/core'; +import { useBooleanToggle } from '@mantine/hooks'; import { showNotification, updateNotification } from '@mantine/notifications'; import { IconCheck, - IconLicense, IconPlayerPlay, IconPlayerStop, IconPlus, @@ -13,8 +13,9 @@ import { } from '@tabler/icons'; import axios from 'axios'; import Dockerode from 'dockerode'; -import addToHomarr from '../../tools/addToHomarr'; +import addToHomarr, { tryMatchService } from '../../tools/addToHomarr'; import { useConfig } from '../../tools/state'; +import { AddAppShelfItemForm } from '../AppShelf/AddAppShelfItem'; function sendDockerCommand(action: string, containerId: string, containerName: string) { showNotification({ @@ -57,8 +58,22 @@ export interface ContainerActionBarProps { export default function ContainerActionBar({ selected, reload }: ContainerActionBarProps) { const { config, setConfig } = useConfig(); + const [opened, setOpened] = useBooleanToggle(false); return ( + setOpened(false)} + title="Add service" + > + + diff --git a/src/components/Docker/DockerDrawer.tsx b/src/components/Docker/DockerDrawer.tsx index ed728f21b..fcb87de76 100644 --- a/src/components/Docker/DockerDrawer.tsx +++ b/src/components/Docker/DockerDrawer.tsx @@ -32,7 +32,7 @@ export default function DockerDrawer(props: any) { setOpened(false)} padding="xl" size="full">
- +
diff --git a/src/tools/addToHomarr.ts b/src/tools/addToHomarr.ts index 91ff8accc..c3efbb21c 100644 --- a/src/tools/addToHomarr.ts +++ b/src/tools/addToHomarr.ts @@ -1,5 +1,6 @@ +import { showNotification } from '@mantine/notifications'; import Dockerode from 'dockerode'; -import { Config } from './types'; +import { Config, MatchingImages, ServiceType, ServiceTypeList } from './types'; async function MatchIcon(name: string) { const res = await fetch( @@ -10,12 +11,30 @@ async function MatchIcon(name: string) { return res.ok ? res.url : '/favicon.svg'; } -function tryMatchType(imageName: string) { - // Search for a match with the Image name from the MATCH_TYPES array - console.log(`Trying to match type for: ${imageName}`); +function tryMatchType(imageName: string): ServiceType { + // Try to find imageName inside MatchingImages + + const match = MatchingImages.find(({ image }) => imageName.includes(image)); + if (match) { + return match.type; + } return 'Other'; } +export function tryMatchService(container: Dockerode.ContainerInfo | undefined) { + if (container === undefined) return {}; + const name = container.Names[0].substring(1); + return { + name, + id: container.Id, + type: tryMatchType(container.Image), + url: `${container.Ports.at(0)?.IP}:${container.Ports.at(0)?.PublicPort}`, + icon: `https://cdn.jsdelivr.net/gh/walkxhub/dashboard-icons/png/${name + .replace(/\s+/g, '-') + .toLowerCase()}.png`, + }; +} + export default async function addToHomarr( container: Dockerode.ContainerInfo, config: Config, @@ -29,7 +48,7 @@ export default async function addToHomarr( name: container.Names[0].substring(1), id: container.Id, type: tryMatchType(container.Image), - url: `${container.Ports.at(0)?.IP}:${container.Ports.at(0)?.PublicPort}`, + url: `localhost:${container.Ports.at(0)?.PublicPort}`, icon: await MatchIcon(container.Names[0].substring(1)), }, ], diff --git a/src/tools/types.ts b/src/tools/types.ts index c66197147..6aa3c70c2 100644 --- a/src/tools/types.ts +++ b/src/tools/types.ts @@ -82,6 +82,12 @@ export type ServiceType = | 'qBittorrent' | 'Transmission'; +export const MatchingImages: { image: string; type: ServiceType }[] = [ + { image: 'lscr.io/linuxserver/radarr', type: 'Radarr' }, + { image: 'lscr.io/linuxserver/sonarr', type: 'Sonarr' }, + { image: 'lscr.io/linuxserver/qbittorrent', type: 'qBittorrent' }, +]; + export interface serviceItem { id: string; name: string;