From f7b933815e591e3f4fdb67623bb1d1070bcf3050 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 4 Feb 2018 12:27:28 -0800 Subject: [PATCH] fix contextual toggling of spoilers/sensitives --- routes/_components/status/Status.html | 7 ++++--- .../_components/status/StatusMediaAttachments.html | 13 +++---------- routes/_components/status/StatusSpoiler.html | 12 ++++-------- routes/_store/store.js | 4 +++- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/routes/_components/status/Status.html b/routes/_components/status/Status.html index ebe7639..a7e225b 100644 --- a/routes/_components/status/Status.html +++ b/routes/_components/status/Status.html @@ -8,13 +8,13 @@ {{#if originalStatus.spoiler_text}} - + {{/if}} {{#if !originalStatus.spoiler_text || spoilerShown}} {{/if}} {{#if originalStatus.media_attachments && originalStatus.media_attachments.length}} - + {{/if}} @@ -72,9 +72,10 @@ computed: { originalStatus: (status) => status.reblog ? status.reblog : status, statusId: (originalStatus) => originalStatus.id, + contextualStatusId: ($currentInstance, timelineType, timelineValue, status) => `${$currentInstance}/${timelineType}/${timelineValue}/${status.id}`, originalAccount: (originalStatus) => originalStatus.account, isStatusInOwnThread: (timelineType, timelineValue, statusId) => timelineType === 'status' && timelineValue === statusId, - spoilerShown: ($spoilersShown, $currentInstance, statusId) => $spoilersShown && $spoilersShown[$currentInstance] && $spoilersShown[$currentInstance][statusId] + spoilerShown: ($spoilersShown, contextualStatusId) => !!$spoilersShown[contextualStatusId] } } \ No newline at end of file diff --git a/routes/_components/status/StatusMediaAttachments.html b/routes/_components/status/StatusMediaAttachments.html index c53074b..7bf468a 100644 --- a/routes/_components/status/StatusMediaAttachments.html +++ b/routes/_components/status/StatusMediaAttachments.html @@ -120,20 +120,13 @@ store: () => store, computed: { mediaAttachments: (status) => status.media_attachments, - sensitiveShown: ($sensitivesShown, $currentInstance, statusId) => { - return $sensitivesShown && $sensitivesShown[$currentInstance] && $sensitivesShown[$currentInstance][statusId] - }, - statusId: (status) => status.id + sensitiveShown: ($sensitivesShown, contextualStatusId) => !!$sensitivesShown[contextualStatusId] }, methods: { onClickSensitiveMediaButton() { - let statusId = this.get('statusId') - let instanceName = this.store.get('currentInstance') + let contextualStatusId = this.get('contextualStatusId') let $sensitivesShown = this.store.get('sensitivesShown') || {} - if (!$sensitivesShown[instanceName]) { - $sensitivesShown[instanceName] = {} - } - $sensitivesShown[instanceName][statusId] = !$sensitivesShown[instanceName][statusId] + $sensitivesShown[contextualStatusId] = !$sensitivesShown[contextualStatusId] this.store.set({'sensitivesShown': $sensitivesShown}) this.fire('recalculateHeight') }, diff --git a/routes/_components/status/StatusSpoiler.html b/routes/_components/status/StatusSpoiler.html index be5fd31..ab47da1 100644 --- a/routes/_components/status/StatusSpoiler.html +++ b/routes/_components/status/StatusSpoiler.html @@ -30,17 +30,13 @@ export default { store: () => store, computed: { - statusId: (status) => status.id + spoilerShown: ($spoilersShown, contextualStatusId) => !!$spoilersShown[contextualStatusId] }, methods: { onClickSpoilerButton() { - let statusId = this.get('statusId') - let instanceName = this.store.get('currentInstance') - let $spoilersShown = this.store.get('spoilersShown') || {} - if (!$spoilersShown[instanceName]) { - $spoilersShown[instanceName] = {} - } - $spoilersShown[instanceName][statusId] = !$spoilersShown[instanceName][statusId] + let contextualStatusId = this.get('contextualStatusId') + let $spoilersShown = this.store.get('spoilersShown') + $spoilersShown[contextualStatusId] = !$spoilersShown[contextualStatusId] this.store.set({'spoilersShown': $spoilersShown}) this.fire('recalculateHeight') } diff --git a/routes/_store/store.js b/routes/_store/store.js index 881e1b3..625f871 100644 --- a/routes/_store/store.js +++ b/routes/_store/store.js @@ -26,7 +26,9 @@ const store = new PinaforeStore({ loggedInInstances: {}, loggedInInstancesInOrder: [], instanceThemes: {}, - autoplayGifs: false + spoilersShown: {}, + sensitivesShown: {}, + autoplayGifs: false, }) mixins(PinaforeStore)