From ff8e92df6c46586e160c01640eb4d885856b83eb Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 14 Apr 2018 10:47:53 -0700 Subject: [PATCH] preload content in CW (#110) * preload content in CW Fixes #63 * fix test --- routes/_components/status/Status.html | 15 ++++++++++++--- routes/_components/status/StatusContent.html | 19 +++++++++++++++---- tests/spec/110-compose-content-warnings.js | 5 +++-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/routes/_components/status/Status.html b/routes/_components/status/Status.html index af79266..8bfaba6 100644 --- a/routes/_components/status/Status.html +++ b/routes/_components/status/Status.html @@ -23,9 +23,9 @@ :originalStatus :uuid :spoilerShown on:recalculateHeight /> {{/if}} - {{#if !spoilerText || spoilerShown}} + {{#if showContent || contentPreloaded}} + :originalStatus :uuid shown="{{showContent}}"/> {{/if}} {{#if originalStatus.media_attachments && originalStatus.media_attachments.length}} INPUT_TAGS.has(node.localName) @@ -127,6 +128,13 @@ // the whole
is clickable in this case registerClickDelegate(delegateKey, (e) => this.onClickOrKeydown(e)) } + if (!this.get('showContent')) { + scheduleIdleTask(() => { + // Perf optimization: lazily load the StatusContent when the user is idle so that + // it's fast when they click the "show more" button + this.set({contentPreloaded: true}) + }) + } }, ondestroy() { let delegateKey = this.get('delegateKey') @@ -214,7 +222,8 @@ timelineType !== 'search' && 'status-in-timeline', isStatusInOwnThread && 'status-in-own-thread' ) - } + }, + showContent: (spoilerText, spoilerShown) => !spoilerText || spoilerShown } } \ No newline at end of file diff --git a/routes/_components/status/StatusContent.html b/routes/_components/status/StatusContent.html index 34a3140..15c12b1 100644 --- a/routes/_components/status/StatusContent.html +++ b/routes/_components/status/StatusContent.html @@ -1,7 +1,4 @@ -
+
{{{massagedContent}}}