Add timestamp to createdOn and lastUpdated
This commit is contained in:
parent
22f8c0885a
commit
6d27f40874
|
@ -1,3 +1,6 @@
|
|||
import { getTimestampInSeconds } from "./helpers";
|
||||
|
||||
export const MIGRATE_VERSION = '2.0.0';
|
||||
export const DEFAULT_DICTIONARY = {
|
||||
name: 'New',
|
||||
specification: 'Dictionary',
|
||||
|
@ -47,7 +50,8 @@ export const DEFAULT_DICTIONARY = {
|
|||
isPublic: false,
|
||||
},
|
||||
lastUpdated: null,
|
||||
createdOn: 0,
|
||||
createdOn: getTimestampInSeconds(),
|
||||
version: MIGRATE_VERSION,
|
||||
};
|
||||
|
||||
export const DEFAULT_PAGE_SIZE = 50;
|
||||
|
|
|
@ -4,6 +4,28 @@ export function cloneObject(object) {
|
|||
return JSON.parse(JSON.stringify(object));
|
||||
}
|
||||
|
||||
export function getIndicesOf(searchStr, findIn, caseSensitive) {
|
||||
// https://stackoverflow.com/a/3410557
|
||||
const searchStrLen = searchStr.length;
|
||||
if (searchStrLen == 0) {
|
||||
return [];
|
||||
}
|
||||
let startIndex = 0, index, indices = [];
|
||||
if (!caseSensitive) {
|
||||
findIn = findIn.toLowerCase();
|
||||
searchStr = searchStr.toLowerCase();
|
||||
}
|
||||
while ((index = findIn.indexOf(searchStr, startIndex)) > -1) {
|
||||
indices.push(index);
|
||||
startIndex = index + searchStrLen;
|
||||
}
|
||||
return indices;
|
||||
}
|
||||
|
||||
export function getTimestampInSeconds() {
|
||||
return Math.round(Date.now() / 1000);
|
||||
}
|
||||
|
||||
export function removeTags(html) {
|
||||
if (html) {
|
||||
var tagBody = '(?:[^"\'>]|"[^"]*"|\'[^\']*\')*';
|
||||
|
@ -32,21 +54,3 @@ export function removeTags(html) {
|
|||
export function slugify(string) {
|
||||
return removeDiacritics(string).replace(/[!a-zA-Z0-9-_]/g, '-');
|
||||
}
|
||||
|
||||
export function getIndicesOf(searchStr, findIn, caseSensitive) {
|
||||
// https://stackoverflow.com/a/3410557
|
||||
const searchStrLen = searchStr.length;
|
||||
if (searchStrLen == 0) {
|
||||
return [];
|
||||
}
|
||||
let startIndex = 0, index, indices = [];
|
||||
if (!caseSensitive) {
|
||||
findIn = findIn.toLowerCase();
|
||||
searchStr = searchStr.toLowerCase();
|
||||
}
|
||||
while ((index = findIn.indexOf(searchStr, startIndex)) > -1) {
|
||||
indices.push(index);
|
||||
startIndex = index + searchStrLen;
|
||||
}
|
||||
return indices;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { renderDictionaryDetails, renderPartsOfSpeech } from "./render";
|
||||
import { removeTags, cloneObject } from "../helpers";
|
||||
import { removeTags, cloneObject, getTimestampInSeconds } from "../helpers";
|
||||
import { LOCAL_STORAGE_KEY, DEFAULT_DICTIONARY } from "../constants";
|
||||
|
||||
export function updateDictionary () {
|
||||
|
@ -73,6 +73,7 @@ export function saveAndCloseEditModal() {
|
|||
}
|
||||
|
||||
export function saveDictionary() {
|
||||
window.currentDictionary.lastUpdated = getTimestampInSeconds();
|
||||
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(window.currentDictionary));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue