Skip to content

Commit 5c31f10

Browse files
fix the buttons leaf problem
1 parent f0b3921 commit 5c31f10

File tree

3 files changed

+89
-18
lines changed

3 files changed

+89
-18
lines changed

src/createFamily/buttons.ts

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,91 @@
1-
import { App, TFile, setTooltip, setIcon, addIcon, WorkspaceLeaf, MarkdownView, Editor } from "obsidian";
1+
import { App, TFile, setTooltip, setIcon, addIcon, WorkspaceLeaf, MarkdownView, Editor, Platform } from "obsidian";
22
import familyModal from "./familyModal";
33
import { NewFileLocation } from '../util/enums';
44
import deleteActiveNoteModal from "./deleteActiveNoteModal";
55
import { createClustersAndOrphansFolder } from "./createClustersAndOrphansFolder";
6+
import { puzzleTemplate } from "./templates";
67

78
const clusters = "CLUSTERS"
89
const orphans = "ORPHANS"
910
let Vars = {}
1011
export async function buttonsLine(app: App, file: TFile, settings?: any) {
1112
this.app = app
1213
Vars = settings
13-
let LEAF: WorkspaceLeaf | null = null;
14-
this.app.workspace.iterateAllLeaves((leaf: WorkspaceLeaf) => {
15-
if (leaf.getViewState().type == "markdown") {
16-
LEAF = leaf
14+
//! Android
15+
console.log("buttonsLine ⸦ Platform:", Platform);
16+
if (Platform.isMobile) {
17+
let LEAF: WorkspaceLeaf | null = null;
18+
this.app.workspace.iterateAllLeaves((leaf: WorkspaceLeaf) => {
19+
if (leaf.getViewState().type == "markdown") {
20+
LEAF = leaf
21+
}
22+
})
23+
24+
if (LEAF !== null) {
25+
const obsidianContainer = (LEAF as WorkspaceLeaf).view.containerEl
26+
27+
const obsidianContainerElements = Array?.from(obsidianContainer?.children)
28+
//@ts-ignore
29+
const obsidianHeaderEl = (LEAF as WorkspaceLeaf).view.headerEl
30+
31+
32+
appendOrRemoveChild(file, obsidianContainer, obsidianContainerElements, obsidianHeaderEl)
33+
firstPageOfClusters(file, obsidianContainerElements)
34+
1735
}
18-
})
1936

20-
if (LEAF !== null) {
21-
const obsidianContainer = (LEAF as WorkspaceLeaf).view.containerEl
37+
}
38+
//! PC
39+
else {
40+
const e = this.app.workspace.activeLeaf.view.file.path
41+
if (e.startsWith(clusters) || e.startsWith(orphans)) {
42+
const LEAF = this.app.workspace.activeLeaf
43+
const obsidianContainer = (LEAF as WorkspaceLeaf).view.containerEl
44+
2245

23-
const obsidianContainerElements = Array?.from(obsidianContainer?.children)
24-
//@ts-ignore
25-
const obsidianHeaderEl = (LEAF as WorkspaceLeaf).view.headerEl
46+
const obsidianContainerElements = Array?.from(obsidianContainer?.children)
47+
48+
//@ts-ignore
49+
const obsidianHeaderEl = (LEAF as WorkspaceLeaf).view.headerEl
2650

2751

28-
appendOrRemoveChild(file, obsidianContainer, obsidianContainerElements, obsidianHeaderEl)
29-
firstPageOfClusters(file, obsidianContainerElements)
3052

53+
appendOrRemoveChild(file, obsidianContainer, obsidianContainerElements, obsidianHeaderEl)
54+
firstPageOfClusters(file, obsidianContainerElements)
55+
} else {
56+
const LEAF2 = this.app.workspace.activeLeaf
57+
const obsidianContainer2 = (LEAF2! as WorkspaceLeaf)?.view?.containerEl
58+
59+
const obsidianContainerElements2 = Array?.from(obsidianContainer2?.children)
60+
61+
//@ts-ignore
62+
const obsidianHeaderEl2 = (LEAF2! as WorkspaceLeaf)?.view?.headerEl
63+
64+
RemoveChild(file, obsidianContainer2, obsidianContainerElements2, obsidianHeaderEl2)
65+
firstPageOfClusters(file, obsidianContainerElements2)
66+
67+
}
3168
}
3269

70+
71+
72+
73+
74+
75+
}
76+
function RemoveChild(file: TFile, obsidianContainer: any, obsidianContainerElements: any, obsidianHeaderEl: any) {
77+
const isButtonsLineContainer: any = obsidianContainerElements.find((item: HTMLElement) => item.classList.contains("buttonsLineContainer"))
78+
79+
if (isButtonsLineContainer && !(file?.path?.startsWith(orphans) || file?.path?.startsWith(clusters))) {
80+
obsidianContainer.removeChild(isButtonsLineContainer)
81+
}
3382
}
3483
//- Append Or Remove Child FUNCTION
3584
function appendOrRemoveChild(file: TFile, obsidianContainer: any, obsidianContainerElements: any, obsidianHeaderEl: any) {
3685
// check if buttonsLineContainer exist in the DOM or not
3786
const isButtonsLineContainer: any = obsidianContainerElements.find((item: HTMLElement) => item.classList.contains("buttonsLineContainer"))
3887

39-
// remove buttonsLineContainer from DOM if the file not in clusters folder or in orphans folder
88+
// // remove buttonsLineContainer from DOM if the file not in clusters folder or in orphans folder
4089
if (isButtonsLineContainer && !(file?.path?.startsWith(orphans) || file?.path?.startsWith(clusters))) {
4190
obsidianContainer.removeChild(isButtonsLineContainer)
4291
}
@@ -129,7 +178,7 @@ function makeButton(type: string, className: string, tooltipMsg: string, element
129178
button.textContent = type;
130179
setTooltip(button, tooltipMsg, { delay: 10 })
131180
button.addClasses(["btn", className])
132-
button.addEventListener('click', () => {
181+
button.addEventListener('click', async () => {
133182
if (type == "Cluster") {
134183
createClustersAndOrphansFolder(this.app);
135184
new familyModal(this.app, NewFileLocation.NewTab, "newCluster", undefined).open();
@@ -168,7 +217,13 @@ function makeButton(type: string, className: string, tooltipMsg: string, element
168217
window.location.href = coffeeLink;
169218
}
170219
else if (type == "puzzleBtn") {
171-
console.log("puzzleBtn")
220+
const puzzleFileExists = await this.app.vault.adapter.exists("/ORPHANS/puzzle.md")
221+
console.log(puzzleFileExists)
222+
if (!puzzleFileExists) {
223+
224+
const puzzleFile = await this.app.vault.create("/ORPHANS/puzzle.md", puzzleTemplate)
225+
this.app.workspace.getLeaf(true).openFile(puzzleFile);
226+
}
172227
}
173228

174229

src/createFamily/commit_info.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
## Did
22

3-
- [*] fix v2.0.0 on mobile
3+
- [*] fix the buttons leaf problem
44

55
## ToDo
66

77
- [ ] make the extra buttons [ puzzle ] functionality implementation
8-
- [ ] fix readme + first cluster
8+
- [ ] test the buttons leaf problem in buttons.ts
9+
- [ ] enhance the code buttons leaf problem in buttons.ts

src/createFamily/templates.ts

Lines changed: 15 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)