generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DucksView): ✨ Add Duck view to show notes which don't have any b…
…readcrumbs
- Loading branch information
1 parent
0d1ec3e
commit 2d0b2b2
Showing
3 changed files
with
127 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script lang="ts"> | ||
import type { App } from "obsidian"; | ||
import { hoverPreview, openOrSwitch } from "obsidian-community-lib"; | ||
import type DucksView from "src/DucksView"; | ||
import type BCPlugin from "src/main"; | ||
export let plugin: BCPlugin; | ||
export let app: App; | ||
export let ducksView: DucksView; | ||
const { main } = plugin.currGraphs; | ||
const files = app.vault.getMarkdownFiles(); | ||
const fileNames = files.map((file) => file.basename); | ||
const ducks = fileNames.filter((name) => !main.neighbors(name).length); | ||
</script> | ||
|
||
<div class="BC-Ducks markdown-preview-view"> | ||
<h6>Notes without Breadcrumbs</h6> | ||
{#each ducks as duck} | ||
<div | ||
on:click={async (e) => await openOrSwitch(app, duck, e)} | ||
on:mouseover={(e) => hoverPreview(e, ducksView, duck)} | ||
> | ||
<a class="internal-link">{duck}</a> | ||
</div> | ||
{/each} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ItemView, WorkspaceLeaf } from "obsidian"; | ||
import { STATS_VIEW } from "src/constants"; | ||
import type BCPlugin from "src/main"; | ||
import Ducks from "./Components/Ducks.svelte"; | ||
|
||
export default class DucksView extends ItemView { | ||
private plugin: BCPlugin; | ||
private view: Ducks; | ||
|
||
constructor(leaf: WorkspaceLeaf, plugin: BCPlugin) { | ||
super(leaf); | ||
this.plugin = plugin; | ||
} | ||
|
||
async onload(): Promise<void> { | ||
super.onload(); | ||
await this.plugin.saveSettings(); | ||
this.app.workspace.onLayoutReady(async () => { | ||
await this.draw(); | ||
}); | ||
} | ||
|
||
getViewType() { | ||
return STATS_VIEW; | ||
} | ||
getDisplayText() { | ||
return "Breadcrumbs Ducks"; | ||
} | ||
|
||
// TODO Duck icon | ||
icon = "info"; | ||
|
||
async onOpen(): Promise<void> {} | ||
|
||
onClose(): Promise<void> { | ||
if (this.view) { | ||
this.view.$destroy(); | ||
} | ||
return Promise.resolve(); | ||
} | ||
|
||
async draw(): Promise<void> { | ||
this.contentEl.empty(); | ||
|
||
this.view = new Ducks({ | ||
target: this.contentEl, | ||
props: { plugin: this.plugin, app: this.app, ducksView: this }, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters