git ssb

0+

Josiah / patchbay-tags



Commit 653e7d95783fcb22649a1ce70a47fc0deb571e3f

Switch to notes, update render to include post

Josiah Witt committed on 12/9/2017, 3:09:51 AM
Parent: 5088f35306e7b681fb4597330037615db8c790b0

Files changed

bookmark/async/save.jschanged
bookmark/html/bookmark.mcsschanged
bookmark/html/render.jschanged
bookmark/html/save.jschanged
bookmark/html/save.mcsschanged
bookmark/html/description.jsdeleted
bookmark/html/notes.jsadded
bookmark/obs/bookmark.jschanged
bookmark/obs/struct.jschanged
bookmark/page/bookmarks.jschanged
message/html/action/bookmark.jschanged
bookmark/async/save.jsView
@@ -8,15 +8,14 @@
88 })
99
1010 exports.create = function(api) {
1111 return nest('bookmark.async.save', function(data, cb) {
12- const { messageId, recps, title, description, tags } = data
12 + const { messageId, recps, notes, tags } = data
1313 api.sbot.async.publish({
1414 type: 'about',
1515 about: messageId,
1616 recps,
17- title,
18- description,
17 + notes,
1918 tags
2019 }, cb)
2120 })
2221 }
bookmark/html/bookmark.mcssView
@@ -17,55 +17,62 @@
1717 $textSubtle
1818 }
1919 }
2020
21- section.title {
22- flex-basis: 100%
21 + section.message {
22 + width: 100%
23 + }
24 +
25 + section.notes {
26 + width: 100%
27 + }
28 +
29 + section.tags {
30 + width: 100%
31 + }
32 +
33 + section.actions {
34 + position: absolute
35 + right: .5rem
36 + top: 1.5rem
2337 font-size: .9rem
38 + }
39 +}
2440
25- span, span a {
26- $textSubtle
41 +Saved {
42 + padding: 1rem .5rem 1rem 6rem
43 + position: relative
44 + display: flex
45 + flex-direction: row
46 + flex-wrap: wrap
47 + justify-content: flex-end
48 +
49 + section.avatar {
50 + position: absolute
51 + left: .5rem
52 +
53 + a img {
2754 }
2855 }
2956
30- section.content {
57 + section.author {
3158 flex-basis: 100%
32- margin-top: .4rem
33-
34- (img) {
35- max-width: 100%
36- }
3759 }
3860
39- section.actions {
61 + section.title {
4062 flex-basis: 100%
41- display: flex
42- justify-content: flex-end
43-
4463 font-size: .9rem
45- a {
46- margin-left: .5em
47- }
4864
49- a.unlike {
65 + span, span a {
5066 $textSubtle
5167 }
5268 }
53-}
5469
55-Details {
56- div {
57- color: black
58- }
70 + section.content {
71 + flex-basis: 100%
72 + margin-top: .4rem
5973
60- a {
61- div.title {
62- font-size: 1.2rem
63- color: black
64- margin-bottom: .5rem
74 + (img) {
75 + max-width: 100%
6576 }
6677 }
67-
68- div.tags {
69- margin: 1rem 0 .5rem 0
70- }
7178 }
bookmark/html/render.jsView
@@ -2,60 +2,69 @@
22 const nest = require('depnest')
33 const ref = require('ssb-ref')
44
55 exports.needs = nest({
6 + 'about.html.avatar': 'first',
67 'bookmark.obs.bookmark': 'first',
78 'bookmark.html': {
8- 'action': 'map',
9- 'tag': 'first'
9 + action: 'map',
10 + tag: 'first'
1011 },
1112 'message.html': {
12- decorate: 'reduce',
13- timestamp: 'first',
13 + author: 'first',
14 + link: 'first',
15 + markdown: 'first',
1416 },
1517 'keys.sync.id': 'first'
1618 })
1719
18-exports.gives = nest({
19- // 'message.html': [ 'render' ],
20- 'bookmark.html': [ 'render' ]
21-})
20 +exports.gives = nest('bookmark.html.render')
2221
2322 exports.create = function(api) {
2423 return nest({
25- // 'message.html.render': renderBookmark,
2624 'bookmark.html.render': renderBookmark
2725 })
2826
2927 function renderBookmark(msg, { pageId } = {}) {
3028 const id = api.keys.sync.id()
3129 const bookmark = api.bookmark.obs.bookmark(msg.key, id)
32- console.log('BKMK', bookmark())
3330
3431 const content = [
35- h('Details', [
36- h('a', { href: bookmark.messageId }, [
37- h('div.title', bookmark.title)
38- ]),
39- h('div.description', bookmark.description),
40- h('div.tags', map(bookmark.tags, tag => api.bookmark.html.tag(tag)))
32 + h('Saved', [
33 + h('section.avatar', {}, api.about.html.avatar(msg.value.author)),
34 + h('section.author', {}, api.message.html.author(msg)),
35 + h('section.title', {}, messageTitle(msg)),
36 + h('section.content', {}, messageContent(msg)),
4137 ])
4238 ]
4339
44- const view = h(
40 + return h(
4541 'Bookmark',
42 + { attributes: { tabindex: '0' } },
4643 [
47- h('section.timestamp', {}, api.message.html.timestamp(msg)),
48- h('section.content', {}, content),
44 + h('section.message', {}, content),
45 + h('section.tags', map(bookmark.tags, tag => api.bookmark.html.tag(tag))),
46 + h('section.notes', computed([bookmark.notes], messageNotes)),
4947 h('section.actions', {}, api.bookmark.html.action(msg.key))
5048 ]
5149 )
50 + }
5251
53- const element = h(
54- 'div',
55- { attributes: { tabindex: '0' } },
56- view
57- )
52 + function messageContent (data) {
53 + if (!data.value.content || !data.value.content.text) return
54 + return h('div', {}, api.message.html.markdown(data.value.content))
55 + }
5856
59- return api.message.html.decorate(element, { msg })
57 + function messageTitle (data) {
58 + var root = data.value.content && data.value.content.root
59 + return !root ? null : h('span', ['re: ', api.message.html.link(root)])
6060 }
61 +
62 + function messageNotes (data) {
63 + console.log(data)
64 + if (!data) return
65 + return h('div', {}, [
66 + h('h4', 'Notes'),
67 + api.message.html.markdown(data)
68 + ])
69 + }
6170 }
bookmark/html/save.jsView
@@ -16,10 +16,9 @@
1616 function create() {
1717 var open = Value(false)
1818 var bookmark = Struct({
1919 messageId: Value(),
20- title: Value(),
21- description: Value(),
20 + notes: Value(),
2221 tags: Value(),
2322 public: Value()
2423 })
2524
@@ -32,10 +31,9 @@
3231 const saveButton = h('button.save', { 'ev-click': () =>
3332 api.bookmark.async.save({
3433 recps: bookmark.public() ? null : [ id ],
3534 messageId: bookmark.messageId(),
36- title: bookmark.title(),
37- description: bookmark.description(),
35 + notes: bookmark.notes(),
3836 tags: bookmark.tags().split(',').map(tag => tag.trim())
3937 }, console.log)
4038 }, 'Save')
4139
@@ -43,18 +41,13 @@
4341 placeholder: 'id of message to save',
4442 'ev-keyup': e => bookmark.messageId.set(e.target.value)
4543 })
4644
47- const titleInput = h('input.title', {
48- placeholder: 'title of message',
49- 'ev-keyup': e => bookmark.title.set(e.target.value)
45 + const notesInput = h('textarea', {
46 + placeholder: 'notes about message',
47 + 'ev-keyup': e => bookmark.notes.set(e.target.value)
5048 })
5149
52- const descriptionInput = h('textarea', {
53- placeholder: 'description of message',
54- 'ev-keyup': e => bookmark.description.set(e.target.value)
55- })
56-
5750 const tagsInput = h('input.tags', {
5851 placeholder: 'message tags (comma separated)',
5952 'ev-keyup': e => bookmark.tags.set(e.target.value)
6053 })
@@ -73,10 +66,9 @@
7366 h('h2', 'Save a Bookmark'),
7467 cancelButton,
7568 saveButton,
7669 messageInput,
77- titleInput,
78- descriptionInput,
70 + notesInput,
7971 tagsInput,
8072 publicInput
8173 ]
8274 ),
bookmark/html/save.mcssView
@@ -19,16 +19,12 @@
1919 box-sizing: border-box
2020 }
2121
2222 input.message {
23- width: 25%
23 + width: 100%
2424 margin-right: .6rem
2525 }
2626
27- input.title {
28- width: calc(75% - .6rem)
29- }
30-
3127 input.tags {
3228 position: absolute
3329 left: 0
3430 bottom: 1.2rem
bookmark/html/description.jsView
@@ -1,30 +1,0 @@
1-const nest = require('depnest')
2-const { h, computed, when } = require('mutant')
3-
4-exports.needs = nest({
5- 'message.html.markdown': 'first'
6-})
7-
8-exports.gives = nest('bookmark.html.description')
9-
10-exports.create = (api) => {
11- return nest('bookmark.html.description', description)
12- function description ({ description, isEditing, onUpdate }) {
13- const markdown = api.message.html.markdown
14- const input = h(
15- 'textarea',
16- {
17- 'ev-input': e => onUpdate(e.target.value),
18- 'value': description
19- }
20- )
21-
22- return h('Description', [
23- when(
24- isEditing,
25- input,
26- computed(description, d => d ? markdown(d) : '')
27- )
28- ])
29- }
30-}
bookmark/html/notes.jsView
@@ -1,0 +1,30 @@
1 +const nest = require('depnest')
2 +const { h, computed, when } = require('mutant')
3 +
4 +exports.needs = nest({
5 + 'message.html.markdown': 'first'
6 +})
7 +
8 +exports.gives = nest('bookmark.html.notes')
9 +
10 +exports.create = (api) => {
11 + return nest('bookmark.html.notes', notes)
12 +
13 + function notes ({ notes, isEditing, onUpdate }) {
14 + const markdown = api.message.html.markdown
15 + const input = h(
16 + 'textarea',
17 + {
18 + 'ev-input': e => onUpdate(e.target.value),
19 + 'value': notes
20 + }
21 + )
22 + return h('Notes', [
23 + when(
24 + isEditing,
25 + input,
26 + computed(notes, d => d ? markdown(d) : '')
27 + )
28 + ])
29 + }
30 +}
bookmark/obs/bookmark.jsView
@@ -18,10 +18,9 @@
1818
1919 const { latestValue, valueFrom, groupedValues } = api.about.obs
2020
2121 const bookmark = api.bookmark.obs.struct({
22- title: latestValue(messageId, 'title'),
23- description: latestValue(messageId, 'description'),
22 + notes: latestValue(messageId, 'notes'),
2423 tags: valueFrom(messageId, 'tags', id),
2524 recps: latestValue(messageId, 'recps')
2625 })
2726
bookmark/obs/struct.jsView
@@ -9,10 +9,9 @@
99
1010 exports.create = function(api) {
1111 return nest('bookmark.obs.struct', function(opts = {}) {
1212 const struct = Struct({
13- title: Value(''),
14- description: Value(''),
13 + notes: Value(''),
1514 tags: Set([]),
1615 recps: Set([])
1716 })
1817
@@ -26,10 +25,9 @@
2625 struct.save = id => {
2726 api.bookmark.async.save({
2827 recps: struct.recps(),
2928 messageId: id,
30- title: struct.title(),
31- description: struct.description(),
29 + notes: struct.notes(),
3230 tags: struct.tags()
3331 }, console.log)
3432 }
3533
bookmark/page/bookmarks.jsView
@@ -23,9 +23,10 @@
2323 save: 'first',
2424 render: 'first',
2525 tags: 'first'
2626 },
27- 'keys.sync.id': 'first'
27 + 'keys.sync.id': 'first',
28 + 'sbot.async.get': 'first'
2829 })
2930
3031 exports.create = function(api) {
3132 return nest({
@@ -44,16 +45,13 @@
4445 const id = api.keys.sync.id()
4546 const tag = path['tag'] || 'Reading List'
4647
4748 const creator = api.bookmark.html.save({})
48- const defaultTags = [ 'Reading List', 'Read', 'Favourite', 'Archived' ]
49 + const defaultTags = [ 'Reading List', 'Read', 'Favourites', 'Archived' ]
4950 const tagSelector = api.bookmark.html.tags(
5051 computed(
5152 [api.bookmark.obs.tagsFrom(id)],
52- tags => {
53- console.log('TAGS', tags)
54- return tags.filter(t => defaultTags.indexOf(t) < 0)
55- }
53 + tags => tags.filter(t => defaultTags.indexOf(t) < 0)
5654 )
5755 )
5856 const currentTag = h('h2', tag)
5957 const { container, content } = api.app.html.scroller({
@@ -87,8 +85,15 @@
8785 msgs.sort((a, b) => a.value.timestamp < b.value.timestamp)
8886 return msgs
8987 }),
9088 pull.flatten(),
89 + pull.map(msg => msg.key),
90 + pull.asyncMap((key, cb) => {
91 + api.sbot.async.get(key, (_, value) => {
92 + const msg = { key, value }
93 + cb(null, msg)
94 + })
95 + }),
9196 Scroller(container, content, api.bookmark.html.render, false, false)
9297 )
9398
9499 container.title = '/bookmarks/' + tag
message/html/action/bookmark.jsView
@@ -40,19 +40,17 @@
4040 tags = currentTags
4141 tags.push('Archived')
4242 }
4343
44- var title
44 + var notes = ""
4545 if (msg.value && msg.value.content && msg.value.content.text) {
46- title = msg.value.content.text.substring(0, 30) + "..."
47- } else {
48- title = "Untitled"
46 + notes = msg.value.content.text.substring(0, 30) + "..."
4947 }
5048
5149 api.bookmark.async.save({
5250 messageId: msg.key,
5351 recps,
54- title,
52 + notes,
5553 tags
5654 }, console.log)
5755 }
5856 }

Built with git-ssb-web