From 407cc851cc3a7ad19d4e7dfc8747ca385c5915d8 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 28 Feb 2011 17:13:54 -0800 Subject: [PATCH] Collapse long threaded displays with a link to the convo view (todo: turn it into an ajax loader for inline expansion) --- lib/threadednoticelist.php | 38 +++++++++++++++++++++++++++----------- theme/base/css/display.css | 4 +++- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/threadednoticelist.php b/lib/threadednoticelist.php index c1c4b4f36a..42b85bd132 100644 --- a/lib/threadednoticelist.php +++ b/lib/threadednoticelist.php @@ -145,6 +145,8 @@ class ThreadedNoticeList extends NoticeList class ThreadedNoticeListItem extends NoticeListItem { + const INITIAL_ITEMS = 3; + /** * finish the notice * @@ -155,24 +157,32 @@ class ThreadedNoticeListItem extends NoticeListItem function showEnd() { - $notice = Notice::conversationStream($this->notice->conversation); + $notice = Notice::conversationStream($this->notice->conversation, 0, self::INITIAL_ITEMS + 2); $notices = array(); + $cnt = 0; + $moreCutoff = null; while ($notice->fetch()) { if ($notice->id == $this->notice->id) { // Skip! continue; } + $cnt++; + if ($cnt > self::INITIAL_ITEMS) { + // boo-yah + $moreCutoff = clone($notice); + break; + } $notices[] = clone($notice); // *grumble* inefficient as hell } if ($notices) { $this->out->elementStart('ul', 'notices threaded-notices xoxo'); - foreach (array_reverse($notices) as $notice) { - $item = new ThreadedNoticeListSubItem($notice, $this->out); + if ($moreCutoff) { + $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out); $item->show(); } - if (common_current_user()) { - $item = new ThreadedNoticeListReplyItem($this->notice, $this->out); + foreach (array_reverse($notices) as $notice) { + $item = new ThreadedNoticeListSubItem($notice, $this->out); $item->show(); } $this->out->elementEnd('ul'); @@ -202,9 +212,9 @@ class ThreadedNoticeListSubItem extends NoticeListItem } /** - * Show a mini inline posting form for replies. + * Placeholder for loading more replies... */ -class ThreadedNoticeListReplyItem extends NoticeListItem +class ThreadedNoticeListMoreItem extends NoticeListItem { /** @@ -233,15 +243,21 @@ class ThreadedNoticeListReplyItem extends NoticeListItem { if (Event::handle('StartOpenNoticeListItemElement', array($this))) { $id = (empty($this->repeat)) ? $this->notice->id : $this->repeat->id; - $this->out->elementStart('li', array('class' => 'notice-reply-placeholder')); + $this->out->elementStart('li', array('class' => 'notice-reply-comments')); } } function showMiniForm() { - $replyToId = $this->notice->id; - $id = 'replyto-notice-' + $replyToId; - $url = common_local_url('newnotice'); + $id = $this->notice->conversation; + $url = common_local_url('conversation', array('id' => $id)) . '#notice-' . $this->notice->id; + + $notice = new Notice(); + $notice->conversation = $id; + $n = $notice->count() - 1; + $msg = sprintf(_m('Show all %d comment', 'Show all %d comments', $n), $n); + + $this->out->element('a', array('href' => $url), $msg); // @fixme replace this with an ajax-friendly form pair? /* diff --git a/theme/base/css/display.css b/theme/base/css/display.css index dabf929a72..98345a0726 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -1133,7 +1133,9 @@ border-top-style:solid; .threaded-notices .notice-reply .controls { text-align: right; } - +.threaded-notices .notice-reply-comments { + margin: 8px; +} /* NOTICES */ #notices_primary { float:left; -- 2.39.5