Skip to content

Commit

Permalink
Update to display last active file on open of view
Browse files Browse the repository at this point in the history
  • Loading branch information
Mossy426 committed Jun 16, 2024
1 parent 6323121 commit 22122cc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
28 changes: 21 additions & 7 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,19 @@ class ScGraphItemView extends ItemView {
this.contentEl.createEl('p', { text: 'Waiting for Smart Connections to load...' });
console.log(this.app);

this.render();
// Introduce a small delay before rendering to give view time to load
setTimeout(() => {
this.render();
}, 500); // Adjust the delay as needed

}

async render() {
// wait until this.smartNotes is available
while (!this.env?.entities_loaded) {
await new Promise(resolve => setTimeout(resolve, 2000));
}

this.contentEl.empty();
this.initializeVariables();
if (Object.keys(this.smartNotes).length === 0) {
Expand All @@ -332,6 +337,16 @@ class ScGraphItemView extends ItemView {
this.addEventListeners();
this.setupSettingsMenu();
this.watchForNoteChanges();

// Load latest active file if opening view for first time
const currentNodeChange = this.app.workspace.getActiveFile();
if (currentNodeChange && !this.currentNoteChanging) {
this.currentNoteKey = currentNodeChange.path;
this.currentNoteChanging = true;
this.render();
return
}


this.updateVisualization();
}
Expand Down Expand Up @@ -1228,12 +1243,11 @@ class ScGraphItemView extends ItemView {
// Check and initialize node positions
nodesData.forEach((node: any) => {

if (!node.x || !node.y) {
console.log('hello');
console.warn(`Node with invalid position: ${node.id}`);
node.x = Math.random() * 1000; // or some default value
node.y = Math.random() * 1000; // or some default value
}
// if (!node.x || !node.y) {
// console.warn(`Node with invalid position: ${node.id}`);
// node.x = Math.random() * 1000; // or some default value
// node.y = Math.random() * 1000; // or some default value
// }
});


Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "smart-connections-visualizer",
"name": "Smart Connections Visualizer",
"version": "1.0.7",
"version": "1.0.8",
"minAppVersion": "0.15.0",
"description": "View your Smart Connections in a visualized format.",
"author": "Evan Moscoso",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smart-connections-visualizer",
"version": "1.0.7",
"version": "1.0.8",
"description": "A plugin that allows you to view your Smart Connections in a visualized format.",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 22122cc

Please sign in to comment.