git ssb

2+

mixmix / ticktack



Commit 314000baff3b2045fe13f8edf6519b9bdd1779d5

basic chunked DOM + style

mix irving committed on 8/8/2017, 11:54:48 AM
Parent: fd90a69c5a2931ed4ec735c57c4b2ebb42bcfe42

Files changed

app/html/app.jschanged
app/html/thread.jschanged
app/html/thread.mcsschanged
styles/mixins.jschanged
test/fixtures/thread.jschanged
app/html/app.jsView
@@ -15,7 +15,8 @@
1515 function app () {
1616 const css = values(api.styles.css()).join('\n')
1717 insertCss(css)
1818
19- return api.app.sync.goTo({ page: 'home' })
19+ // return api.app.sync.goTo({ page: 'home' })
20+ return api.app.sync.goTo({key: "%fXXZgQrwnj7F+Y19H0IXxNriuvPFoahvusih3UzpkfA=.sha256"})
2021 }
2122 }
app/html/thread.jsView
@@ -1,9 +1,9 @@
11 const nest = require('depnest')
2-const { h, Array: MutantArray, map } = require('mutant')
2+const { h, Array: MutantArray, map, computed, when } = require('mutant')
33 const pull = require('pull-stream')
44 const last = require('lodash/last')
5-const get = require('lodash/last')
5+const get = require('lodash/get')
66
77 exports.gives = nest('app.html.thread')
88
99 exports.needs = nest({
@@ -17,23 +17,44 @@
1717 // location here can expected to be: { page: 'home' }
1818
1919 const chunkedThread = buildChunkedThreadObs(source)
2020
21+ var myId = '@EMovhfIrFk4NihAKnRNhrfRaqIhBv1Wj8pTxJNgvCCY=.ed25519'
22+ // TODO (mix) use keys.sync.id
23+
2124 const { goTo } = api.app.sync
2225 const threadView = h('Thread',
2326 map(chunkedThread, chunk => {
24- return h('div' , [
25- h('div', '---'),
2627
27- map(chunk, msg => {
28- return h('div', {style: { margin: '10px', background: 'white' }}, msg.value.content.text) // TODO (mix): use lodash/get
29- })
30- ])
28+ return computed(chunk, chunk => get(chunk, '[0].value.author') === myId
29+ ? h('div.my-chunk', [
30+ h('div.avatar'),
31+ h('div.msgs', map(chunk, msg => {
32+ return h('div.msg-row', [
33+ h('div.spacer'),
34+ h('div.msg', get(msg, 'value.content.text'))
35+ ])
36+ }))
37+ ])
38+ : h('div.other-chunk', [
39+ h('div.avatar', 'other'),
40+ h('div.msgs', map(chunk, msg => {
41+ return h('div.msg-row', [
42+ h('div.msg', get(msg, 'value.content.text')),
43+ h('div.spacer')
44+ ])
45+ }))
46+ ])
47+ )
3148 })
3249 )
3350
3451 return threadView
3552 }
53+
54+ function isByMe (msg) {
55+ return msg && msg.value.author === myId
56+ }
3657 }
3758
3859 function buildChunkedThreadObs (source) {
3960 var chunkedThread = MutantArray()
@@ -67,4 +88,5 @@
6788 // TODO (mix) use lodash/get
6889 return msgA.value.author === msgB.value.author
6990 }
7091
92+
app/html/thread.mcssView
@@ -1,5 +1,98 @@
11 Thread {
2- background-color: lightgrey
2+ background-color: #eee
33 padding: 1rem
4+ font-family: 'arial'
5+
6+ max-width: 1400px
7+
8+ display: flex
9+ flex-direction: column
10+
11+ div.my-chunk {
12+ $chunk
13+
14+ justify-content: space-between
15+
16+ div.avatar {
17+ visibility: hidden
18+ }
19+
20+ div.msgs {
21+ div.msg-row {
22+ div.msg {
23+ $primaryColor
24+
25+ border-bottom-left-radius: .7rem
26+ border-top-left-radius: .7rem
27+ }
28+ :first-child {
29+ div.msg {
30+ border-top-right-radius: .7rem
31+ }
32+ }
33+ :last-child {
34+ div.msg {
35+ border-bottom-right-radius: .7rem
36+ }
37+ }
38+ }
39+ }
40+ }
41+
42+ div.other-chunk {
43+ $chunk
44+
45+ div.msgs {
46+
47+ div.msg-row {
48+ div.msg {
49+ border-bottom-right-radius: .7rem
50+ border-top-right-radius: .7rem
51+ }
52+ :first-child {
53+ div.msg {
54+ border-top-left-radius: .7rem
55+ }
56+ }
57+ :last-child {
58+ div.msg {
59+ border-bottom-left-radius: .7rem
60+ }
61+ }
62+ }
63+ }
64+ }
465 }
566
67+$chunk {
68+ display: flex
69+ margin-bottom: .5rem
70+
71+ div.avatar {
72+ background-color: grey
73+ width: 2rem
74+ height: 2rem
75+ border-radius: 1rem
76+
77+ margin-right: 1rem
78+ }
79+
80+ div.msgs {
81+ max-width: 80%
82+ div.msg-row {
83+ display: flex
84+
85+ div.msg {
86+ line-height: 1.2rem
87+ background-color: #fff
88+ padding: .7rem
89+ margin-bottom: .3rem
90+ border-radius: .3rem
91+ }
92+ div.msg-spacer {
93+ flex-grow: grow
94+ }
95+ }
96+ }
97+}
98+
styles/mixins.jsView
@@ -9,14 +9,15 @@
99 })
1010 }
1111
1212 const mainMixins = `
13-$colorPrimary {
14- color: green
13+$primaryColor {
14+ color: white
15+ background-color: #3dc8c3
1516 }
1617
1718 $colorSubtle {
18- color: gray
19+ color: #222
1920 }
2021
2122 $avatarSmall {
2223 width: 32px
test/fixtures/thread.jsView
@@ -1,7 +1,7 @@
11 // an arrage of messages in a thread
22 // can stream by making a source with pull.values()
3-// If you assume you're Dominic, your key is : %IAkSWeMycouc4MM7eakTTIC+TITDNtvfpFp3Jgz4LiU=.sha256
3+// If you assume you're Dominic, your key is : @EMovhfIrFk4NihAKnRNhrfRaqIhBv1Wj8pTxJNgvCCY=.ed25519
44
55 module.exports = [{
66 "key": "%fXXZgQrwnj7F+Y19H0IXxNriuvPFoahvusih3UzpkfA=.sha256",
77 "value": {

Built with git-ssb-web