git ssb

0+

Josiah / patchbay-tags



Commit 0c6abd793f009544b7ae0cda6266da58bff2c66c

Add bookmark actions via tags

Josiah Witt committed on 11/27/2017, 10:30:34 PM
Parent: d6861e3a6c97728f151fbc42d87fe7b565358976

Files changed

bookmark/html/render.jschanged
bookmark/html/action/archive.jsadded
bookmark/html/action/favourite.jsadded
bookmark/html/action/read.jsadded
bookmark/html/tag.jsadded
bookmark/obs/bookmark.jschanged
bookmark/html/render.jsView
@@ -1,64 +1,53 @@
1-const { h, Value, when, computed } = require('mutant')
1 +const { h, Value, when, computed, map } = require('mutant')
22 const nest = require('depnest')
33
44 exports.needs = nest({
55 'blob.sync.url': 'first',
66 'bookmark.obs.bookmark': 'first',
77 'feed.html.render': 'first',
88 'keys.sync.load': 'first',
99 'about.html.link': 'first',
10- 'about.html.image': 'first',
10 + 'bookmark.html.action': 'map',
1111 'message.html': {
1212 decorate: 'reduce',
13- link: 'first',
14- markdown: 'first',
15- backlinks: 'first',
16- meta: 'map',
17- action: 'map',
1813 timestamp: 'first',
1914 },
2015 })
2116
2217 exports.gives = nest({
23- 'message.html': [ 'render' ],
18 + // 'message.html': [ 'render' ],
2419 'bookmark.html': [ 'render' ]
2520 })
2621
2722 exports.create = function(api) {
28- const { timestamp, meta, backlinks, action } = api.message.html
29-
3023 return nest({
31- 'message.html.render': renderBookmark,
24 + // 'message.html.render': renderBookmark,
3225 'bookmark.html.render': renderBookmark
3326 })
3427
3528 function renderBookmark(msg, { pageId } = {}) {
3629 if (!msg.value || (msg.value.content.type !== 'bookmark')) return
3730
3831 const bookmark = api.bookmark.obs.bookmark(msg.key)
32 + console.log(bookmark())
3933
4034 const content = [
4135 h('a', { href: bookmark.messageId }, [
4236 h('.details', [
4337 h('Title', bookmark.title),
4438 h('Description', bookmark.description),
45- h('Tags', bookmark.tags().map(tag =>
46- h('Tag', tag)
47- ))
39 + h('Tags', map(bookmark.tags, tag => h('Tag', tag)))
4840 ])
4941 ])
5042 ]
5143
5244 const message = h(
5345 'Message -bookmark',
5446 [
55- h('section.avatar', {}, api.about.html.image(msg.value.author)),
56- h('section.timestamp', {}, timestamp(msg)),
57- h('section.meta', {}, meta(msg)),
47 + h('section.timestamp', {}, api.message.html.timestamp(msg)),
5848 h('section.content', {}, content),
59- h('section.actions', {}, action(msg)),
60- h('footer.backlinks', {}, backlinks(msg))
49 + h('section.actions', {}, api.bookmark.html.action(msg))
6150 ]
6251 )
6352
6453 const element = h(
bookmark/html/action/archive.jsView
@@ -1,0 +1,15 @@
1 +var nest = require('depnest')
2 +
3 +exports.needs = nest({
4 + 'bookmark.html.tag': 'first'
5 +})
6 +
7 +exports.gives = nest('bookmark.html.action')
8 +
9 +exports.create = (api) => {
10 + return nest('bookmark.html.action', archive)
11 +
12 + function archive(msg) {
13 + return api.bookmark.html.tag('archived', 'Archive', 'Unarchive')(msg)
14 + }
15 +}
bookmark/html/action/favourite.jsView
@@ -1,0 +1,15 @@
1 +var nest = require('depnest')
2 +
3 +exports.needs = nest({
4 + 'bookmark.html.tag': 'first'
5 +})
6 +
7 +exports.gives = nest('bookmark.html.action')
8 +
9 +exports.create = (api) => {
10 + return nest('bookmark.html.action', favourite)
11 +
12 + function favourite(msg) {
13 + return api.bookmark.html.tag('favourite', 'Favourite', 'Unfavourite')(msg)
14 + }
15 +}
bookmark/html/action/read.jsView
@@ -1,0 +1,15 @@
1 +var nest = require('depnest')
2 +
3 +exports.needs = nest({
4 + 'bookmark.html.tag': 'first'
5 +})
6 +
7 +exports.gives = nest('bookmark.html.action')
8 +
9 +exports.create = (api) => {
10 + return nest('bookmark.html.action', read)
11 +
12 + function read(msg) {
13 + return api.bookmark.html.tag('read', 'Read', 'Unread')(msg)
14 + }
15 +}
bookmark/html/tag.jsView
@@ -1,0 +1,51 @@
1 +var { h, computed, when } = require('mutant')
2 +var nest = require('depnest')
3 +
4 +exports.needs = nest({
5 + 'bookmark.obs.bookmark': 'first',
6 + 'bookmark.async.tags': 'first'
7 +})
8 +
9 +exports.gives = nest('bookmark.html.tag')
10 +
11 +exports.create = (api) => {
12 + return nest('bookmark.html.tag', tag)
13 +
14 + function tag(tagValue, doActionText, undoActionText) {
15 + return function(msg) {
16 + var bookmark = api.bookmark.obs.bookmark(msg.key)
17 + console.log(bookmark())
18 + var tagged = computed([bookmark.tags, tagValue], isTagged)
19 + return when(tagged,
20 + h('a.undoAction', {
21 + href: '#',
22 + 'ev-click': () => publishAction(msg, bookmark.tags, tagValue, false)
23 + }, undoActionText),
24 + h('a.doAction', {
25 + href: '#',
26 + 'ev-click': () => publishAction(msg, bookmark.tags, tagValue, true)
27 + }, doActionText)
28 + )
29 + }
30 + }
31 +
32 + function publishAction(msg, tags, tagValue, status = true) {
33 + var currentTags = tags() || []
34 + var nextTags
35 + if (status) {
36 + nextTags = currentTags
37 + nextTags.push(tagValue)
38 + } else {
39 + nextTags = currentTags.filter(t => t !== tagValue)
40 + }
41 + api.bookmark.async.tags({
42 + bookmark: msg.key,
43 + tags: [ nextTags ],
44 + public: true
45 + }, console.log)
46 + }
47 +}
48 +
49 +function isTagged(tags, tag) {
50 + return tags.includes(tag)
51 +}
bookmark/obs/bookmark.jsView
@@ -4,25 +4,27 @@
44 const { computed } = require('mutant')
55
66 exports.needs = nest({
77 'about.obs.latestValue': 'first',
8- 'about.obs.groupedValues': 'first',
9- 'bookmark.obs.struct': 'first'
8 + 'about.obs.valueFrom': 'first',
9 + 'bookmark.obs.struct': 'first',
10 + 'keys.sync.id': 'first'
1011 })
1112
1213 exports.gives = nest('bookmark.obs.bookmark')
1314
1415 exports.create = function(api) {
1516 return nest('bookmark.obs.bookmark', function(bookmarkId) {
1617 if (!ref.isLink(bookmarkId)) throw new Error('an id must be specified')
1718
18- const { latestValue, groupedValues } = api.about.obs
19 + const { latestValue, valueFrom } = api.about.obs
20 + const id = api.keys.sync.id()
1921
2022 const bookmark = api.bookmark.obs.struct({
2123 title: latestValue(bookmarkId, 'title'),
2224 description: latestValue(bookmarkId, 'description'),
2325 messageId: latestValue(bookmarkId, 'messageId'),
24- tags: computed([groupedValues(bookmarkId, 'tags')], Object.keys)
26 + tags: valueFrom(bookmarkId, 'tags', id)
2527 })
2628
2729 return bookmark
2830 })

Built with git-ssb-web