From e11da6667b0f9e91a6357ce9c8ef560380419054 Mon Sep 17 00:00:00 2001 From: axel7083 <42176370+axel7083@users.noreply.github.com> Date: Mon, 22 Jan 2024 12:02:46 +0100 Subject: [PATCH] fix: revert + using state management Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> --- .../backend/src/registries/RouterRegistry.ts | 36 ------------------- packages/backend/src/studio-api-impl.spec.ts | 2 -- packages/backend/src/studio-api-impl.ts | 10 ------ packages/backend/src/studio.ts | 3 -- packages/frontend/src/App.svelte | 13 ++++--- packages/frontend/src/Route.svelte | 11 +++--- packages/frontend/src/pages/Model.spec.ts | 2 -- packages/frontend/src/utils/client.ts | 15 ++++++++ packages/shared/src/StudioAPI.ts | 4 --- 9 files changed, 29 insertions(+), 67 deletions(-) delete mode 100644 packages/backend/src/registries/RouterRegistry.ts diff --git a/packages/backend/src/registries/RouterRegistry.ts b/packages/backend/src/registries/RouterRegistry.ts deleted file mode 100644 index a97baad27..000000000 --- a/packages/backend/src/registries/RouterRegistry.ts +++ /dev/null @@ -1,36 +0,0 @@ -/********************************************************************** - * Copyright (C) 2024 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ***********************************************************************/ -import type { RouterState } from '@shared/src/models/IRouterState'; - -export class RouterRegistry { - private state: RouterState; - - constructor() { - this.state = { - url: '/', - }; - } - - getRouterState(): RouterState { - return this.state; - } - - setRouterState(state: RouterState) { - this.state = state; - } -} diff --git a/packages/backend/src/studio-api-impl.spec.ts b/packages/backend/src/studio-api-impl.spec.ts index 618ed4d9f..71c31bbd6 100644 --- a/packages/backend/src/studio-api-impl.spec.ts +++ b/packages/backend/src/studio-api-impl.spec.ts @@ -30,7 +30,6 @@ import type { Webview } from '@podman-desktop/api'; import * as fs from 'node:fs'; import { CatalogManager } from './managers/catalogManager'; -import type { RouterRegistry } from './registries/RouterRegistry'; vi.mock('./ai.json', () => { return { @@ -79,7 +78,6 @@ beforeEach(async () => { {} as unknown as TaskRegistry, {} as unknown as PlayGroundManager, catalogManager, - {} as unknown as RouterRegistry, ); vi.resetAllMocks(); vi.mock('node:fs'); diff --git a/packages/backend/src/studio-api-impl.ts b/packages/backend/src/studio-api-impl.ts index 1d3c75e6d..a36f268e5 100644 --- a/packages/backend/src/studio-api-impl.ts +++ b/packages/backend/src/studio-api-impl.ts @@ -31,8 +31,6 @@ import * as path from 'node:path'; import type { CatalogManager } from './managers/catalogManager'; import type { Catalog } from '@shared/src/models/ICatalog'; import type { PlaygroundState } from '@shared/src/models/IPlaygroundState'; -import type { RouterState } from '@shared/src/models/IRouterState'; -import type { RouterRegistry } from './registries/RouterRegistry'; export class StudioApiImpl implements StudioAPI { constructor( @@ -41,7 +39,6 @@ export class StudioApiImpl implements StudioAPI { private taskRegistry: TaskRegistry, private playgroundManager: PlayGroundManager, private catalogManager: CatalogManager, - private routerRegistry: RouterRegistry, ) {} async ping(): Promise { @@ -126,11 +123,4 @@ export class StudioApiImpl implements StudioAPI { async getCatalog(): Promise { return this.catalogManager.getCatalog(); } - - async saveRouterState(state: RouterState): Promise { - this.routerRegistry.setRouterState(state); - } - async getRouterState(): Promise { - return this.routerRegistry.getRouterState(); - } } diff --git a/packages/backend/src/studio.ts b/packages/backend/src/studio.ts index 86a3a1071..15db733c0 100644 --- a/packages/backend/src/studio.ts +++ b/packages/backend/src/studio.ts @@ -28,7 +28,6 @@ import * as fs from 'node:fs'; import { TaskRegistry } from './registries/TaskRegistry'; import { PlayGroundManager } from './managers/playground'; import { CatalogManager } from './managers/catalogManager'; -import { RouterRegistry } from './registries/RouterRegistry'; export class Studio { readonly #extensionContext: ExtensionContext; @@ -98,7 +97,6 @@ export class Studio { this.playgroundManager = new PlayGroundManager(this.#panel.webview); // Create catalog manager, responsible for loading the catalog files and watching for changes this.catalogManager = new CatalogManager(applicationManager.appUserDirectory, this.#panel.webview); - const routerRegister = new RouterRegistry(); // Creating StudioApiImpl this.studioApi = new StudioApiImpl( @@ -107,7 +105,6 @@ export class Studio { taskRegistry, this.playgroundManager, this.catalogManager, - routerRegister, ); await this.catalogManager.loadCatalog(); diff --git a/packages/frontend/src/App.svelte b/packages/frontend/src/App.svelte index 9780b97bd..33d0d0435 100644 --- a/packages/frontend/src/App.svelte +++ b/packages/frontend/src/App.svelte @@ -11,21 +11,24 @@ import Preferences from '/@/pages/Preferences.svelte'; import Registries from '/@/pages/Registries.svelte'; import Models from '/@/pages/Models.svelte'; import Recipe from '/@/pages/Recipe.svelte'; - import Model from './pages/Model.svelte'; +import Model from './pages/Model.svelte'; import { onMount } from 'svelte'; -import { studioClient } from '/@/utils/client'; +import { getRouterState } from '/@/utils/client'; router.mode.hash(); -onMount(async () => { +let isMounted = false; + +onMount(() => { // Load router state on application startup - const state = await studioClient.getRouterState(); + const state = getRouterState(); router.goto(state.url); + isMounted = true; }); - +
diff --git a/packages/frontend/src/Route.svelte b/packages/frontend/src/Route.svelte index d174c1ac0..c45d45c14 100644 --- a/packages/frontend/src/Route.svelte +++ b/packages/frontend/src/Route.svelte @@ -1,7 +1,7 @@