Skip to content

Commit

Permalink
fix: refresh data when rendering the statistics UI
Browse files Browse the repository at this point in the history
Signed-off-by: edonyzpc <[email protected]>
  • Loading branch information
edonyzpc committed Mar 25, 2024
1 parent 4cb6612 commit 4fffd54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { RecordPreview, RECORD_PREVIEW_TYPE } from './preview';
import { STAT_PREVIEW_TYPE, Stat } from './statsView'
import StatsManager from './stats/StatsManager'
import { pluginField, statusBarEditorPlugin, sectionWordCountEditorPlugin } from './stats/EditorPlugin'
import { STATS_FILE_NAME } from './constant'

const debug = (debug: boolean, ...msg: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
if (debug) console.log(...msg);
Expand Down Expand Up @@ -89,11 +88,9 @@ export class PluginManager extends Plugin {
RECORD_PREVIEW_TYPE,
(leaf) => { return new RecordPreview(this.app, this, leaf); }
);
const staticsDataDir = this.app.vault.configDir + "/" + STATS_FILE_NAME;
const staticsFileData = await this.app.vault.adapter.read(staticsDataDir);
this.registerView(
STAT_PREVIEW_TYPE,
(leaf) => { return new Stat(this.app, this, leaf, staticsFileData); }
(leaf) => { return new Stat(this.app, this, leaf); }
)
});
this.statsManager = new StatsManager(this.app, this);
Expand Down
8 changes: 5 additions & 3 deletions src/statsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { App, ItemView, WorkspaceLeaf, addIcon } from "obsidian";
import { PluginManager } from "./plugin";
import Statistics from './components/Statistics.svelte'
import { icons } from './utils'
import { PluginAST_STAT_ICON } from './constant'
import { PluginAST_STAT_ICON, STATS_FILE_NAME } from './constant'

export const STAT_PREVIEW_TYPE = "vault-statistics-preview";

Expand All @@ -13,11 +13,11 @@ export class Stat extends ItemView {
plugin: PluginManager;
staticsFileData: string;

constructor(app: App, plugin: PluginManager, leaf: WorkspaceLeaf, staticsFileData: string) {
constructor(app: App, plugin: PluginManager, leaf: WorkspaceLeaf) {
super(leaf);
this.app = app;
this.plugin = plugin;
this.staticsFileData = staticsFileData;
this.staticsFileData = "";
addIcon(PluginAST_STAT_ICON, icons[PluginAST_STAT_ICON]);
}

Expand All @@ -34,6 +34,8 @@ export class Stat extends ItemView {
}

async onOpen() {
const staticsDataDir = this.app.vault.configDir + "/" + STATS_FILE_NAME;
this.staticsFileData = await this.app.vault.adapter.read(staticsDataDir);
const el = this.containerEl.getElementsByClassName("view-content");
this.component = new Statistics({
target: el[0],
Expand Down

0 comments on commit 4fffd54

Please sign in to comment.