From 75fe5733829985cc94639f3208ddafe42364ae4a Mon Sep 17 00:00:00 2001 From: Antonio Sonis Date: Sun, 3 Dec 2023 23:31:56 +0100 Subject: [PATCH] feat: adding index stuff Signed-off-by: Antonio Sonis --- src/main/index.mjs | 6 ++++++ src/preload/index.js | 3 ++- src/renderer/src/components/steps/CreateApplication.jsx | 5 +++-- .../steps/compose-application/ComposeApplication.jsx | 7 ++++++- src/renderer/src/useStackablesStore.js | 5 ++--- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/index.mjs b/src/main/index.mjs index ccd029e7..f10da6cd 100644 --- a/src/main/index.mjs +++ b/src/main/index.mjs @@ -6,6 +6,7 @@ import icon from '../../resources/icon.png?asset' import setupMenu from './menu.mjs' import { getTemplates, getPlugins } from './client.mjs' import { prepareFolder, createApp } from './generate.mjs' +const generate = require('boring-name-generator') // eslint-disable-next-line no-unused-vars const isMac = process.platform === 'darwin' @@ -116,6 +117,11 @@ app.whenReady().then(() => { ipcMain.handle('quit-app', () => { app.quit() }) + + ipcMain.handle('generate-name', async () => { + const val = await generate({ words: 1 }).dashed + return val + }) }) // Quit when all windows are closed, except on macOS. There, it's common diff --git a/src/preload/index.js b/src/preload/index.js index 961ad3e2..757dd347 100644 --- a/src/preload/index.js +++ b/src/preload/index.js @@ -20,7 +20,8 @@ if (process.contextIsolated) { prepareFolder: (folder, templates, appName) => (ipcRenderer.invoke('prepare-folder', folder, templates, appName)), onLog: callback => ipcRenderer.on('log', callback), createApp: (folder, project) => (ipcRenderer.invoke('create-app', folder, project)), - quitApp: () => (ipcRenderer.invoke('quit-app')) + quitApp: () => (ipcRenderer.invoke('quit-app')), + getServiceName: () => (ipcRenderer.invoke('generate-name')) }) } catch (error) { console.error(error) diff --git a/src/renderer/src/components/steps/CreateApplication.jsx b/src/renderer/src/components/steps/CreateApplication.jsx index 5fbe15ae..b1cf1545 100644 --- a/src/renderer/src/components/steps/CreateApplication.jsx +++ b/src/renderer/src/components/steps/CreateApplication.jsx @@ -28,7 +28,7 @@ const CreateApplication = React.forwardRef(({ onNext }, ref) => { } }, [formData]) - function handleSubmit (event) { + async function handleSubmit (event) { event.preventDefault() addFormData({ createApplication: { @@ -37,7 +37,8 @@ const CreateApplication = React.forwardRef(({ onNext }, ref) => { } }) if (callAddService) { - addService() + const serviceName = await window.api.getServiceName() + addService(serviceName) } onNext() } diff --git a/src/renderer/src/components/steps/compose-application/ComposeApplication.jsx b/src/renderer/src/components/steps/compose-application/ComposeApplication.jsx index e4145103..e2a6e042 100644 --- a/src/renderer/src/components/steps/compose-application/ComposeApplication.jsx +++ b/src/renderer/src/components/steps/compose-application/ComposeApplication.jsx @@ -106,6 +106,11 @@ const ComposeApplication = React.forwardRef(({ onNext, onBack }, ref) => { setShowModalViewAll(false) } + async function onClickAddService () { + const serviceName = await window.api.getServiceName() + addService(serviceName) + } + function handleEditApplicationName (newName) { addFormData({ createApplication: { @@ -181,7 +186,7 @@ const ComposeApplication = React.forwardRef(({ onNext, onBack }, ref) => {
 
addService()} + onClick={() => onClickAddService()} enabled={services.find(service => Object.keys(service.template).length === 0) === undefined || currentView === GRID_VIEW} /> diff --git a/src/renderer/src/useStackablesStore.js b/src/renderer/src/useStackablesStore.js index dabf5caa..442e53e3 100644 --- a/src/renderer/src/useStackablesStore.js +++ b/src/renderer/src/useStackablesStore.js @@ -1,5 +1,4 @@ import { create } from 'zustand' -import { generateName } from '../../main/client.mjs' const useStackablesStore = create((set, get) => ({ formData: {}, @@ -10,12 +9,12 @@ const useStackablesStore = create((set, get) => ({ formData: { ...get().formData, ...newValue } } }), - addService: () => set((state) => { + addService: (serviceName) => set((state) => { const currentServices = get().services return { ...state, services: [...currentServices, { - name: generateName({ words: 1 }), + name: serviceName, template: {}, plugins: [] }]