Skip to content

Commit

Permalink
Merge pull request #19 from nosdav/enter
Browse files Browse the repository at this point in the history
enter
  • Loading branch information
melvincarvalho authored May 13, 2024
2 parents 7e3b851 + a6e4a6b commit 8e055f1
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ export class App extends Component {
// await this.userLogin();
}

/**
* Handle key press in the bookmark input.
*
* @param {Event} event - The keypress event.
*/
handleKeyPress = (event) => {
if (event.key === 'Enter') {
this.addBookmark();
}
}


/**
* Update the URL of the new bookmark.
*
Expand Down Expand Up @@ -130,19 +142,14 @@ export class App extends Component {
this.setState({ bookmarks: updatedBookmarks }, this.saveBookmarks);
};

/**
* Render the application.
*
* @return {string} The HTML to render.
*/
render() {
const { userPublicKey, newBookmarkUrl, bookmarks } = this.state;

// Sort bookmarks in reverse chronological order (newest to oldest)
const sortedBookmarks = bookmarks.slice().reverse()

return html`
<${GithubRibbon} repo="https://github.com/nosdav/pastebin/" />
<${GithubRibbon} repo="https://github.com/nosdav/pastebin/" />
<div class="container">
<h1>Bookmark Manager</h1>
<input
Expand All @@ -151,40 +158,35 @@ export class App extends Component {
placeholder="Enter a new bookmark URL"
value="${newBookmarkUrl}"
onInput="${this.updateNewBookmarkUrl}"
onKeyPress="${this.handleKeyPress}" // Added handler for key press
/>
${userPublicKey
? html`
${userPublicKey ? html`
<button onClick="${this.addBookmark}" type="button">
Add Bookmark
</button>
<br />
<br />
`
: html` <button id="login" onClick="${this.userLogin}">
Login
</button>`}
<br /><br />
` : html`
<button id="login" onClick="${this.userLogin}">
Login
</button>`}
<ul id="bookmark-list">
${sortedBookmarks.map(
(bookmark) => html`
(bookmark) => html`
<li>
<a target="_blank" href=${bookmark.url}>${bookmark.url}</a>
<button
onClick="${() => this.deleteBookmark(bookmark)}"
style="margin-left: 20px;"
type="button"
>
Delete
</button>
</li>
`
)}
)}
</ul>
</div>
`;

}


Expand Down

0 comments on commit 8e055f1

Please sign in to comment.