🔥 Remove old and unused components

This commit is contained in:
Manuel Ruwe
2022-12-23 17:17:57 +01:00
parent b23f464140
commit f3b601dc2d
37 changed files with 131 additions and 1945 deletions

View File

@@ -35,23 +35,3 @@ export function tryMatchService(container: Dockerode.ContainerInfo | undefined)
.toLowerCase()}.png`,
};
}
export default async function addToHomarr(
container: Dockerode.ContainerInfo,
config: Config,
setConfig: (newconfig: Config) => void
) {
setConfig({
...config,
apps: [
...config.apps,
{
name: container.Names[0].substring(1),
id: container.Id,
type: tryMatchType(container.Image),
url: `localhost:${container.Ports.at(0)?.PublicPort}`,
icon: await MatchIcon(container.Names[0].substring(1)),
},
],
});
}

View File

@@ -6,7 +6,7 @@ export const getFallbackConfig = (name?: string): BackendConfigType => ({
name: name ?? 'default',
},
categories: [],
widgets: {},
widgets: [],
apps: [],
settings: {
common: {

View File

@@ -6,18 +6,17 @@ export const getFrontendConfig = (name: string): ConfigType => {
return {
...config,
apps: config.apps.map((s) => ({
...s,
integration: s.integration
? {
...s.integration,
properties: s.integration?.properties.map((p) => ({
...p,
value: p.type === 'private' ? null : p.value,
isDefined: p.value != null,
})),
}
: null,
apps: config.apps.map((app) => ({
...app,
integration: {
...app.integration ?? null,
type: app.integration?.type ?? null,
properties: app.integration?.properties.map((property) => ({
...property,
value: property.type === 'private' ? undefined : property.value,
isDefined: property.value != null,
})) ?? [],
},
})),
};
};

View File

@@ -1,13 +0,0 @@
import { useConfig } from '../state';
import { Config, ServiceType } from '../types';
export const useGetServiceByType = (...serviceTypes: ServiceType[]) => {
const { config } = useConfig();
return getServiceByType(config, ...serviceTypes);
};
export const getServiceByType = (config: Config, ...serviceTypes: ServiceType[]) =>
config.apps.filter((s) => serviceTypes.includes(s.type));
export const getServiceById = (config: Config, id: string) => config.apps.find((s) => s.id === id);

View File

@@ -1,14 +0,0 @@
import { v4 as uuidv4 } from 'uuid';
import { Config } from './types';
export function migrateToIdConfig(config: Config): Config {
// Set the config and add an ID to all the services that don't have one
const services = config.apps.map((service) => ({
...service,
id: service.id ?? uuidv4(),
}));
return {
...config,
apps: services,
};
}

View File

@@ -1,92 +0,0 @@
// src/context/state.js
import { showNotification } from '@mantine/notifications';
import axios from 'axios';
import { createContext, ReactNode, useContext, useState } from 'react';
import { IconCheck as Check, IconX as X } from '@tabler/icons';
import { Config } from './types';
type configContextType = {
config: Config;
setConfig: (newconfig: Config) => void;
loadConfig: (name: string) => void;
getConfigs: () => Promise<string[]>;
};
const configContext = createContext<configContextType>({
config: {
name: 'default',
apps: [],
settings: {
searchUrl: 'https://google.com/search?q=',
},
modules: {},
},
setConfig: () => {},
loadConfig: async (name: string) => {},
getConfigs: async () => [],
});
export function useConfig() {
const context = useContext(configContext);
if (context === undefined) {
throw new Error('useConfig must be used within a ConfigProvider');
}
return context;
}
type Props = {
children: ReactNode;
};
export function ConfigProvider({ children }: Props) {
const [config, setConfigInternal] = useState<Config>({
name: 'default',
apps: [],
settings: {
searchUrl: 'https://www.google.com/search?q=',
},
modules: {},
});
async function loadConfig(configName: string) {
try {
const response = await axios.get(`/api/configs/${configName}`);
setConfigInternal(JSON.parse(response.data));
showNotification({
title: 'Config',
icon: <Check />,
color: 'green',
autoClose: 1500,
radius: 'md',
message: `Loaded config : ${configName}`,
});
} catch (error) {
showNotification({
title: 'Config',
icon: <X />,
color: 'red',
autoClose: 1500,
radius: 'md',
message: `Error loading config : ${configName}`,
});
}
}
function setConfig(newconfig: Config) {
axios.put(`/api/configs/${newconfig.name}`, newconfig);
setConfigInternal(newconfig);
}
async function getConfigs(): Promise<string[]> {
const response = await axios.get('/api/configs');
return response.data;
}
const value = {
config,
setConfig,
loadConfig,
getConfigs,
};
return <configContext.Provider value={value}>{children}</configContext.Provider>;
}