Skip to content

Commit bc5499f

Browse files
refactor: Cleaninig
1 parent d94b658 commit bc5499f

File tree

14 files changed

+138
-130
lines changed

14 files changed

+138
-130
lines changed

src/createFamily/bigIF.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/createFamily/buttons.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { App, TFile, setTooltip, setIcon, addIcon, MarkdownView, Editor, Platform } from "obsidian";
22
import familyModal from "./familyModal";
3-
import { NewFileLocation } from '../util/enums';
3+
import U from '../util/U';
44
import deleteActiveNoteModal from "./deleteActiveNoteModal";
55
import { createClustersAndOrphansFolder } from "./createClustersAndOrphansFolder";
66
import { puzzleTemplate } from "./templates";
7-
import type { clusterPluginSettings } from "main";
8-
import { stringify } from "querystring";
7+
import type { clusterPluginSettings } from "../settings/settings";
98

109
const clusters = "CLUSTERS"
1110
const orphans = "ORPHANS"
@@ -39,9 +38,10 @@ export async function buttonsLine(appObject: App, file: TFile, settings?: cluste
3938
const activeLeavePath = activeLeave?.file?.path as string
4039
if (activeLeavePath.startsWith(clusters) || activeLeavePath.startsWith(orphans)) {
4140
const obsidianContainer = activeLeave?.containerEl
41+
//@ts-ignore
4242
const obsidianContainerElements = Array?.from(obsidianContainer?.children)
4343
//@ts-ignore
44-
const obsidianHeaderEl = activeLeave!.headerEl
44+
const obsidianHeaderEl = activeLeave?.headerEl
4545

4646
if (removeButtons) {//remove buttons when on unload
4747
RemoveButtonsLine(file, obsidianContainer, obsidianContainerElements, obsidianHeaderEl)
@@ -52,10 +52,11 @@ export async function buttonsLine(appObject: App, file: TFile, settings?: cluste
5252

5353
}
5454
} else {
55-
const obsidianContainer2 = activeLeave!.containerEl
55+
const obsidianContainer2 = activeLeave?.containerEl
56+
//@ts-ignore
5657
const obsidianContainerElements2 = Array?.from(obsidianContainer2?.children)
5758
//@ts-ignore
58-
const obsidianHeaderEl2 = activeLeave!.headerEl
59+
const obsidianHeaderEl2 = activeLeave?.headerEl
5960
// remove buttonsLineContainer from DOM if the file not in clusters folder or in orphans folder
6061
RemoveChild(file, obsidianContainer2, obsidianContainerElements2, obsidianHeaderEl2)
6162
firstPageOfClusters(file, obsidianContainerElements2)
@@ -185,23 +186,23 @@ function makeButton(appObject: App, type: string, className: string, tooltipMsg:
185186
button.addEventListener('click', async () => {
186187
if (type == "Cluster") {
187188
createClustersAndOrphansFolder(appObject);
188-
new familyModal(appObject, NewFileLocation.NewTab, "newCluster", undefined).open();
189+
new familyModal(appObject, U.NewFileLocation.NewTab, "newCluster", undefined).open();
189190
}
190191
else if (type == "Son") {
191192
createClustersAndOrphansFolder(appObject);
192-
new familyModal(appObject, NewFileLocation.NewTab, "newSon", undefined).open()
193+
new familyModal(appObject, U.NewFileLocation.NewTab, "newSon", undefined).open()
193194
}
194195
else if (type == "Brother") {
195196
createClustersAndOrphansFolder(appObject);
196-
new familyModal(appObject, NewFileLocation.NewTab, "newBrother", undefined).open();
197+
new familyModal(appObject, U.NewFileLocation.NewTab, "newBrother", undefined).open();
197198
}
198199
else if (type == "Orphan") {
199200
createClustersAndOrphansFolder(appObject);
200-
new familyModal(appObject, NewFileLocation.NewTab, "newOrphan", undefined).open();
201+
new familyModal(appObject, U.NewFileLocation.NewTab, "newOrphan", undefined).open();
201202
}
202203
else if (type == "Delete") {
203204
createClustersAndOrphansFolder(appObject);
204-
new deleteActiveNoteModal(appObject, NewFileLocation.NewTab, "deleteNote").open();
205+
new deleteActiveNoteModal(appObject, U.NewFileLocation.NewTab, "deleteNote").open();
205206
}
206207
// Extra Buttons
207208
else if (type == "extraBtn") {
@@ -280,21 +281,21 @@ function firstPageOfClusters(file: TFile, obsidianContainerElements: any) {
280281

281282
}
282283

283-
export async function cardStyleFunction(settings: clusterPluginSettings){
284+
export async function cardStyleFunction(settings: clusterPluginSettings) {
284285
setTimeout(() => {
285-
286-
const appContainer = document.body
286+
287+
const appContainer = document.body
287288
const classList = Array.from(appContainer.classList)
288-
const isDark = classList.find((className : string) => className ==="theme-dark" )
289-
289+
const isDark = classList.find((className: string) => className === "theme-dark")
290+
290291
console.log("classList:", classList);
291-
if(settings.cardStyle){
292-
if(isDark){
292+
if (settings.cardStyle) {
293+
if (isDark) {
293294

294295
appContainer.classList.add("card-layout-open-dark")
295296
}
296297
appContainer.classList.add("card-layout-open-light")
297-
}else{
298+
} else {
298299
appContainer.classList.remove("card-layout-open-dark")
299300
appContainer.classList.remove("card-layout-open-light")
300301
}

src/createFamily/coloringTreePanel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export async function foldPropertiesElement(appObject: App, file: TFile) {
88
if (file.path.startsWith(clusters) || file.path.startsWith(orphans)) {
99
//FIX try to use toggle class instead of add/remove
1010
//@ts-ignore
11-
const propertiesElement: HTMLElement = appObject.workspace.activeEditor!.containerEl.querySelector('.metadata-container');
11+
const propertiesElement: HTMLElement = appObject.workspace.activeEditor?.containerEl.querySelector('.metadata-container');
1212
const metaDataContentElement = propertiesElement.querySelector('.collapse-indicator') as HTMLElement;
1313
const collapseIndicatorElement = propertiesElement.querySelector('.metadata-properties-heading') as HTMLElement;
1414
if (propertiesElement) {

src/createFamily/deleteActiveNoteModal.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { App, Notice, Modal, TFolder, TFile, setIcon } from "obsidian";
2-
import { NewFileLocation } from "../util/enums";
1+
import { App, Modal, TAbstractFile, TFolder, setIcon } from "obsidian";
32
import svgElements from "./svg";
3+
import { NewFileLocation } from '../util/U';
44

55

66

@@ -86,13 +86,13 @@ export default class deleteActiveNoteModal extends Modal {
8686

8787

8888
//parent folder info
89-
const theContainingFolder = getActiveFile!.parent!
90-
const theContainingFolderItemsNumber = getActiveFile!.parent!.children.length
91-
const theContainingFolderPath = getActiveFile!.parent!.path
89+
const theContainingFolder = getActiveFile?.parent
90+
const theContainingFolderItemsNumber = getActiveFile?.parent?.children.length
91+
9292
//Related Sons Folder
93-
const theRelatedSonsFolder = getActiveFile!.parent!.children.find((item: any) => {
93+
const theRelatedSonsFolder = getActiveFile?.parent?.children.find((item: any) => {
9494
// normal note
95-
if (item instanceof TFolder && item.name == getActiveFile!.basename) {
95+
if (item instanceof TFolder && item.name == getActiveFile?.basename) {
9696
return item
9797
}
9898
// cluster
@@ -107,7 +107,7 @@ export default class deleteActiveNoteModal extends Modal {
107107
await this.app.vault.trash(getActiveFile!, true)
108108
await this.app.vault.trash(theRelatedSonsFolder, true)
109109
if (theContainingFolderItemsNumber == 2) {
110-
await this.app.vault.trash(theContainingFolder, true)
110+
await this.app.vault.trash(theContainingFolder as TAbstractFile, true)
111111
}
112112
} else {
113113
//delete current active file
@@ -117,7 +117,7 @@ export default class deleteActiveNoteModal extends Modal {
117117

118118
//delete parent folder of active file if it is empty
119119
if (theContainingFolderItemsNumber == 1) {
120-
await this.app.vault.trash(theContainingFolder, true)
120+
await this.app.vault.trash(theContainingFolder as TAbstractFile, true)
121121
}
122122
}
123123

src/createFamily/familyModal.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { App, normalizePath, Platform, TFolder, Notice, Modal, Instruction, Vault, MarkdownView, setIcon } from "obsidian";
2-
import { NewFileLocation } from '../util/enums';
1+
import { App, normalizePath, Platform, TFolder, Notice, Modal, setIcon } from "obsidian";
32
import { path } from '../util/utils';
43
import svgElements from "./svg";
54
import { templates, clusterTemplate, orphanTemplate } from "./templates";
5+
import { NewFileLocation } from '../util/U';
6+
7+
68

79
const clusters = "CLUSTERS"
810
const orphans = "ORPHANS"
@@ -326,12 +328,11 @@ export default class familyModal extends Modal {
326328
*/
327329
async createNewNote(appObject: App, input: string, template: string): Promise<void> {
328330
const { vault } = appObject;
329-
const { adapter } = vault;
330331
const prependDirInput = path.join(this.newDirectoryPath, input);
331332
const { dir, name } = path.parse(prependDirInput);
332333
const directoryPath = path.join(this.folder.path, dir);
333334

334-
let filePath = path.join(directoryPath, `${name}.md`);
335+
const filePath = path.join(directoryPath, `${name}.md`);
335336

336337
try {
337338
const fileExists = appObject.vault.getAbstractFileByPath(filePath);

src/createFamily/svg.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { addIcon, setIcon } from "obsidian";
22

3-
//@ts-ignore
4-
export default function svgElements(){
5-
6-
return{
7-
cluster:function(){
3+
4+
export default function svgElements() {
5+
6+
return {
7+
cluster: function () {
88
// 1 - Container Element
99
const con = document.createElement('div');
10-
con.classList.add("inputMsgCon","cluster");
10+
con.classList.add("inputMsgCon", "cluster");
1111

1212
// 2 - SVG Element
1313
addIcon("cluster-svg", `<g clip-path="url(#clip0_2_2)">
@@ -18,8 +18,8 @@ export default function svgElements(){
1818
<rect width="100" height="100" fill="white"/>
1919
</clipPath>
2020
</defs>`);
21-
22-
setIcon(con ,"cluster-svg")
21+
22+
setIcon(con, "cluster-svg")
2323
// 3 - Text Element
2424
const text = document.createElement('div');
2525
text.innerText = "Create Cluster";
@@ -30,10 +30,10 @@ export default function svgElements(){
3030

3131
return con;
3232
},
33-
son:function(){
33+
son: function () {
3434
// 1 - Container Element
3535
const con = document.createElement('div');
36-
con.classList.add("inputMsgCon","son");
36+
con.classList.add("inputMsgCon", "son");
3737

3838
// 2 - SVG Element
3939
setIcon(con, 'baby');
@@ -48,13 +48,13 @@ export default function svgElements(){
4848

4949
return con;
5050
},
51-
brother:function(){
52-
// 1 - Container Element
51+
brother: function () {
52+
// 1 - Container Element
5353
const con = document.createElement('div');
54-
con.classList.add("inputMsgCon","brother");
54+
con.classList.add("inputMsgCon", "brother");
5555

5656
// 2 - SVG Element
57-
setIcon(con , "git-compare")
57+
setIcon(con, "git-compare")
5858

5959
// 3 - Text Element
6060
const text = document.createElement('div');
@@ -66,10 +66,10 @@ export default function svgElements(){
6666

6767
return con;
6868
},
69-
orphan:function(){
69+
orphan: function () {
7070
// 1 - Container Element
7171
const con = document.createElement('div');
72-
con.classList.add("inputMsgCon","orphan");
72+
con.classList.add("inputMsgCon", "orphan");
7373

7474
// 2 - SVG Element
7575
setIcon(con, 'disc');
@@ -84,13 +84,13 @@ export default function svgElements(){
8484

8585
return con;
8686
},
87-
delete:function(){
87+
delete: function () {
8888
// 1 - Container Element
8989
const con = document.createElement('div');
90-
con.classList.add("inputMsgCon","delete");
90+
con.classList.add("inputMsgCon", "delete");
9191

9292
// 2 - SVG Element
93-
setIcon(con ,"trash-2")
93+
setIcon(con, "trash-2")
9494

9595
// 3 - Text Element
9696
const text = document.createElement('div');
@@ -105,13 +105,13 @@ export default function svgElements(){
105105
noThing: function () {
106106
// 1 - Container Element
107107
const con = document.createElement('div');
108-
con.classList.add("inputMsgCon","noThing");
109-
108+
con.classList.add("inputMsgCon", "noThing");
109+
110110
// 2 - SVG Element
111-
setIcon(con ,"x-circle")
112-
111+
setIcon(con, "x-circle")
112+
113113
return con;
114-
},
114+
},
115115

116116
}
117117
}

0 commit comments

Comments
 (0)