Skip to content

Commit

Permalink
Fix: Auto-select note
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjuma committed May 6, 2024
1 parent 57f2771 commit caa8e08
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ class App extends Component {
async componentDidMount() {
const getnotes = await this.handleIndexedDB("getall");
const pinnedNotes = await this.handleIndexedDB("getallpins");


this.setState({
allnotes: getnotes,
pinnedNotes: pinnedNotes || [],
Expand All @@ -60,26 +58,9 @@ class App extends Component {
if (this.state.allnotes.length === 0) {
this.handleClickHomeBtn();
return;
}

// Sort the notes using the current or default sorting value
this.handleSortNotes(this.state.sortby);

// Determine which note to select
const sortedNotes = this.state.allnotes;
const selectedNoteId = this.state.pinnedNotes.length > 0
? this.state.pinnedNotes[0] // Top pinned note
: sortedNotes.length > 0 ? sortedNotes[0].noteid : null; // Top unpinned note or none

// Automatically select the determined note after ensuring it exists
if (selectedNoteId) {
setTimeout(() => {
const noteElement = document.getElementById(selectedNoteId);
if (noteElement) {
noteElement.click();
}
}, 0); // Delay to ensure rendering is complete
}
}
// Sort notes by the default sort order
this.handleSortNotes(this.state.sortby);
});

this.updateCodeSyntaxHighlighting();
Expand Down Expand Up @@ -124,7 +105,7 @@ handleUnpinNote = async (noteid) => {
return { pinnedNotes };
}, () => {
this.handleSortNotes(this.state.sortby);
document.getElementById(noteid)
document.getElementById(noteid).click();
});
};

Expand Down

0 comments on commit caa8e08

Please sign in to comment.