diff --git a/TODO b/TODO index ff441a7..577ee27 100644 --- a/TODO +++ b/TODO @@ -7,15 +7,4 @@ * People Picker widget to integrate with contacts for posting(?) # Widget Reorg - * Replace existing programmatic template rendering (from templates.js), be sure to clean up all instances - * Start with timeline/List widget - * Add filter (search user name and content) once this is working properly - * Be sure to tweak lookahead to work nicely with quick flicks on the list widget - * Separation of data/logic/presentation - * Data is available immediately from widget model, rather than having to parse it from the DOM as it is currently - * Perform all logic (filtering/sorting/classifying entries as new/read/direct/retweet/etc) on the data prior to rendering view - * Invalid items, such as tweets without users, should be pruned at the model level, perhaps in Lawnchair - * If it will be reused, break this logic off into one of the helpers, view into shared - * View becomes a dumb shell, easy to maintain - * Using Mojo models allows us to update multiple widgets onscreen with one call to modelChanged() - * Make sure to apply all existing event listeners to the widgets \ No newline at end of file + * Add filter (search user name and content) once this is working properly diff --git a/app/assistants/favorites-assistant.js b/app/assistants/favorites-assistant.js index 8028715..534cb04 100644 --- a/app/assistants/favorites-assistant.js +++ b/app/assistants/favorites-assistant.js @@ -8,6 +8,10 @@ function FavoritesAssistant() { FavoritesAssistant.prototype.setup = function() { + this.timelineModel = {items: []}; + this.controller.setupWidget("favorites-timeline", {itemTemplate: "shared/tweet", hasNoWidgets: true, lookahead: 20, renderLimit: 20}, this.timelineModel); + this.filterState = "favorites"; + this.scroller = this.controller.getSceneScroller(); this.initAppMenu({ 'items':loggedin_appmenu_items }); this.initTwit('DOM'); @@ -69,7 +73,7 @@ FavoritesAssistant.prototype.activate = function(event) { Prepare for timeline entry taps */ this.bindTimelineEntryTaps('#favorites-timeline'); - + this.controller.listen("favorites-timeline", Mojo.Event.listTap, this.handleTimelineTap); /* set up the public timeline */ @@ -107,7 +111,9 @@ FavoritesAssistant.prototype.activate = function(event) { }; - thisA.favtl.addItems(no_dupes); + // thisA.favtl.addItems(no_dupes); + thisA.renderTimeline(); + sc.helpers.markAllAsRead('#favorites-timeline div.timeline-entry'); // favs are never "new" sc.helpers.updateRelativeTimes('#favorites-timeline div.timeline-entry span.date', 'data-created_at'); thisA.hideInlineSpinner('activity-spinner-favorites'); @@ -151,7 +157,7 @@ FavoritesAssistant.prototype.deactivate = function(event) { stop listening for timeline entry taps */ this.unbindTimelineEntryTaps('#favorites-timeline'); - + this.controller.stopListening("favorites-timeline", Mojo.Event.listTap, this.handleTimelineTap); /* unbind and stop refresher for public timeline */ diff --git a/app/assistants/my-timeline-assistant.js b/app/assistants/my-timeline-assistant.js index 9721357..4ab94d2 100644 --- a/app/assistants/my-timeline-assistant.js +++ b/app/assistants/my-timeline-assistant.js @@ -53,6 +53,8 @@ function MyTimelineAssistant(argFromPusher) { MyTimelineAssistant.prototype.setup = function() { sch.debug('SETUP'); + this.timelineModel = {items: []}; + this.controller.setupWidget("my-timeline", {itemTemplate: "shared/tweet", hasNoWidgets: true, lookahead: 20, renderLimit: 20}, this.timelineModel); var thisA = this; @@ -179,6 +181,7 @@ MyTimelineAssistant.prototype.deactivate = function(event) { stop listening for timeline entry taps */ this.unbindTimelineEntryTaps('#my-timeline'); + this.controller.stopListening("my-timeline", Mojo.Event.listTap, this.handleTimelineTap); @@ -220,10 +223,6 @@ MyTimelineAssistant.prototype.cleanup = function(event) { MyTimelineAssistant.prototype.initTimeline = function() { sch.debug('initializing Timeline in assistant'); - // TODO: Timeline list widget - this.timelineModel = {items: []}; - this.controller.setupWidget("my-timeline", {itemTemplate: "shared/tweet", hasNoWidgets: true, lookahead: 20, renderLimit: 20}, this.timelineModel); - var thisA = this; /* set up the combined "my" timeline @@ -272,26 +271,7 @@ MyTimelineAssistant.prototype.initTimeline = function() { // TODO: Timeline list widget // remove invalid data, massage into format that works for view interpolation, sort - sc.app.Tweets.bucket.all(function(tweets) { - thisA.timelineModel.items = tweets.select(function(tweet) { - if(tweet.id && tweet.user) - return true; - else - return false; - }). - map(function(tweet){ - tweet.status = null; - tweet.status = tweet.not_new ? "" : "new"; - tweet.status += tweet.SC_is_reply ? " reply" : ""; - tweet.protected_icon = tweet.user["protected"] ? "protected-icon" : ""; - tweet.relative_time = sch.getRelativeTime(tweet.created_at); - return tweet; - }). - sort(function(a, b) { - return b.SC_created_at_unixtime - a.SC_created_at_unixtime; - }); - thisA.controller.modelChanged(thisA.timelineModel); - }); + thisA.renderTimeline(); /* sort timeline diff --git a/app/helpers/scene.js b/app/helpers/scene.js index 38b7a9d..7e6a650 100644 --- a/app/helpers/scene.js +++ b/app/helpers/scene.js @@ -239,33 +239,80 @@ scene_helpers.addCommonSceneMethods = function(assistant) { assistant.filterTimeline = function(command) { if (!command) { - command = this.filterState; + command = this.filterState || "filter-timeline-all"; } switch (command) { case 'filter-timeline-all': - jQuery('#my-timeline div.timeline-entry').show(); + this.renderTimeline(true); break; case 'filter-timeline-replies-dm': - jQuery('#my-timeline div.timeline-entry').hide(); - jQuery('#my-timeline div.timeline-entry.reply, #my-timeline div.timeline-entry.dm').show(); + this.timelineModel.items = this.timelineModel.items.filter(function(tweet) { + if(tweet.SC_is_reply || tweet.SC_is_dm) + return true; + else + return false; + }); break; case 'filter-timeline-replies': - jQuery('#my-timeline div.timeline-entry').hide(); - jQuery('#my-timeline div.timeline-entry.reply').show(); + this.timelineModel.items = this.timelineModel.items.filter(function(tweet) { + if(tweet.SC_is_reply) + return true; + else + return false; + }); break; case 'filter-timeline-dms': - jQuery('#my-timeline div.timeline-entry').hide(); - jQuery('#my-timeline div.timeline-entry.dm').show(); + this.timelineModel.items = this.timelineModel.items.filter(function(tweet) { + if(tweet.SC_is_dm) + return true; + else + return false; + }); break; - default: - jQuery('#my-timeline div.timeline-entry').show(); + case "favorites": + this.timelineModel.items = this.timelineModel.items.filter(function(tweet) { + if(tweet.favorited) + return true; + else + return false; + }); + break; } this.filterState = command; + this.controller.modelChanged(this.timelineModel); + this.scrollToTop(); }; - + assistant.renderTimeline = function(skipFilter) { + var thisA = this; + sc.app.Tweets.bucket.all(function(tweets) { + thisA.timelineModel.items = tweets.select(function(tweet) { + if(tweet.id && tweet.user) + return true; + else + return false; + }). + map(function(tweet){ + tweet.status = null; + tweet.status = tweet.not_new ? "" : "new"; + tweet.status += tweet.SC_is_reply ? " reply" : ""; + tweet.protected_icon = tweet.user["protected"] ? "protected-icon" : ""; + tweet.relative_time = sch.getRelativeTime(tweet.created_at); + return tweet; + }). + sort(function(a, b) { + return b.SC_created_at_unixtime - a.SC_created_at_unixtime; + }); + if(skipFilter) { + thisA.controller.modelChanged(thisA.timelineModel); + thisA.scrollToTop(); + } + else + thisA.filterTimeline(); + }); + }; assistant.setTimelineTextSize = function(tl_id, size) { size = size.toLowerCase(); diff --git a/app/views/favorites/favorites-scene.html b/app/views/favorites/favorites-scene.html index e9f9ae0..8067b71 100644 --- a/app/views/favorites/favorites-scene.html +++ b/app/views/favorites/favorites-scene.html @@ -18,5 +18,5 @@ -
+
\ No newline at end of file diff --git a/app/views/startsearch/startsearch-scene.html b/app/views/startsearch/startsearch-scene.html index 03887dd..3d2a5e4 100644 --- a/app/views/startsearch/startsearch-scene.html +++ b/app/views/startsearch/startsearch-scene.html @@ -29,7 +29,6 @@
-
Search