also store app version in data object

pull/6/head
casperlamboo 5 years ago
parent 02a7f64d5f
commit 9996728f9c
  1. 3
      index.js
  2. 4
      src/components/App.js
  3. 2
      src/components/DoodlePreview.js
  4. 4
      src/shape/JSONToSketchData.js
  5. 5
      src/shape/docToFile.js
  6. 3
      src/shape/sketchDataToJSON.js

@ -56,8 +56,7 @@ window.addEventListener('keydown', (event) => {
// add model to store
import modelData from './models/circle_error.d3sketch';
import JSONToSketchData from './src/shape/JSONToSketchData.js';
const { data, appVersion } = JSON.parse(modelData);
JSONToSketchData({ data }, appVersion).then(sketch => {
JSONToSketchData(JSON.parse(modelData)).then(sketch => {
store.dispatch(actions.openSketch(sketch));
});

@ -99,8 +99,8 @@ class App extends React.Component {
case 'D3SKETCH':
case 'JSON':
const url = URL.createObjectURL(file);
const { data, appVersion } = await fetch(url).then(result => result.json());
const sketchData = await JSONToSketchData(data, appVersion);
const data = await fetch(url).then(result => result.json());
const sketchData = await JSONToSketchData(data);
openSketch(sketchData);
break;
case 'JPG':

@ -48,7 +48,7 @@ class DoodlePreview extends React.Component {
async componentDidMount() {
let { docData, sketchData } = this.props;
if (docData) sketchData = await JSONToSketchData(docData.data, docData.appVersion);
if (docData) sketchData = await JSONToSketchData(docData);
const { canvas } = this.refs;

@ -68,12 +68,12 @@ function revive(appVersion, key, value) {
return value;
}
export default async function JSONToSketchData(data, appVersion) {
export default async function JSONToSketchData({ data, appVersion }) {
let sketchData;
if (semver.gt(appVersion, '0.17.4')) {
sketchData = reviveObject(data, (key, value) => revive(appVersion, key, value));
} else {
sketchData = JSON.parse(data.data, (key, value) => revive(appVersion, key, value));
sketchData = JSON.parse(data, (key, value) => revive(appVersion, key, value));
}
sketchData = await recursivePromiseApply(sketchData);

@ -9,8 +9,7 @@ export default async function docToFile(db, doc, { image = false, sketch = false
author: doc.author,
id: doc._id,
createdOn: doc.createdOn,
updatedOn: doc.updatedOn,
appVersion: doc.appVersion
updatedOn: doc.updatedOn
};
if (doc.class) response.class = doc.class;
@ -28,7 +27,7 @@ export default async function docToFile(db, doc, { image = false, sketch = false
}
const data = await blobToJSON(doc._attachments.sketch.data);
response.data = await JSONToSketchData(data, appVersion);
response.data = await JSONToSketchData(data);
} else {
const data = { data: doc.data, appVersion };
response.data = await JSONToSketchData(data);

@ -1,4 +1,5 @@
import { vectorArrayToBase64, imageToBase64 } from '../utils/binaryUtils.js';
import { VERSION } from '../constants/general.js';
function createShapeData(shape) {
shape = { ...shape };
@ -59,5 +60,5 @@ export default function sketchDataToJSON({ objectsById, spaces }) {
}
}
return data;
return { data, appVersion: VERSION };
}

Loading…
Cancel
Save