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 PMParent: 996cb9ffec97abd3bf8391f3a15e462d01fd663d
Files changed
main-window.js | changed |
modules/feed-summary.js | changed |
modules/public.js | changed |
main-window.js | ||
---|---|---|
@@ -33,10 +33,15 @@ | ||
33 | 33 | } |
34 | 34 | |
35 | 35 | var forwardHistory = [] |
36 | 36 | var backHistory = [] |
37 | + | |
37 | 38 | 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') | |
39 | 44 | }) |
40 | 45 | |
41 | 46 | var canGoForward = Value(false) |
42 | 47 | var canGoBack = Value(false) |
@@ -73,43 +78,43 @@ | ||
73 | 78 | classList: [ when(canGoForward, '-active') ] |
74 | 79 | }, '>') |
75 | 80 | ]), |
76 | 81 | 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') | |
89 | 84 | ]), |
90 | 85 | h('span.appTitle', ['Patchwork']), |
91 | 86 | h('span', [ searchBox ]), |
92 | 87 | 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') | |
105 | 90 | ]) |
106 | 91 | ]), |
107 | 92 | mainElement |
108 | 93 | ]) |
109 | 94 | |
110 | 95 | // scoped |
111 | 96 | |
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 | + | |
112 | 117 | function goBack () { |
113 | 118 | if (backHistory.length) { |
114 | 119 | canGoForward.set(true) |
115 | 120 | forwardHistory.push(currentView()) |
modules/feed-summary.js | ||
---|---|---|
@@ -86,13 +86,18 @@ | ||
86 | 86 | }) |
87 | 87 | |
88 | 88 | var abortLastFeed = null |
89 | 89 | |
90 | - return MutantArray([ | |
90 | + var result = MutantArray([ | |
91 | 91 | when(updates, updateLoader), |
92 | 92 | when(sync, scrollElement, m('Loading -large')) |
93 | 93 | ]) |
94 | 94 | |
95 | + result.reload = refresh | |
96 | + result.pendingUpdates = updates | |
97 | + | |
98 | + return result | |
99 | + | |
95 | 100 | // scoped |
96 | 101 | |
97 | 102 | function refresh () { |
98 | 103 | if (abortLastFeed) { |
modules/public.js | ||
---|---|---|
@@ -48,9 +48,42 @@ | ||
48 | 48 | var whoToFollow = computed([obs_following(id), obs_recently_updated_feeds(200)], (following, recent) => { |
49 | 49 | return Array.from(recent).filter(x => x !== id && !following.has(x)).slice(0, 10) |
50 | 50 | }) |
51 | 51 | |
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', [ | |
53 | 86 | h('div.side', [ |
54 | 87 | h('h2', 'Active Channels'), |
55 | 88 | when(loading, [ h('Loading') ]), |
56 | 89 | h('ChannelList', { |
@@ -122,43 +155,15 @@ | ||
122 | 155 | ]) |
123 | 156 | }) |
124 | 157 | ]) |
125 | 158 | ]), |
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 ]) | |
160 | 160 | ]) |
161 | + | |
162 | + result.pendingUpdates = feedSummary.pendingUpdates | |
163 | + result.reload = feedSummary.reload | |
164 | + | |
165 | + return result | |
161 | 166 | } |
162 | 167 | |
163 | 168 | // scoped |
164 | 169 |
Built with git-ssb-web