Refactored moment.js out of app
Reduces bundle size by 25%
This commit is contained in:
parent
736d7118b0
commit
0ade9b5b9b
7 changed files with 22 additions and 29 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -21,3 +21,4 @@ nbproject
|
|||
.buildpath
|
||||
.project
|
||||
.settings/
|
||||
webpack-stats.json
|
|
@ -275,11 +275,10 @@ class PageController extends Controller
|
|||
$draft = $this->entityRepo->updatePageDraft($page, $request->only(['name', 'html', 'markdown']));
|
||||
|
||||
$updateTime = $draft->updated_at->timestamp;
|
||||
$utcUpdateTimestamp = $updateTime + Carbon::createFromTimestamp(0)->offset;
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => trans('entities.pages_edit_draft_save_at'),
|
||||
'timestamp' => $utcUpdateTimestamp
|
||||
'timestamp' => $updateTime
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
19
package-lock.json
generated
19
package-lock.json
generated
|
@ -3645,15 +3645,6 @@
|
|||
"is-extglob": "1.0.0"
|
||||
}
|
||||
},
|
||||
"extract-loader": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/extract-loader/-/extract-loader-1.0.2.tgz",
|
||||
"integrity": "sha512-hwlXWGHwzBXRNQCkDnLJuNgSkRsmYOwNz7wG9pHfA2EAgQaBCuQR71az7qL3rQT1JAMujiKPc+laet0kddVXWQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"loader-utils": "1.1.0"
|
||||
}
|
||||
},
|
||||
"extract-text-webpack-plugin": {
|
||||
"version": "4.0.0-beta.0",
|
||||
"resolved": "https://registry.npmjs.org/extract-text-webpack-plugin/-/extract-text-webpack-plugin-4.0.0-beta.0.tgz",
|
||||
|
@ -3710,16 +3701,6 @@
|
|||
"escape-string-regexp": "1.0.5"
|
||||
}
|
||||
},
|
||||
"file-loader": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/file-loader/-/file-loader-1.1.11.tgz",
|
||||
"integrity": "sha512-TGR4HU7HUsGg6GCOPJnFk06RhWgEWFLAGWiT6rcD+GRC2keU3s9RGJ+b3Z6/U73jwwNb2gKLJ7YCrp+jvU4ALg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"loader-utils": "1.1.0",
|
||||
"schema-utils": "0.4.5"
|
||||
}
|
||||
},
|
||||
"filename-regex": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"scripts": {
|
||||
"build": "webpack",
|
||||
"production": "NODE_ENV=production webpack && rm -f ./public/dist/*styles.js",
|
||||
"build-profile": "NODE_ENV=production webpack --profile --json > webpack-stats.json && rm -f ./public/dist/*styles.js",
|
||||
"dev": "npm-run-all --parallel watch livereload",
|
||||
"watch": "webpack --watch",
|
||||
"livereload": "livereload ./public/dist/",
|
||||
|
@ -34,7 +35,6 @@
|
|||
"jquery": "^3.3.1",
|
||||
"markdown-it": "^8.3.1",
|
||||
"markdown-it-task-lists": "^2.0.0",
|
||||
"moment": "^2.21.0",
|
||||
"vue": "^2.2.6",
|
||||
"vuedraggable": "^2.14.1"
|
||||
},
|
||||
|
|
15
resources/assets/js/services/dates.js
Normal file
15
resources/assets/js/services/dates.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
export function getCurrentDay() {
|
||||
let date = new Date();
|
||||
let month = date.getMonth() + 1;
|
||||
let day = date.getDate();
|
||||
|
||||
return `${date.getFullYear()}-${(month>9?'':'0') + month}-${(day>9?'':'0') + day}`;
|
||||
}
|
||||
|
||||
export function utcTimeStampToLocalTime(timestamp) {
|
||||
let date = new Date(timestamp * 1000);
|
||||
let hours = date.getHours();
|
||||
let mins = date.getMinutes();
|
||||
return `${(hours>9?'':'0') + hours}:${(mins>9?'':'0') + mins}`;
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
const moment = require('moment');
|
||||
require('moment/locale/en-gb');
|
||||
moment.locale('en-gb');
|
||||
import * as Dates from "../services/dates";
|
||||
|
||||
let autoSaveFrequency = 30;
|
||||
|
||||
|
@ -96,9 +94,8 @@ let methods = {
|
|||
let url = window.baseUrl(`/ajax/page/${this.pageId}/save-draft`);
|
||||
window.$http.put(url, data).then(response => {
|
||||
draftErroring = false;
|
||||
let updateTime = moment.utc(moment.unix(response.data.timestamp)).toDate();
|
||||
if (!this.isNewDraft) this.isUpdateDraft = true;
|
||||
this.draftNotifyChange(response.data.message + moment(updateTime).format('HH:mm'));
|
||||
this.draftNotifyChange(`${response.data.message } ${Dates.utcTimeStampToLocalTime(response.data.timestamp)}`);
|
||||
lastSave = Date.now();
|
||||
}, errorRes => {
|
||||
if (draftErroring) return;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const moment = require('moment');
|
||||
import * as Dates from "../services/dates";
|
||||
|
||||
let data = {
|
||||
terms: '',
|
||||
|
@ -153,7 +153,7 @@ let methods = {
|
|||
},
|
||||
|
||||
enableDate(optionName) {
|
||||
this.search.dates[optionName.toLowerCase()] = moment().format('YYYY-MM-DD');
|
||||
this.search.dates[optionName.toLowerCase()] = Dates.getCurrentDay();
|
||||
this.dateChange(optionName);
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue