From 832542c1c579cc0c1143e51478a128346b6136d6 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Mon, 9 Aug 2021 17:12:20 +0200 Subject: [PATCH] Started implementing "Export Project" --- theatre/studio/src/Studio.ts | 4 ++++ theatre/studio/src/StudioStore/StudioStore.ts | 21 +++++++++++++++++++ .../src/panels/DetailPanel/ProjectDetails.tsx | 20 +++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/theatre/studio/src/Studio.ts b/theatre/studio/src/Studio.ts index 082e097..571f53a 100644 --- a/theatre/studio/src/Studio.ts +++ b/theatre/studio/src/Studio.ts @@ -172,4 +172,8 @@ export class Studio { redo() { this._store.redo() } + + createExportedStateOfProject(projectId: string): string { + return this._store.createExportedStateOfProject(projectId) + } } diff --git a/theatre/studio/src/StudioStore/StudioStore.ts b/theatre/studio/src/StudioStore/StudioStore.ts index cef4a6f..56a07bd 100644 --- a/theatre/studio/src/StudioStore/StudioStore.ts +++ b/theatre/studio/src/StudioStore/StudioStore.ts @@ -27,6 +27,7 @@ import type {Store} from 'redux' import {persistStateOfStudio} from './persistStateOfStudio' import {isSheetObject} from '@theatre/shared/instanceTypes' import globals from '@theatre/shared/globals' +import {nanoid} from 'nanoid' export type Drafts = { historic: Draft @@ -269,4 +270,24 @@ export default class StudioStore { redo() { this._reduxStore.dispatch(studioActions.historic.redo()) } + + createExportedStateOfProject(projectId: string): string { + const projectHistoricState = + this._reduxStore.getState().$persistent.historic.innerState.coreByProject[ + projectId + ] + const revision = nanoid(16) + + const s = { + revision, + definitionVersion: globals.currentProjectStateDefinitionVersion, + projectState: projectHistoricState, + } + + // pushOnDiskRevisionBrowserStateIsBasedOn.originalReducer(s, revision) + + const exportString = JSON.stringify(s, null, 2) + + return exportString + } } diff --git a/theatre/studio/src/panels/DetailPanel/ProjectDetails.tsx b/theatre/studio/src/panels/DetailPanel/ProjectDetails.tsx index e2c6ab0..49fffde 100644 --- a/theatre/studio/src/panels/DetailPanel/ProjectDetails.tsx +++ b/theatre/studio/src/panels/DetailPanel/ProjectDetails.tsx @@ -1,4 +1,5 @@ import type Project from '@theatre/core/projects/Project' +import getStudio from '@theatre/studio/getStudio' import React from 'react' const ProjectDetails: React.FC<{ @@ -6,7 +7,24 @@ const ProjectDetails: React.FC<{ }> = ({projects}) => { const project = projects[0] - return
editing project {project.address.projectId}
+ const exportProject = () => { + const str = getStudio().createExportedStateOfProject( + project.address.projectId, + ) + const file = new File([str], 'state.json', {type: 'application/json'}) + const objUrl = URL.createObjectURL(file) + const a = document.createElement('a') + a.href = objUrl + a.target = '_blank' + a.setAttribute('download', 'state.json') + a.click() + } + + return ( +
+ +
+ ) } export default ProjectDetails