Skip to content

Commit

Permalink
Add ability to export a JSON file to send in an API request
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Jan 1, 2024
1 parent a7e7c66 commit a048b2d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
18 changes: 17 additions & 1 deletion composables/useProjectStoreFactory.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import download from 'downloadjs';
import { v4 as uuid } from 'uuid';
import { cloneDeep, replace } from 'lodash';
import { defineStore } from 'pinia';
import useIndexedDb from './useIndexedDb';
import { namespace } from './useProjectStores';
import useTemplateStore from './useTemplateStore';
import { cloneDeep, replace, omit } from 'lodash';

export default function (id, initialValue = null) {
const storage = useIndexedDb(
Expand Down Expand Up @@ -74,6 +74,22 @@ export default function (id, initialValue = null) {
download(JSON.stringify(state, null, 2), `${name}.json`);
},

/**
* Export the project into a JSON file for an API request.
*/
exportForApi() {
const state = this.clone();

const json = {
settings: omit(state.settings, ['image']),
editors: state.page.editors,
};

const name = state.tab.name || 'json';

download(JSON.stringify(json, null, 2), `${name}.json`);
},

/**
* Save the project as a template.
*/
Expand Down
9 changes: 7 additions & 2 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,19 @@ export default {
{
separator: true,
},
{
name: 'export-json',
title: 'Export JSON (API Request)',
click: () => currentProject.value?.exportForApi(),
},
{
name: 'export-config',
title: 'Export Configuration',
title: 'Export JSON Configuration',
click: () => currentProject.value?.export(),
},
{
name: 'import-config',
title: 'Import Configuration',
title: 'Import JSON Configuration',
click: importNewProject,
},
{
Expand Down

0 comments on commit a048b2d

Please sign in to comment.