Skip to content

Commit

Permalink
Use new bookmarklet features
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Feb 28, 2023
1 parent 4619597 commit e120cbf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://github.com/hifiwi-fi/breadcrum.net/issues"
},
"dependencies": {
"@breadcrum/bookmarklet": "^1.0.2",
"@breadcrum/bookmarklet": "^1.0.3",
"@fastify/accepts": "^4.0.0",
"@fastify/auth": "^4.0.0",
"@fastify/autoload": "^5.3.1",
Expand Down
14 changes: 11 additions & 3 deletions web/bookmarks/add/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Component, html, render, useEffect, useState } from 'uland-isomorphic'
import { useUser } from '../../hooks/useUser.js'
import { fetch } from 'fetch-undici'
import { version } from '@breadcrum/bookmarklet/version.js'
import { useLSP } from '../../hooks/useLSP.js'
import { useQuery } from '../../hooks/useQuery.js'
import { bookmarkEdit } from '../../components/bookmark/bookmark-edit.js'
Expand All @@ -14,6 +15,8 @@ export const page = Component(() => {
const { query } = useQuery()
const [bookmark, setBookmark] = useState(null)
const [newlyCreated, setNewlyCreated] = useState(false)
const [bookmarkletUpdateAvailable, setBookmarkletUpdateAvailable] = useState(false)
const [bookmarkletVersion, setBookmarkletVersion] = useState()

useEffect(() => {
if (!user && !loading) {
Expand All @@ -27,14 +30,17 @@ export const page = Component(() => {
setBookmark({
url: query.get('url'),
title: query.get('title'),
note: query.get('description'),
tags: query.getAll('tags')
note: query.get('note') || query.get('description'),
tags: query.getAll('tags').filter(t => Boolean(t))
})
}

const init = async () => {
setNewlyCreated(false)
const queryUrl = query.get('url')
const ver = query.get('ver')
setBookmarkletVersion(ver)
if (ver !== version) setBookmarkletUpdateAvailable(true)

if (!queryUrl) {
setFallbackBookmark()
Expand All @@ -44,7 +50,7 @@ export const page = Component(() => {
const payload = {
url: queryUrl,
title: query.get('title'),
note: query.get('description'),
note: query.get('note') || query.get('description'),
tags: query.getAll('tags').filter(t => Boolean(t))
}

Expand Down Expand Up @@ -120,6 +126,8 @@ export const page = Component(() => {
return html`
${bookmarkEdit({
bookmark,
bookmarkletUpdateAvailable,
bookmarkletVersion,
onSave: handleSaveBookmark,
legend: existingBookmark
? newlyCreated
Expand Down
14 changes: 14 additions & 0 deletions web/components/bookmark/bookmark-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { useLSP } from '../../hooks/useLSP.js'

export const bookmarkEdit = Component(({
bookmark: b,
bookmarkletUpdateAvailable,
bookmarkletVersion,
onSave,
onDeleteBookmark,
onCancelEdit,
Expand Down Expand Up @@ -420,6 +422,18 @@ export const bookmarkEdit = Component(({
</div>
</div>
${
bookmarkletVersion
? html`
<div class="bc-help-text">
Version ${bookmarkletVersion}
${bookmarkletUpdateAvailable
? html`<a onclick=${handleNewWindowLink} target="_blank" href="/docs/bookmarklets/">An updated bookmarklet is available</a>`
: null}
</div>
`
: null
}
<!-- Bookmark Error Box -->
${error ? html`<div class="error-box">${error.message}</div>` : null}
</fieldset>
Expand Down
2 changes: 0 additions & 2 deletions web/docs/bookmarklets/bookmarklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ export const bookmarklet = getBookmarklet({
HOST: process.env.HOST,
WINDOW_TITLE: '🥖 Breadcrum'
})

console.log({ bookmarklet })
3 changes: 2 additions & 1 deletion web/docs/bookmarklets/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env browser */
import { Component, html, render } from 'uland-isomorphic'
import { bookmarklet } from '../bookmarklets/bookmarklet.js'
import { version } from '@breadcrum/bookmarklet/version.js'

export const page = Component(() => {
return html`
Expand All @@ -11,7 +12,7 @@ export const page = Component(() => {
When you visit a page you want to bookmark, click the the bookmarklet in your bookmark bar or menu and it will open a new bookmark window. Existing URLs will open an edit window.
</p>
<p><a class="bc-bookmarklet" href="${bookmarklet}">🥖 bookmark</a></p>
<p><a class="bc-bookmarklet" href="${bookmarklet}">🥖 bookmark</a> <span class="bc-help-text">Version ${version}</span></p>
<h2>Apple Shortcut</h2>
Expand Down

0 comments on commit e120cbf

Please sign in to comment.