Skip to content

Commit

Permalink
Redirect to permalink after add
Browse files Browse the repository at this point in the history
Some interfaces can't close windows (iOS shortcuts), so this provides a better UX in those situations.
  • Loading branch information
bcomnes committed Mar 7, 2023
1 parent a5a493a commit e4645a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions web/bookmarks/add/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,23 @@ export const page = Component(() => {
})

if (response.ok) {
finish()
finish(await response.json())
} else {
throw new Error(`${response.status} ${response.statusText} ${await response.text()}`)
}

function finish () {
function finish (responseBody) {
const { id } = responseBody?.data ?? {}
const redirectTarget = id ? `/bookmarks/view/?id=${id}` : '/bookmarks'
if (query.get('jump') === 'close') {
try {
window.close()
} catch (err) {
console.error(err)
// TODO: go to permalink?
window.location.replace('/bookmarks')
window.location.replace(redirectTarget)
}
} else {
// TODO: go to permalink?
window.location.replace('/bookmarks')
window.location.replace(redirectTarget)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion web/components/bookmark/bookmark-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const bookmarkEdit = Component(({
try {
url = (new URL(form.url.value)).toString()
} catch (err) {
console.error(new Error(`Error sanitizing URL: ${url}`, { cause: err }))
console.warn(new Error(`Error sanitizing URL: ${url}`, { cause: err }))
}
const title = form.title.value
const note = form.note.value
Expand Down

0 comments on commit e4645a7

Please sign in to comment.