git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 2e5aeeedfe7057f58946f677c5820a04f965057c

preload all tabs, display pending update count on tabs, reload tab on select if has updates

Matt McKegg committed on 11/4/2016, 1:15:39 PM
Parent: 996cb9ffec97abd3bf8391f3a15e462d01fd663d

Files changed

main-window.jschanged
modules/feed-summary.jschanged
modules/public.jschanged
main-window.jsView
@@ -33,10 +33,15 @@
3333 }
3434
3535 var forwardHistory = []
3636 var backHistory = []
37+
3738 var views = MutantDict({
38- '/public': screenView('/public')
39+ // preload tabs (and subscribe to update notifications)
40+ '/public': screenView('/public'),
41+ '/private': screenView('/private'),
42+ [ssbClient.id]: screenView(ssbClient.id),
43+ '/notifications': screenView('/notifications')
3944 })
4045
4146 var canGoForward = Value(false)
4247 var canGoBack = Value(false)
@@ -73,43 +78,43 @@
7378 classList: [ when(canGoForward, '-active') ]
7479 }, '>')
7580 ]),
7681 h('span.nav', [
77- h('a', {
78- href: '#/public',
79- classList: [
80- when(selected('/public'), '-selected')
81- ]
82- }, 'Public'),
83- h('a', {
84- href: '#/private',
85- classList: [
86- when(selected('/private'), '-selected')
87- ]
88- }, 'Private')
82+ tab('Public', '/public'),
83+ tab('Private', '/private')
8984 ]),
9085 h('span.appTitle', ['Patchwork']),
9186 h('span', [ searchBox ]),
9287 h('span.nav', [
93- h('a', {
94- href: `#${ssbClient.id}`,
95- classList: [
96- when(selected(`${ssbClient.id}`), '-selected')
97- ]
98- }, 'Profile'),
99- h('a', {
100- href: `#/notifications`,
101- classList: [
102- when(selected(`/notifications`), '-selected')
103- ]
104- }, 'Mentions')
88+ tab('Profile', ssbClient.id),
89+ tab('Mentions', '/notifications')
10590 ])
10691 ]),
10792 mainElement
10893 ])
10994
11095 // scoped
11196
97+ function tab (name, view) {
98+ var instance = views.get(view)
99+ return h('a', {
100+ 'ev-click': function (ev) {
101+ if (instance.pendingUpdates && instance.pendingUpdates() && instance.reload) {
102+ instance.reload()
103+ }
104+ },
105+ href: `#${view}`,
106+ classList: [
107+ when(selected(view), '-selected')
108+ ]
109+ }, [
110+ name,
111+ when(instance.pendingUpdates, [
112+ ' (', instance.pendingUpdates, ')'
113+ ])
114+ ])
115+ }
116+
112117 function goBack () {
113118 if (backHistory.length) {
114119 canGoForward.set(true)
115120 forwardHistory.push(currentView())
modules/feed-summary.jsView
@@ -86,13 +86,18 @@
8686 })
8787
8888 var abortLastFeed = null
8989
90- return MutantArray([
90+ var result = MutantArray([
9191 when(updates, updateLoader),
9292 when(sync, scrollElement, m('Loading -large'))
9393 ])
9494
95+ result.reload = refresh
96+ result.pendingUpdates = updates
97+
98+ return result
99+
95100 // scoped
96101
97102 function refresh () {
98103 if (abortLastFeed) {
modules/public.jsView
@@ -48,9 +48,42 @@
4848 var whoToFollow = computed([obs_following(id), obs_recently_updated_feeds(200)], (following, recent) => {
4949 return Array.from(recent).filter(x => x !== id && !following.has(x)).slice(0, 10)
5050 })
5151
52- return h('SplitView', [
52+ var feedSummary = feed_summary(getFeed, [
53+ message_compose({type: 'post'}, {placeholder: 'Write a public message'})
54+ ], {
55+ waitUntil: computed([
56+ following.sync,
57+ subscribedChannels.sync
58+ ], x => x.every(Boolean)),
59+ windowSize: 500,
60+ filter: (item) => {
61+ return (
62+ id === item.author ||
63+ following().has(item.author) ||
64+ subscribedChannels().has(item.channel) ||
65+ (item.repliesFrom && item.repliesFrom.has(id)) ||
66+ item.digs && item.digs.has(id)
67+ )
68+ },
69+ bumpFilter: (msg, group) => {
70+ if (!group.message) {
71+ return (
72+ isMentioned(id, msg.value.content.mentions) ||
73+ msg.value.author === id || (
74+ fromDay(msg, group.fromTime) && (
75+ following().has(msg.value.author) ||
76+ group.repliesFrom.has(id)
77+ )
78+ )
79+ )
80+ }
81+ return true
82+ }
83+ })
84+
85+ var result = h('SplitView', [
5386 h('div.side', [
5487 h('h2', 'Active Channels'),
5588 when(loading, [ h('Loading') ]),
5689 h('ChannelList', {
@@ -122,43 +155,15 @@
122155 ])
123156 })
124157 ])
125158 ]),
126- h('div.main', [
127- feed_summary(getFeed, [
128- message_compose({type: 'post'}, {placeholder: 'Write a public message'})
129- ], {
130- waitUntil: computed([
131- following.sync,
132- subscribedChannels.sync
133- ], x => x.every(Boolean)),
134- windowSize: 500,
135- filter: (item) => {
136- return (
137- id === item.author ||
138- following().has(item.author) ||
139- subscribedChannels().has(item.channel) ||
140- (item.repliesFrom && item.repliesFrom.has(id)) ||
141- item.digs && item.digs.has(id)
142- )
143- },
144- bumpFilter: (msg, group) => {
145- if (!group.message) {
146- return (
147- isMentioned(id, msg.value.content.mentions) ||
148- msg.value.author === id || (
149- fromDay(msg, group.fromTime) && (
150- following().has(msg.value.author) ||
151- group.repliesFrom.has(id)
152- )
153- )
154- )
155- }
156- return true
157- }
158- })
159- ])
159+ h('div.main', [ feedSummary ])
160160 ])
161+
162+ result.pendingUpdates = feedSummary.pendingUpdates
163+ result.reload = feedSummary.reload
164+
165+ return result
161166 }
162167
163168 // scoped
164169

Built with git-ssb-web