git ssb

0+

Josiah / patchbay-tags



Commit 3fa5fc29ea7ab4747f55ee28ba9428b03abe9c89

Edit bookmarks

Josiah Witt committed on 12/9/2017, 2:43:26 PM
Parent: 653e7d95783fcb22649a1ce70a47fc0deb571e3f

Files changed

bookmark/async/save.jschanged
bookmark/html/bookmark.mcsschanged
bookmark/html/notes.jschanged
bookmark/html/render.jschanged
bookmark/html/tags.jschanged
bookmark/html/tags.mcsschanged
bookmark/html/notes.mcssadded
bookmark/html/tagsBar.jsadded
bookmark/html/tagsBar.mcssadded
bookmark/page/bookmarks.jschanged
bookmark/async/save.jsView
@@ -8,9 +8,13 @@
88 })
99
1010 exports.create = function(api) {
1111 return nest('bookmark.async.save', function(data, cb) {
12- const { messageId, recps, notes, tags } = data
12 + const { messageId, notes, tags } = data
13 + var recps = data.recps
14 + if (recps && recps.length === 0) {
15 + recps = null
16 + }
1317 api.sbot.async.publish({
1418 type: 'about',
1519 about: messageId,
1620 recps,
bookmark/html/bookmark.mcssView
@@ -31,12 +31,26 @@
3131 }
3232
3333 section.actions {
3434 position: absolute
35- right: .5rem
35 + right: 3.1rem
3636 top: 1.5rem
3737 font-size: .9rem
3838 }
39 +
40 + button.edit {
41 + position: absolute
42 + right: 0
43 + top: 1.5rem
44 + font-size: .63rem
45 + }
46 +
47 + button.save {
48 + position: absolute
49 + right: 4.1rem
50 + top: 1.5rem
51 + font-size: .63rem
52 + }
3953 }
4054
4155 Saved {
4256 padding: 1rem .5rem 1rem 6rem
bookmark/html/notes.jsView
@@ -9,9 +9,9 @@
99
1010 exports.create = (api) => {
1111 return nest('bookmark.html.notes', notes)
1212
13- function notes ({ notes, isEditing, onUpdate }) {
13 + function notes(notes, isEditing, onUpdate) {
1414 const markdown = api.message.html.markdown
1515 const input = h(
1616 'textarea',
1717 {
bookmark/html/render.jsView
@@ -1,14 +1,16 @@
1-const { h, Value, when, computed, map } = require('mutant')
1 +const { h, Struct, Value, when, computed, map } = require('mutant')
22 const nest = require('depnest')
33 const ref = require('ssb-ref')
44
55 exports.needs = nest({
66 'about.html.avatar': 'first',
77 'bookmark.obs.bookmark': 'first',
8 + 'bookmark.obs.struct': 'first',
89 'bookmark.html': {
910 action: 'map',
10- tag: 'first'
11 + notes: 'first',
12 + tags: 'first'
1113 },
1214 'message.html': {
1315 author: 'first',
1416 link: 'first',
@@ -19,15 +21,25 @@
1921
2022 exports.gives = nest('bookmark.html.render')
2123
2224 exports.create = function(api) {
25 +
2326 return nest({
2427 'bookmark.html.render': renderBookmark
2528 })
2629
2730 function renderBookmark(msg, { pageId } = {}) {
2831 const id = api.keys.sync.id()
2932 const bookmark = api.bookmark.obs.bookmark(msg.key, id)
33 + const edited = api.bookmark.obs.struct()
34 + for (var i in bookmark.recps()) {
35 + edited.recps.add(bookmark.recps()[i])
36 + }
37 + for (var i in bookmark.tags()) {
38 + edited.tags.add(bookmark.tags()[i])
39 + }
40 + edited.notes.set(bookmark.notes())
41 + const isEditing = Value(false)
3042
3143 const content = [
3244 h('Saved', [
3345 h('section.avatar', {}, api.about.html.avatar(msg.value.author)),
@@ -36,35 +48,61 @@
3648 h('section.content', {}, messageContent(msg)),
3749 ])
3850 ]
3951
52 + const editToggle = h('button.edit', {
53 + 'ev-click': () => isEditing.set(!isEditing())
54 + }, when(isEditing, 'Cancel', 'Edit'))
55 +
56 + const saveButton = when(isEditing,
57 + h('button.save', {
58 + 'ev-click': () => {
59 + edited.save(msg.key)
60 + isEditing.set(false)
61 + }
62 + }, 'Save'),
63 + null
64 + )
65 +
4066 return h(
4167 'Bookmark',
4268 { attributes: { tabindex: '0' } },
4369 [
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)),
47- h('section.actions', {}, api.bookmark.html.action(msg.key))
70 + h('section.message', content),
71 + h('section.tags',
72 + api.bookmark.html.tags(
73 + bookmark.tags,
74 + isEditing,
75 + tags => {
76 + edited.tags.clear()
77 + const toAdd = tags.split(',').map(t => t.trim())
78 + for(var i in toAdd) {
79 + edited.tags.add(toAdd[i])
80 + }
81 + }
82 + )
83 + ),
84 + h('section.notes', [
85 + h('h4', 'Notes'),
86 + api.bookmark.html.notes(
87 + bookmark.notes,
88 + isEditing,
89 + notes => edited.notes.set(notes)
90 + )
91 + ]),
92 + h('section.actions', when(isEditing, null, api.bookmark.html.action(msg.key))),
93 + editToggle,
94 + saveButton
4895 ]
4996 )
5097 }
5198
52- function messageContent (data) {
99 + function messageContent(data) {
53100 if (!data.value.content || !data.value.content.text) return
54101 return h('div', {}, api.message.html.markdown(data.value.content))
55102 }
56103
57- function messageTitle (data) {
104 + function messageTitle(data) {
58105 var root = data.value.content && data.value.content.root
59106 return !root ? null : h('span', ['re: ', api.message.html.link(root)])
60107 }
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- }
70108 }
bookmark/html/tags.jsView
@@ -1,6 +1,6 @@
11
2-var { h, map } = require('mutant')
2 +var { h, map, when } = require('mutant')
33 var nest = require('depnest')
44
55 exports.needs = nest({
66 'bookmark.html.tag': 'first'
@@ -8,17 +8,17 @@
88
99 exports.gives = nest('bookmark.html.tags')
1010
1111 exports.create = (api) => {
12- return nest('bookmark.html.tags', tags =>
13- h('Tags', [
14- h('h2', 'Tags'),
15- h('div.default', [
16- api.bookmark.html.tag("Reading List"),
17- api.bookmark.html.tag("Read"),
18- api.bookmark.html.tag("Favourites"),
19- api.bookmark.html.tag("Archived")
20- ]),
21- h('div', map(tags, tag => api.bookmark.html.tag(tag)))
22- ])
12 + return nest('bookmark.html.tags', (tags, isEditing, onUpdate) =>
13 + h('Tags',
14 + when(isEditing,
15 + h('input', {
16 + placeholder: 'message tags (comma separated)',
17 + 'ev-keyup': e => onUpdate(e.target.value),
18 + value: tags().join(",")
19 + }),
20 + map(tags, tag => api.bookmark.html.tag(tag))
21 + )
22 + )
2323 )
2424 }
bookmark/html/tags.mcssView
@@ -1,7 +1,11 @@
11 Tags {
2- border-bottom: 1px solid gray
2 +
3 + input {
4 + border: 1px solid gray
5 + padding: .6rem
6 + font-size: .9rem
7 + box-sizing: border-box
8 + width: 50%
9 + }
310
4- div {
5- margin-bottom: 1.5rem
6- }
711 }
bookmark/html/notes.mcssView
@@ -1,0 +1,11 @@
1 +Notes {
2 + textarea {
3 + width: 100%
4 + border: 1px solid gray
5 + padding: .6rem
6 + font-size: .9rem
7 + resize: none
8 + margin: 10px 0
9 + box-sizing: border-box
10 + }
11 +}
bookmark/html/tagsBar.jsView
@@ -1,0 +1,24 @@
1 +
2 +var { h, map } = require('mutant')
3 +var nest = require('depnest')
4 +
5 +exports.needs = nest({
6 + 'bookmark.html.tag': 'first'
7 +})
8 +
9 +exports.gives = nest('bookmark.html.tagsBar')
10 +
11 +exports.create = (api) => {
12 + return nest('bookmark.html.tagsBar', tags =>
13 + h('TagsBar', [
14 + h('h2', 'Tags'),
15 + h('div.default', [
16 + api.bookmark.html.tag("Reading List"),
17 + api.bookmark.html.tag("Read"),
18 + api.bookmark.html.tag("Favourites"),
19 + api.bookmark.html.tag("Archived")
20 + ]),
21 + h('div', map(tags, tag => api.bookmark.html.tag(tag)))
22 + ])
23 + )
24 +}
bookmark/html/tagsBar.mcssView
@@ -1,0 +1,7 @@
1 +TagsBar {
2 + border-bottom: 1px solid gray
3 +
4 + div {
5 + margin-bottom: 1.5rem
6 + }
7 +}
bookmark/page/bookmarks.jsView
@@ -21,9 +21,9 @@
2121 },
2222 'bookmark.html': {
2323 save: 'first',
2424 render: 'first',
25- tags: 'first'
25 + tagsBar: 'first'
2626 },
2727 'keys.sync.id': 'first',
2828 'sbot.async.get': 'first'
2929 })
@@ -46,17 +46,17 @@
4646 const tag = path['tag'] || 'Reading List'
4747
4848 const creator = api.bookmark.html.save({})
4949 const defaultTags = [ 'Reading List', 'Read', 'Favourites', 'Archived' ]
50- const tagSelector = api.bookmark.html.tags(
50 + const tagsBar = api.bookmark.html.tagsBar(
5151 computed(
5252 [api.bookmark.obs.tagsFrom(id)],
5353 tags => tags.filter(t => defaultTags.indexOf(t) < 0)
5454 )
5555 )
5656 const currentTag = h('h2', tag)
5757 const { container, content } = api.app.html.scroller({
58- prepend: [ creator, tagSelector, currentTag ]
58 + prepend: [ creator, tagsBar, currentTag ]
5959 })
6060
6161 pull(
6262 api.bookmark.pull.find(),
@@ -67,13 +67,11 @@
6767
6868 for (const msg in index[id]['tags'][tag]) {
6969 // Hide 'Archived' messages unless viewing 'Archived' tag
7070 // Hide 'Read' messages from 'Reading List' tag
71- const isArchived = archived[msg]
72- const isRead = read[msg]
73- if (tag !== 'Archived' && isArchived) continue
74- else if (tag === 'Reading List' && isRead) continue
75- else {
71 + if (tag !== 'Archived' && archived[msg]) continue
72 + else if (tag === 'Reading List' && read[msg]) continue
73 + else if (index[id]['tags'][tag][msg]) {
7674 msgs.push({
7775 key: msg,
7876 value: {
7977 content: {},

Built with git-ssb-web