Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

making user's homepage show posts (but user can't create them just yet)

  • Loading branch information...
commit 31785e372749148156b30fab3580d443f49a649d 1 parent e03bb40
@garu authored
Showing with 17 additions and 2 deletions.
  1. +17 −2 tweetylicious.pl
View
19 tweetylicious.pl
@@ -152,9 +152,14 @@ package main;
return $self->render('not_found')
unless Model::User->count('WHERE username = ?', $user);
+ # fetch posts by user
+ my $posts = Model::fetch_posts_by($user);
+
# fill our stash with information for the template
$self->stash(
- user => Model::User->load( $user ),
+ user => Model::User->load( $user ),
+ posts => $posts || [],
+ total_posts => Model::Post->count('WHERE username = ?', $user),
);
} => 'homepage';
@@ -198,6 +203,7 @@ package main;
@@ homepage.html.ep
% layout 'main';
+% use Mojo::ByteStream 'b';
<div id="content" class="half ui-corner-left">
% if (session('name') and session('name') eq $user->{username}) {
<h2>Hi, <%= session 'name' %>!</h2>
@@ -210,7 +216,15 @@ package main;
<h2 id="title"><%= $user->{username} %>'s posts</h2>
% }
<ul class="messages">
-%# here we'll render all the posts in the page (later)
+%# now we render all the posts in the page
+% foreach my $post ( @$posts ) {
+ <li class="ui-corner-all">
+%# the author of the post can delete it
+% if ($post->{username} eq session('name') ) {
+ <a href="/<%= $post->{username} %>/post/<%= $post->{id} %>/delete" class="ui-icon ui-icon-trash" title="delete this post"></a>
+% }
+ <a class="who" href="/<%= $post->{username} %>"><img src="http://www.gravatar.com/avatar/<%= $post->{gravatar} %>?s=60.jpg" /><%= $post->{username} %></a><span class="what"><%= b($post->{content})->decode('UTF-8')->to_string %></span><span class="when"><%= $post->{date} %></span></li>
+% }
</ul>
</div>
<div id="sub-section" class="ui-corner-right">
@@ -218,6 +232,7 @@ package main;
<li><span>Name</span><%= $user->{username} %></li>
<li><span>Bio</span><%= $user->{bio} %></li>
</ul>
+ <div id="totalposts"><span><%= $total_posts %></span> Posts</div>
</div>
@@ login.html.ep
Please sign in to comment.
Something went wrong with that request. Please try again.