|
1 | 1 | import { joinPath, slugify } from '../../lib/strings.js'
|
2 | 2 | import { query } from './query.js'
|
3 | 3 | import * as filesystem from './index'
|
4 |
| -import { includesList as toolbarIncludesList, add as addToToolbar, remove as removeFromToolbar } from './toolbar' |
| 4 | +import { |
| 5 | + includesList as toolbarIncludesList, |
| 6 | + add as addToToolbar, |
| 7 | + remove as removeFromToolbar, |
| 8 | + getCurrentBookmark as getToolbarCurrentBookmark |
| 9 | +} from './toolbar' |
5 | 10 | import { URL } from 'url'
|
6 | 11 | import * as profileDb from '../dbs/profile-data-db'
|
7 | 12 |
|
@@ -62,12 +67,23 @@ export async function add ({href, title, pinned, toolbar}) {
|
62 | 67 | }
|
63 | 68 | slug = slug.toLowerCase()
|
64 | 69 |
|
65 |
| - await remove(href) // in case this is an edit |
| 70 | + let openInPane = undefined |
| 71 | + let existing = await get(href) |
| 72 | + if (existing) { |
| 73 | + if (existing.toolbar) { |
| 74 | + let existingToolbar = await getToolbarCurrentBookmark(href) |
| 75 | + openInPane = existingToolbar ? existingToolbar.openInPane : undefined |
| 76 | + } |
| 77 | + if (typeof title === 'undefined') title = existing.title |
| 78 | + if (typeof pinned === 'undefined') pinned = existing.pinned |
| 79 | + if (typeof toolbar === 'undefined') toolbar = existing.toolbar |
| 80 | + await remove(href) |
| 81 | + } |
66 | 82 |
|
67 | 83 | var filename = await filesystem.getAvailableName('/bookmarks', slug, 'goto') // avoid collisions
|
68 | 84 | var path = joinPath('/bookmarks', filename)
|
69 | 85 | await filesystem.get().pda.writeFile(path, '', {metadata: {href, title, pinned: pinned ? '1' : undefined}})
|
70 |
| - if (toolbar) await addToToolbar({bookmark: filename}) |
| 86 | + if (toolbar) await addToToolbar({bookmark: filename, openInPane}) |
71 | 87 | return path
|
72 | 88 | }
|
73 | 89 |
|
|
0 commit comments