Skip to content

Commit

Permalink
feat: init statistic view command
Browse files Browse the repository at this point in the history
Signed-off-by: edonyzpc <[email protected]>
  • Loading branch information
edonyzpc committed Mar 15, 2024
1 parent 5716020 commit b309459
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ThemeUpdater } from './themeManifest';
import { monkeyPatchConsole } from './obsidian-hack/obsidian-mobile-debug';
import { CalloutModal } from './callout';
import { RecordPreview, RECORD_PREVIEW_TYPE } from './preview';
import { STAT_PREVIEW_TYPE } from './stat'

const debug = (debug: boolean, ...msg: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
if (debug) console.log(...msg);
Expand Down Expand Up @@ -195,6 +196,14 @@ export class PluginManager extends Plugin {
}
})

this.addCommand({
id: "show-statistics",
name: "Show statistics",
callback: async () => {
await this.activeStatView();
}
})

// This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new SettingTab(this.app, this));
}
Expand Down Expand Up @@ -339,6 +348,20 @@ export class PluginManager extends Plugin {
this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(RECORD_PREVIEW_TYPE)[0]
);
}
}

async activeStatView() {
this.app.workspace.detachLeavesOfType(STAT_PREVIEW_TYPE);

const viewLeaf = this.app.workspace.getLeaf('tab');
await viewLeaf.setViewState({
type: STAT_PREVIEW_TYPE,
active: true,
});

this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(STAT_PREVIEW_TYPE)[0]
);
}
}

33 changes: 33 additions & 0 deletions src/stat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { App, ItemView, WorkspaceLeaf } from "obsidian";

import { PluginManager } from "./plugin";
import RecordList from './components/RecordList.svelte'

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

export class Stat extends ItemView {
component!: RecordList;
app: App;
plugin: PluginManager;

constructor(app: App, plugin: PluginManager, leaf: WorkspaceLeaf) {
super(leaf);
this.app = app;
this.plugin = plugin;
}

getViewType() {
return STAT_PREVIEW_TYPE;
}

getDisplayText() {
return "Vault Statistics Preview";
}

async onOpen() {
}

async onClose() {
this.component.$destroy();
}
}

0 comments on commit b309459

Please sign in to comment.