Change createdTime and modifiedTime to createdOn and lastModified
Also, add these values to dictionary data.
This commit is contained in:
parent
5a1384464f
commit
f2f8379f9d
|
@ -109,6 +109,10 @@ export function characterIsUppercase (character) {
|
|||
return character === character.toUpperCase();
|
||||
}
|
||||
|
||||
export function timestampInSeconds () {
|
||||
return Math.round(Date.now() / 1000);
|
||||
}
|
||||
|
||||
export function getWordsStats (words, partsOfSpeech, isCaseSensitive = false) {
|
||||
const wordStats = {
|
||||
numberOfWords: [
|
||||
|
|
|
@ -2,6 +2,7 @@ import assert from 'assert';
|
|||
import store from 'store';
|
||||
import wordDb from './WordDatabase';
|
||||
import idManager from './IDManager';
|
||||
import { timestampInSeconds } from '../Helpers';
|
||||
|
||||
const defaultDictionary = {
|
||||
name: 'New',
|
||||
|
@ -41,6 +42,8 @@ const defaultDictionary = {
|
|||
isComplete: false,
|
||||
isPublic: false,
|
||||
},
|
||||
lastUpdated: null,
|
||||
createdOn: timestampInSeconds(),
|
||||
};
|
||||
|
||||
class DictionaryData {
|
||||
|
@ -324,6 +327,18 @@ class DictionaryData {
|
|||
return store.set('Lexiconga', updatedValues);
|
||||
}
|
||||
|
||||
get lastUpdated () {
|
||||
return store.get('Lexiconga').lastUpdated
|
||||
|| defaultDictionary.lastUpdated;
|
||||
}
|
||||
|
||||
set lastUpdated (value) {
|
||||
assert(typeof value === 'number', 'lastUpdated must be passed as a number.');
|
||||
const updatedValues = store.get('Lexiconga');
|
||||
updatedValues.lastUpdated = value;
|
||||
return store.set('Lexiconga', updatedValues);
|
||||
}
|
||||
|
||||
get wordsPromise () {
|
||||
if (this.sortByDefinition) {
|
||||
return wordDb.words.toCollection().sortBy('definition');
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { timestampInSeconds } from "../Helpers";
|
||||
|
||||
export class Updater {
|
||||
constructor (appWithDictionaryState, dictionary) {
|
||||
this.app = appWithDictionaryState;
|
||||
|
@ -64,6 +66,8 @@ export class Updater {
|
|||
if (updatedDetails.isEmpty()) {
|
||||
reject('No dictionary details have changed.');
|
||||
} else {
|
||||
this.dictionary.lastUpdated = timestampInSeconds();
|
||||
updatedDetails.lastUpdated = this.dictionary.lastUpdated;
|
||||
this.app.setState(updatedDetails, () => {
|
||||
if (updatedDetails.hasOwnProperty('settings')) {
|
||||
this.app.updateDisplayedWords();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import PropTypes from 'prop-types';
|
||||
import store from 'store';
|
||||
import wordDb from './WordDatabase';
|
||||
import {timestampInSeconds} from '../Helpers';
|
||||
|
||||
export class Word {
|
||||
constructor (values = {}) {
|
||||
|
@ -11,8 +12,8 @@ export class Word {
|
|||
partOfSpeech: PropTypes.string,
|
||||
definition: PropTypes.string,
|
||||
details: PropTypes.string,
|
||||
createdTime: PropTypes.number,
|
||||
modifiedTime: PropTypes.number,
|
||||
createdOn: PropTypes.number,
|
||||
lastUpdated: PropTypes.number,
|
||||
}, values, 'value', 'Word');
|
||||
|
||||
const {
|
||||
|
@ -22,8 +23,8 @@ export class Word {
|
|||
partOfSpeech = '',
|
||||
definition = '',
|
||||
details = '',
|
||||
createdTime = null,
|
||||
modifiedTime = null,
|
||||
createdOn = null,
|
||||
lastUpdated = null,
|
||||
} = values;
|
||||
|
||||
this.name = name;
|
||||
|
@ -31,16 +32,15 @@ export class Word {
|
|||
this.partOfSpeech = partOfSpeech;
|
||||
this.definition = definition;
|
||||
this.details = details;
|
||||
this.createdTime = createdTime;
|
||||
this.modifiedTime = modifiedTime;
|
||||
this.createdOn = createdOn;
|
||||
this.lastUpdated = lastUpdated;
|
||||
|
||||
// Only create an id property if an ID exists.
|
||||
if (id) this.id = id;
|
||||
}
|
||||
|
||||
create () {
|
||||
const timestampInSeconds = Math.round(Date.now() / 1000);
|
||||
this.createdTime = timestampInSeconds;
|
||||
this.createdOn = timestampInSeconds();
|
||||
|
||||
// Delete id if it exists to allow creation of new word.
|
||||
if (this.hasOwnProperty('id')) delete this.id;
|
||||
|
@ -56,8 +56,7 @@ export class Word {
|
|||
}
|
||||
|
||||
update () {
|
||||
const timestampInSeconds = Math.round(Date.now() / 1000);
|
||||
this.modifiedTime = timestampInSeconds;
|
||||
this.lastUpdated = timestampInSeconds();
|
||||
|
||||
return wordDb.words.put(this)
|
||||
.then((id) => {
|
||||
|
|
|
@ -4,7 +4,7 @@ import {Word} from './Word';
|
|||
|
||||
const db = new Dexie('Lexiconga');
|
||||
db.version(1).stores({
|
||||
words: '++id, name, partOfSpeech, createdTime, modifiedTime',
|
||||
words: '++id, name, partOfSpeech, createdOn, lastUpdated',
|
||||
});
|
||||
|
||||
if (['emptydb', 'donotsave'].includes(process.env.NODE_ENV)) {
|
||||
|
|
Loading…
Reference in New Issue