git ssb

0+

Josiah / patchbay-tags



Commit ec8a974282c6aa88e8450029617f906f6f638993

Confirm notes/tags when saving from feed

Josiah Witt committed on 12/10/2017, 2:30:06 PM
Parent: 3fa5fc29ea7ab4747f55ee28ba9428b03abe9c89

Files changed

bookmark/html/confirm.jsadded
bookmark/html/confirm.mcssadded
message/html/action/bookmark.jschanged
bookmark/html/confirm.jsView
@@ -1,0 +1,77 @@
1 +const nest = require('depnest')
2 +const lightbox = require('hyperlightbox')
3 +const { h, Value, computed } = require('mutant')
4 +
5 +exports.gives = nest('bookmark.html.confirm')
6 +
7 +exports.needs = nest({
8 + 'bookmark.async.save': 'first',
9 + 'bookmark.html': {
10 + notes: 'first',
11 + tags: 'first'
12 + },
13 + message: {
14 + 'async.publish': 'first',
15 + 'html.render': 'first'
16 + },
17 + 'keys.sync.id': 'first'
18 +})
19 +
20 +exports.create = function (api) {
21 + return nest({
22 + 'bookmark.html': { confirm }
23 + })
24 +
25 + function confirm (content, cb) {
26 + cb = cb || function () {}
27 +
28 + var lb = lightbox()
29 + document.body.appendChild(lb)
30 +
31 + const tagString = Value(content.tags.join(','))
32 + const tags = computed([tagString], x =>
33 + x.split(',').map(t => t.trim())
34 + )
35 + const notes = Value(content.notes)
36 + const isEditing = Value(true)
37 +
38 + var okay = h('button.save', {
39 + 'ev-click': () => {
40 + lb.remove()
41 + api.bookmark.async.save({
42 + messageId: content.messageId,
43 + recps: content.recps,
44 + tags: tags(),
45 + notes: notes()
46 + }, cb)
47 + }},
48 + 'save'
49 + )
50 +
51 + var cancel = h('button.cancel', {
52 + 'ev-click': () => {
53 + lb.remove()
54 + cb(null)
55 + }},
56 + 'cancel'
57 + )
58 +
59 + okay.addEventListener('keydown', (ev) => {
60 + if (ev.keyCode === 27) cancel.click() // escape
61 + })
62 +
63 + lb.show(h('SaveConfirm', [
64 + h('section -tags', [
65 + h('h4', 'Tags'),
66 + api.bookmark.html.tags(tags, isEditing, t => tagString.set(t))
67 + ]),
68 + h('section -notes', [
69 + h('h4', 'Notes'),
70 + api.bookmark.html.notes(notes, isEditing, n => notes.set(n))
71 + ]),
72 + h('section -actions', [cancel, okay])
73 + ]))
74 +
75 + okay.focus()
76 + }
77 +}
bookmark/html/confirm.mcssView
message/html/action/bookmark.jsView
@@ -3,51 +3,38 @@
33
44 exports.needs = nest({
55 'keys.sync.id': 'first',
66 'bookmark.obs.bookmark': 'first',
7- 'bookmark.async.save': 'first'
7 + 'bookmark.async.save': 'first',
8 + 'bookmark.html.confirm': 'first'
89 })
910
1011 exports.gives = nest('message.html.action')
1112
1213 exports.create = (api) => {
1314 return nest('message.html.action', msg => {
1415 var id = api.keys.sync.id()
1516 var bookmark = api.bookmark.obs.bookmark(msg.key, id)
17 + console.log(bookmark())
1618 var saved = computed([bookmark.tags], tags => isSaved(tags))
1719 return when(saved,
18- h('a.archive', {
20 + h('a.edit', {
1921 href: '#',
20- 'ev-click': () => save(msg, bookmark.recps(), bookmark.tags(), false)
21- }, 'Archive'),
22 + 'ev-click': () => save(msg, bookmark.recps(), bookmark.tags(), bookmark.notes())
23 + }, 'Edit'),
2224 h('a.save', {
2325 href: '#',
24- 'ev-click': () => save(msg, null, [], true)
26 + 'ev-click': () => save(msg, null, [], "")
2527 }, 'Save')
2628 )
2729 })
2830
29- function save (msg, recps, bookmarkTags, status = true) {
30- var currentTags = bookmarkTags || []
31- var tags
32- if (status) {
33- if (currentTags.includes('Archived')) {
34- tags = currentTags.filter(t => t !== 'Archived')
35- } else {
36- tags = currentTags
37- }
38- tags.push('Reading List')
39- } else {
40- tags = currentTags
41- tags.push('Archived')
31 + function save (msg, recps, bookmarkTags, notes) {
32 + var tags = bookmarkTags
33 + if (!tags || tags.length === 0) {
34 + tags = ['Reading List']
4235 }
43-
44- var notes = ""
45- if (msg.value && msg.value.content && msg.value.content.text) {
46- notes = msg.value.content.text.substring(0, 30) + "..."
47- }
48-
49- api.bookmark.async.save({
36 + return api.bookmark.html.confirm({
5037 messageId: msg.key,
5138 recps,
5239 notes,
5340 tags

Built with git-ssb-web