Implement persisted page visits counter

This commit is contained in:
BorysLevytskyi
2021-01-17 11:29:41 +02:00
parent 37d4e76e99
commit 9f5059f7a0
2 changed files with 13 additions and 2 deletions

View File

@@ -19,6 +19,8 @@ ReactDOM.render(root, document.getElementById('root'));
executeStartupCommands(); executeStartupCommands();
appData.appState.registerVisit();
log.debug("started"); log.debug("started");
function executeStartupCommands() { function executeStartupCommands() {

View File

@@ -7,6 +7,7 @@ export type PersistedAppData = {
uiTheme: string; uiTheme: string;
version: number; version: number;
debugMode: boolean | null; debugMode: boolean | null;
pageVisistsCount: number;
} }
export type CommandResultView = { export type CommandResultView = {
@@ -28,6 +29,7 @@ export default class AppState {
persistedVersion: number; persistedVersion: number;
wasOldVersion: boolean; wasOldVersion: boolean;
env: string; env: string;
pageVisitsCount: number;
constructor(persistData : PersistedAppData, env: string) { constructor(persistData : PersistedAppData, env: string) {
this.commandResults = []; this.commandResults = [];
@@ -39,6 +41,7 @@ export default class AppState {
this.persistedVersion = persistData.version || 0.1; this.persistedVersion = persistData.version || 0.1;
this.wasOldVersion = persistData.version != null && this.version > this.persistedVersion; this.wasOldVersion = persistData.version != null && this.version > this.persistedVersion;
this.debugMode = env !== 'prod' || persistData.debugMode === true; this.debugMode = env !== 'prod' || persistData.debugMode === true;
this.pageVisitsCount = persistData.pageVisistsCount || 0;
} }
addCommandResult(input : string, view : JSX.Element) { addCommandResult(input : string, view : JSX.Element) {
@@ -76,12 +79,18 @@ export default class AppState {
this.triggerChanged(); this.triggerChanged();
} }
registerVisit() {
this.pageVisitsCount++;
this.triggerChanged();
}
getPersistData() : PersistedAppData { getPersistData() : PersistedAppData {
return { return {
emphasizeBytes: this.emphasizeBytes, emphasizeBytes: this.emphasizeBytes,
uiTheme: this.uiTheme, uiTheme: this.uiTheme,
version: this.version, version: this.version,
debugMode: this.debugMode debugMode: this.debugMode,
pageVisistsCount: this.pageVisitsCount
} }
} }
}; };