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