Skip to content

Commit d94b658

Browse files
refactor: improve code formatting and organization across multiple files
1 parent a802506 commit d94b658

File tree

6 files changed

+57
-54
lines changed

6 files changed

+57
-54
lines changed

main.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1-
import { Plugin, TFile} from "obsidian";
1+
import { Plugin, TFile } from "obsidian";
22
import P from "src/util/P";
3-
import { settingTab ,DEFAULT_SETTINGS ,clusterPluginSettings } from "./src/settings/settings";
3+
import { settingTab, DEFAULT_SETTINGS, clusterPluginSettings } from "./src/settings/settings";
44

55

66
export default class clusterPlugin extends Plugin {
77
settings: clusterPluginSettings;
88

99
async onload() {
1010
console.log("loading Cluster plugin");
11+
const file = this.app.workspace.getActiveFile() as TFile;
1112

1213
await this.loadSettings();
1314
this.addSettingTab(new settingTab(this.app, this));
1415

15-
// UN-SORTED Folder Styling
16-
setTimeout(async () => {
17-
await P.addUnsortedFilesCounter(this.app);
18-
await P.unSortedObserver(this.app);
19-
}, 1000);
2016

21-
22-
const file = this.app.workspace.getActiveFile() as TFile;
23-
if (file) {
24-
await P.buttonsLine(this.app, file, this.settings);
25-
}
17+
file ? await P.buttonsLine(this.app, file, this.settings) : null;
2618
P.addEvents(this)
27-
P.addRibbonIcon( this);
28-
P.fileMenu(this,P.SimpleFocus);
19+
P.addRibbonIcon(this);
20+
P.fileMenu(this, P.SimpleFocus);
2921
P.addCommands(this);
30-
31-
await P.cardStyleFunction( this.settings);//card style for lorens theme
22+
P.unsorted.unsortedFiles(this.app);
23+
await P.cardStyleFunction(this.settings);//card style for lorens theme
3224
}
3325

3426
async loadSettings() {
@@ -44,7 +36,7 @@ export default class clusterPlugin extends Plugin {
4436
// Remove Buttons line
4537
const file = this.app.workspace.getActiveFile() as TFile;
4638
await P.buttonsLine(this.app, file, this.settings, true);
47-
P.unSortedObserver(this.app, false);
39+
P.unsorted.unSortedObserver(this.app, false);
4840
console.log("unloading Cluster plugin");
4941
}
5042
}

src/focus/simpleFocus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const hideenClass = "plugin-simple-focus-hidden";
44

5-
class SimpleFocusClass {
5+
class SimpleFocusClass {
66
isFocus: boolean;
77
constructor() {
88
this.isFocus = false;

src/mainParts/addCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function addCommands(plugin: Plugin) {
8484
name: "Enter focus",
8585
callback: () => {
8686
const file = plugin.app.workspace.getActiveFile();
87-
if(file?.path) {
87+
if (file?.path) {
8888
SimpleFocus.enterFocus(file.path)
8989
}
9090
},

src/mainParts/fileMenu.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { TFile, TFolder, Menu } from "obsidian";
1+
import { TFile, TFolder, Menu, Plugin } from "obsidian";
22
import familyModal from "../createFamily/familyModal";
33
import { createClustersAndOrphansFolder } from "../createFamily/createClustersAndOrphansFolder";
44
import { NewFileLocation } from "src/util/enums";
5+
import SimpleFocusClass from "src/focus/simpleFocus";
56

67

78
const clusters = "CLUSTERS"
89
const orphans = "ORPHANS"
9-
//@ts-ignore
10-
export function fileMenu(x ,SimpleFocus) {
11-
//- file-menu
12-
x.registerEvent(
13-
x.app.workspace.on("file-menu", (menu: Menu, file: TFile) => {
10+
11+
export function fileMenu(plugin: Plugin, SimpleFocus: SimpleFocusClass) {
12+
plugin.registerEvent(
13+
plugin.app.workspace.on("file-menu", (menu: Menu, file: TFile) => {
1414
//- Focus menu
1515
if (file) {
1616
menu.addItem((item) => {
@@ -34,9 +34,9 @@ export function fileMenu(x ,SimpleFocus) {
3434
.setTitle("New cluster")
3535
.setIcon("folder-git-2")
3636
.onClick(async () => {
37-
createClustersAndOrphansFolder(x.app);
37+
createClustersAndOrphansFolder(plugin.app);
3838
const graphActiveFile = file
39-
new familyModal(x.app, NewFileLocation.NewTab, "newCluster", graphActiveFile).open();
39+
new familyModal(plugin.app, NewFileLocation.NewTab, "newCluster", graphActiveFile).open();
4040
});
4141
});
4242
}
@@ -48,9 +48,9 @@ export function fileMenu(x ,SimpleFocus) {
4848
.setTitle("New son")
4949
.setIcon("baby")
5050
.onClick(async () => {
51-
createClustersAndOrphansFolder(x.app);
51+
createClustersAndOrphansFolder(plugin.app);
5252
const graphActiveFile = file
53-
new familyModal(x.app, NewFileLocation.NewTab, "newSon", graphActiveFile).open();
53+
new familyModal(plugin.app, NewFileLocation.NewTab, "newSon", graphActiveFile).open();
5454
});
5555
});
5656
}
@@ -65,9 +65,9 @@ export function fileMenu(x ,SimpleFocus) {
6565
.setTitle("New brother")
6666
.setIcon("git-compare")
6767
.onClick(async () => {
68-
createClustersAndOrphansFolder(x.app);
68+
createClustersAndOrphansFolder(plugin.app);
6969
const graphActiveFile = file
70-
new familyModal(x.app, NewFileLocation.NewTab, "newBrother", graphActiveFile).open();
70+
new familyModal(plugin.app, NewFileLocation.NewTab, "newBrother", graphActiveFile).open();
7171
});
7272
});
7373
}
@@ -83,9 +83,9 @@ export function fileMenu(x ,SimpleFocus) {
8383
.setTitle("New orphan")
8484
.setIcon("disc")
8585
.onClick(async () => {
86-
createClustersAndOrphansFolder(x.app);
86+
createClustersAndOrphansFolder(plugin.app);
8787
const graphActiveFile = file
88-
new familyModal(x.app, NewFileLocation.NewTab, "newOrphan", graphActiveFile).open();
88+
new familyModal(plugin.app, NewFileLocation.NewTab, "newOrphan", graphActiveFile).open();
8989
});
9090
});
9191
}

src/settings/settings.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,22 @@ export class settingTab extends PluginSettingTab {
9292
toggle.setValue(this.plugin.settings.cardStyle);
9393
toggle.onChange(async (value) => {
9494
this.plugin.settings.cardStyle = value;
95-
const appContainer = document.body
96-
const classList = Array.from(appContainer.classList)
97-
const isDark = classList.find((className : string) => className ==="theme-dark" )
98-
if(value){
99-
await this.plugin.saveSettings();
100-
if(isDark){
95+
const appContainer = document.body
96+
const classList = Array.from(appContainer.classList)
97+
const isDark = classList.find((className: string) => className === "theme-dark")
98+
if (value) {
99+
await this.plugin.saveSettings();
100+
if (isDark) {
101101

102-
appContainer.classList.add("card-layout-open-dark")
103-
}
104-
appContainer.classList.add("card-layout-open-light")
105-
}else{
106-
appContainer.classList.remove("card-layout-open-dark")
107-
appContainer.classList.remove("card-layout-open-light")
108-
await this.plugin.saveSettings();
102+
appContainer.classList.add("card-layout-open-dark")
103+
}
104+
appContainer.classList.add("card-layout-open-light")
105+
} else {
106+
appContainer.classList.remove("card-layout-open-dark")
107+
appContainer.classList.remove("card-layout-open-light")
108+
await this.plugin.saveSettings();
109109

110-
}
110+
}
111111
});
112112
});
113113
}
@@ -128,8 +128,8 @@ export class settingTab extends PluginSettingTab {
128128
button.setIcon("github");
129129
button.onClick(
130130
() =>
131-
(window.location.href =
132-
"https://github.com/lorens-osman-dev/cluster"),
131+
(window.location.href =
132+
"https://github.com/lorens-osman-dev/cluster"),
133133
);
134134
});
135135

src/util/P.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { App } from "obsidian";
12
import { fileMenu } from "src/mainParts/fileMenu";
23
import { addCommands } from "src/mainParts/addCommands";
34
import { addEvents } from "src/mainParts/events";
@@ -13,6 +14,14 @@ import {
1314
unSortedObserver,
1415
foldPropertiesElement,
1516
} from "../createFamily/coloringTreePanel";
17+
18+
// unsorted
19+
function unsortedFiles(appInstance: App) {
20+
setTimeout(async () => {
21+
await addUnsortedFilesCounter(appInstance);
22+
await unSortedObserver(appInstance);
23+
}, 1000);
24+
}
1625
const P = {
1726
fileMenu,
1827
addEvents,
@@ -22,10 +31,12 @@ const P = {
2231
buttonsLine,
2332
cardStyleFunction,
2433
coloringTreePanel,
25-
addUnsortedFilesCounter,
26-
unSortedObserver,
34+
unsorted: {
35+
unsortedFiles,
36+
addUnsortedFilesCounter,
37+
unSortedObserver,
38+
},
2739
foldPropertiesElement,
40+
};
2841

29-
}
30-
31-
export default P
42+
export default P;

0 commit comments

Comments
 (0)