Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Add updateMainTimeline
Browse files Browse the repository at this point in the history
  • Loading branch information
kana committed Nov 3, 2011
1 parent 906ad02 commit 481ee9e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
55 changes: 55 additions & 0 deletions public/javascripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,61 @@
});
};

var mainTimelineSinceId = '1';
var updateMainTimeline = function () {
var indicateRequestingStatus = function () {
$('#main-column').twipsy('show');
};
var restoreRequestingStatus = function () {
$('#main-column').twipsy('hide');
};
indicateRequestingStatus();
callTwitterApi(
'/api/1/statuses/user_timeline.json',
'GET',
{
since_id: mainTimelineSinceId,
count: '20'
},
function (data) {
var tweetTable = {};
$.each(data, function (_, tweet) {
tweetTable[tweet.id_str] = tweet;
});
var ids = $.map(data, function (tweet) {return tweet.id_str;});
ids.sort();
if (1 <= ids.length)
mainTimelineSinceId = ids[ids.length - 1];
$.each(ids, function (_, id) {
var tweet = tweetTable[id];
var d = {
screenName: tweet.user.screen_name,
text: tweet.text,
postedAt: tweet.created_at,
id: tweet.id_str
};
$('#main-column .tweets').prepend(
$(
$('#tweet-template').html().replace(
/{{([^{}]+)}}/g,
function (_, key) {
return d[key];
}
)
).addClass('mine')
);
});
},
function (data) {
// FIXME: Alert gracefully.
alert(data.error);
},
function () {
restoreRequestingStatus();
}
);
};

$(document).ready(function () {
$('#columns .tweets').empty(); // Remove dummy content.

Expand Down
9 changes: 8 additions & 1 deletion views/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
.row#columns
.span16
.row
.span8
#main-column.column.span8(data-twipsy='enabled' data-title='Fetching new tweets...' data-trigger='manual')
%h2 Main
.tweets
-# Tweet {{{
Expand Down Expand Up @@ -197,5 +197,12 @@
%a(href='https://github.com/kana/ddh0313/issues')
Report issues

#internal.hide
#tweet-template
.tweet
%a.screen_name(href='http://twitter.com/{{screenName}}') {{screenName}}
%span.text {{text}}
%a.posted_at(href='http://twitter.com/{{screenName}}/statuses/{{id}}') {{postedAt}}

-# __END__
-# vim: foldmethod=marker

0 comments on commit 481ee9e

Please sign in to comment.