Merge branch 'feature' of git://github.com/siddhant1/p5.js-web-editor into siddhant1-feature

This commit is contained in:
Cassie Tarakajian 2019-03-04 12:33:39 -05:00
commit 02e2a7b0ce
6 changed files with 65 additions and 36 deletions

View file

@ -1,13 +1,13 @@
import format from 'date-fns/format';
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import moment from 'moment';
import { Link, browserHistory } from 'react-router';
import InlineSVG from 'react-inlinesvg';
import { Helmet } from 'react-helmet';
import * as SketchActions from '../actions/projects';
import InlineSVG from 'react-inlinesvg';
import { connect } from 'react-redux';
import { browserHistory, Link } from 'react-router';
import { bindActionCreators } from 'redux';
import * as ProjectActions from '../actions/project';
import * as SketchActions from '../actions/projects';
import * as ToastActions from '../actions/toast';
const trashCan = require('../../../images/trash-can.svg');
@ -73,8 +73,8 @@ class SketchList extends React.Component {
})()}
</td>
<th scope="row"><Link to={`/${username}/sketches/${sketch.id}`}>{sketch.name}</Link></th>
<td>{moment(sketch.createdAt).format('MMM D, YYYY h:mm A')}</td>
<td>{moment(sketch.updatedAt).format('MMM D, YYYY h:mm A')}</td>
<td>{format(new Date(sketch.createdAt), 'MMM D, YYYY h:mm A')}</td>
<td>{format(new Date(sketch.updatedAt), 'MMM D, YYYY h:mm A')}</td>
</tr>)}
</tbody>
</table>}

View file

@ -1,7 +1,8 @@
import classNames from 'classnames';
import differenceInMilliseconds from 'date-fns/difference_in_milliseconds';
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import PropTypes from 'prop-types';
import React from 'react';
import moment from 'moment';
import classNames from 'classnames';
class Timer extends React.Component {
constructor(props) {
@ -20,16 +21,19 @@ class Timer extends React.Component {
}
showSavedTime() {
if (Math.abs(moment().diff(this.props.projectSavedTime)) < 10000) {
const now = new Date();
if (Math.abs(differenceInMilliseconds(now, this.props.projectSavedTime) < 10000)) {
return 'Saved: just now';
} else if (Math.abs(moment().diff(this.props.projectSavedTime)) < 20000) {
} else if (differenceInMilliseconds(now, this.props.projectSavedTime) < 20000) {
return 'Saved: 15 seconds ago';
} else if (Math.abs(moment().diff(this.props.projectSavedTime)) < 30000) {
} else if (differenceInMilliseconds(now, this.props.projectSavedTime) < 30000) {
return 'Saved: 25 seconds ago';
} else if (Math.abs(moment().diff(this.props.projectSavedTime)) < 46000) {
} else if (differenceInMilliseconds(now, this.props.projectSavedTime) < 46000) {
return 'Saved: 35 seconds ago';
}
return `Saved: ${moment(this.props.projectSavedTime).fromNow()}`;
return `Saved: ${distanceInWordsToNow(this.props.projectSavedTime, {
includeSeconds: true
})} ago`;
}
render() {

46
package-lock.json generated
View file

@ -3442,6 +3442,11 @@
"semver": "^5.5.0"
}
},
"date-fns": {
"version": "1.30.1",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.30.1.tgz",
"integrity": "sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw=="
},
"date-now": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz",
@ -5076,7 +5081,8 @@
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true
"bundled": true,
"optional": true
},
"aproba": {
"version": "1.2.0",
@ -5094,11 +5100,13 @@
},
"balanced-match": {
"version": "1.0.0",
"bundled": true
"bundled": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -5111,15 +5119,18 @@
},
"code-point-at": {
"version": "1.1.0",
"bundled": true
"bundled": true,
"optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true
"bundled": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true
"bundled": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
@ -5222,7 +5233,8 @@
},
"inherits": {
"version": "2.0.3",
"bundled": true
"bundled": true,
"optional": true
},
"ini": {
"version": "1.3.5",
@ -5232,6 +5244,7 @@
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -5244,17 +5257,20 @@
"minimatch": {
"version": "3.0.4",
"bundled": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"bundled": true
"bundled": true,
"optional": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -5271,6 +5287,7 @@
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -5343,7 +5360,8 @@
},
"number-is-nan": {
"version": "1.0.1",
"bundled": true
"bundled": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
@ -5353,6 +5371,7 @@
"once": {
"version": "1.4.0",
"bundled": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -5428,7 +5447,8 @@
},
"safe-buffer": {
"version": "5.1.2",
"bundled": true
"bundled": true,
"optional": true
},
"safer-buffer": {
"version": "2.1.2",
@ -5458,6 +5478,7 @@
"string-width": {
"version": "1.0.2",
"bundled": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -5475,6 +5496,7 @@
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -5513,11 +5535,13 @@
},
"wrappy": {
"version": "1.0.2",
"bundled": true
"bundled": true,
"optional": true
},
"yallist": {
"version": "3.0.3",
"bundled": true
"bundled": true,
"optional": true
}
}
},

View file

@ -96,6 +96,7 @@
"cors": "^2.8.5",
"cross-env": "^5.2.0",
"csslint": "^0.10.0",
"date-fns": "^1.30.1",
"decomment": "^0.8.7",
"dotenv": "^2.0.0",
"dropzone": "^4.3.0",

View file

@ -1,6 +1,5 @@
import each from 'async/each';
import moment from 'moment';
import isBefore from 'date-fns/is_before';
import Project from '../models/project';
import { resolvePathToFile } from '../utils/filePath';
import { deleteObjectsFromS3, getObjectKey } from './aws.controller';
@ -56,7 +55,7 @@ function deleteMany(files, ids) {
each(ids, (id, cb) => {
if (files.id(id).url) {
if (!process.env.S3_DATE
|| (process.env.S3_DATE && moment(process.env.S3_DATE) < moment(files.id(id).createdAt))) {
|| (process.env.S3_DATE && isBefore(new Date(process.env.S3_DATE), new Date(files.id(id).createdAt)))) {
const objectKey = getObjectKey(files.id(id).url);
objectKeys.push(objectKey);
}

View file

@ -1,13 +1,14 @@
import archiver from 'archiver';
import request from 'request';
import moment from 'moment';
import format from 'date-fns/format';
import isUrl from 'is-url';
import slugify from 'slugify';
import jsdom, { serializeDocument } from 'jsdom';
import { resolvePathToFile } from '../utils/filePath';
import generateFileSystemSafeName from '../utils/generateFileSystemSafeName';
import isBefore from 'date-fns/is_before';
import request from 'request';
import slugify from 'slugify';
import Project from '../models/project';
import User from '../models/user';
import { resolvePathToFile } from '../utils/filePath';
import generateFileSystemSafeName from '../utils/generateFileSystemSafeName';
import { deleteObjectsFromS3, getObjectKey } from './aws.controller';
export function createProject(req, res) {
@ -109,7 +110,7 @@ export function getProject(req, res) {
function deleteFilesFromS3(files) {
deleteObjectsFromS3(files.filter((file) => {
if (file.url) {
if (!process.env.S3_DATE || (process.env.S3_DATE && moment(process.env.S3_DATE) < moment(file.createdAt))) {
if (!process.env.S3_DATE || (process.env.S3_DATE && isBefore(new Date(process.env.S3_DATE), new Date(file.createdAt)))) {
return true;
}
}
@ -291,7 +292,7 @@ function buildZip(project, req, res) {
res.status(500).send({ error: err.message });
});
const currentTime = moment().format('YYYY_MM_DD_HH_mm_ss');
const currentTime = format(new Date(), 'YYYY_MM_DD_HH_mm_ss');
project.slug = slugify(project.name, '_');
res.attachment(`${generateFileSystemSafeName(project.slug)}_${currentTime}.zip`);
zip.pipe(res);