diff --git a/studio-frontend/src/app/app.element.ts b/studio-frontend/src/app/app.element.ts index 011106f..17c336d 100644 --- a/studio-frontend/src/app/app.element.ts +++ b/studio-frontend/src/app/app.element.ts @@ -11,11 +11,14 @@ import { DialogElement } from "@storyteller/studio-ui/dialog"; import { SceneHierarchyElement, StorytellerApi, + StorytellerLocalApi, + StorytellerRemoteApi, StudioURLParams, + mockApi, } from "@storyteller/studio-web"; import { match } from "@storyteller/utility"; import { LitElement, TemplateResult, html, nothing } from "lit"; -import { customElement, state } from "lit/decorators.js"; +import { customElement, property, state } from "lit/decorators.js"; import { classMap } from "lit/directives/class-map.js"; import { createRef, ref } from "lit/directives/ref.js"; import { styleMap } from "lit/directives/style-map.js"; @@ -57,7 +60,7 @@ export class AppElement extends LitElement { @state() currentSidebar : string = 'hierarchy'; - private api = new StorytellerApi(); + @property({ attribute: false }) api: StorytellerApi = new StorytellerApi(mockApi ? new StorytellerLocalApi() : new StorytellerRemoteApi()); #addToSceneButtonRef = createRef(); #videoStylePreviewBtnRef = createRef(); diff --git a/studio-web/src/lib/storyteller-api.ts b/studio-web/src/lib/storyteller-api.ts index bc786d3..980bb3e 100644 --- a/studio-web/src/lib/storyteller-api.ts +++ b/studio-web/src/lib/storyteller-api.ts @@ -3,7 +3,7 @@ import { v4 as uuid } from "uuid"; import { DBSchema, IDBPDatabase, openDB } from "idb"; import * as studio from "@storyteller/studio"; -const mockApi = window.location.search.includes("mock-api"); +export const mockApi = window.location.search.includes("mock-api"); interface IStorytellerApi { createScene(file: File): Promise @@ -18,7 +18,7 @@ interface IStorytellerApi { mediaFile(token: MediaFileToken): Promise } -class StorytellerApiBase implements IStorytellerApi { +export class StorytellerRemoteApi implements IStorytellerApi { #api = axios.create({ baseURL: "https://api.fakeyou.com", withCredentials: true, @@ -137,7 +137,7 @@ interface LocalDbSchema extends DBSchema { } } -class StorytellerApiMock implements IStorytellerApi { +export class StorytellerLocalApi implements IStorytellerApi { database?: IDBPDatabase; dateFormat: Intl.DateTimeFormat = new Intl.DateTimeFormat("en-us") @@ -437,27 +437,31 @@ class StorytellerApiMock implements IStorytellerApi { export class StorytellerApi implements IStorytellerApi { createScene(file: File): Promise { - return this.api_base.createScene(file) + return this.apiBase.createScene(file) } session(): Promise { - return this.api_base.session() + return this.apiBase.session() } listMediaFiles(options: ListMediaFilesOptions): Promise { - return this.api_base.listMediaFiles(options) + return this.apiBase.listMediaFiles(options) } uploadMediaFile(file: File, { subtype, mediaClass }: UploadMediaFileOptions): Promise { - return this.api_base.uploadMediaFile(file, { subtype, mediaClass }) + return this.apiBase.uploadMediaFile(file, { subtype, mediaClass }) } renameMediaFile(token: string, name: string): Promise { - return this.api_base.renameMediaFile(token, name) + return this.apiBase.renameMediaFile(token, name) } convertFbxToGltf(token: string): Promise { - return this.api_base.convertFbxToGltf(token) + return this.apiBase.convertFbxToGltf(token) } mediaFile(token: string): Promise { - return this.api_base.mediaFile(token) + return this.apiBase.mediaFile(token) + } + apiBase: IStorytellerApi; + + constructor(apiBase: IStorytellerApi) { + this.apiBase = apiBase } - api_base: IStorytellerApi = mockApi ? new StorytellerApiMock() : new StorytellerApiBase(); } export class ApiError extends Error {