From 48ca5352c94e1863050ea1e3003fe873fc050aaf Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Mon, 27 Nov 2023 00:14:41 +0100 Subject: [PATCH] Add client side reload of the config with the newly added apps --- .../Docker/docker-select-board.modal.tsx | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/components/Manage/Tools/Docker/docker-select-board.modal.tsx b/src/components/Manage/Tools/Docker/docker-select-board.modal.tsx index 63b4da364..4248f4b0e 100644 --- a/src/components/Manage/Tools/Docker/docker-select-board.modal.tsx +++ b/src/components/Manage/Tools/Docker/docker-select-board.modal.tsx @@ -6,7 +6,9 @@ import { IconCheck, IconX } from '@tabler/icons-react'; import { ContainerInfo } from 'dockerode'; import { Trans, useTranslation } from 'next-i18next'; import { z } from 'zod'; +import { useConfigContext } from '~/config/provider'; import { useConfigStore } from '~/config/store'; +import { generateDefaultApp } from '~/tools/shared/app'; import { api } from '~/utils/api'; import { useI18nZodResolver } from '~/utils/i18n-zod-resolver'; @@ -23,15 +25,18 @@ export const DockerSelectBoardModal = ({ id, innerProps }: ContextModalProps store.updateConfig); const handleSubmit = async (values: FormType) => { + const newApps = innerProps.containers.map((container) => ({ + name: (container.Names.at(0) ?? 'App').replace('/', ''), + port: container.Ports.at(0)?.PublicPort, + icon: container.icon, + })); await mutateAsync( { - apps: innerProps.containers.map((container) => ({ - name: (container.Names.at(0) ?? 'App').replace('/', ''), - port: container.Ports.at(0)?.PublicPort, - icon: container.icon, - })), + apps: newApps, boardName: values.board, }, { @@ -42,7 +47,21 @@ export const DockerSelectBoardModal = ({ id, innerProps }: ContextModalProps, color: 'green', }); - //TODO: Update config or reload it from server + updateConfig(configName!, (config) => { + const lowestWrapper = config?.wrappers.sort((a, b) => a.position - b.position)[0]; + const defaultApp = generateDefaultApp(lowestWrapper.id); + return { + ...config, + apps: [ + ...config.apps, + ...newApps.map((app) => ({ + ...defaultApp, + ...app, + wrapperId: lowestWrapper.id, + })), + ], + }; + }); modals.close(id); }, onError: () => { @@ -125,4 +144,3 @@ export const openDockerSelectBoardModal = (innerProps: InnerProps) => { function uuidv4(): any { throw new Error('Function not implemented.'); } -