fix contextual toggling of spoilers/sensitives

This commit is contained in:
Nolan Lawson 2018-02-04 12:27:28 -08:00
parent 542368fd3d
commit f7b933815e
4 changed files with 14 additions and 22 deletions

View file

@ -8,13 +8,13 @@
<StatusAuthor status="{{originalStatus}}" :isStatusInOwnThread /> <StatusAuthor status="{{originalStatus}}" :isStatusInOwnThread />
<StatusSidebar status="{{originalStatus}}" /> <StatusSidebar status="{{originalStatus}}" />
{{#if originalStatus.spoiler_text}} {{#if originalStatus.spoiler_text}}
<StatusSpoiler status="{{originalStatus}}" :spoilerShown on:recalculateHeight /> <StatusSpoiler status="{{originalStatus}}" :contextualStatusId on:recalculateHeight />
{{/if}} {{/if}}
{{#if !originalStatus.spoiler_text || spoilerShown}} {{#if !originalStatus.spoiler_text || spoilerShown}}
<StatusContent status="{{originalStatus}}" :isStatusInOwnThread /> <StatusContent status="{{originalStatus}}" :isStatusInOwnThread />
{{/if}} {{/if}}
{{#if originalStatus.media_attachments && originalStatus.media_attachments.length}} {{#if originalStatus.media_attachments && originalStatus.media_attachments.length}}
<StatusMediaAttachments status="{{originalStatus}}" on:recalculateHeight /> <StatusMediaAttachments status="{{originalStatus}}" :contextualStatusId on:recalculateHeight />
{{/if}} {{/if}}
<StatusToolbar :status /> <StatusToolbar :status />
</article> </article>
@ -72,9 +72,10 @@
computed: { computed: {
originalStatus: (status) => status.reblog ? status.reblog : status, originalStatus: (status) => status.reblog ? status.reblog : status,
statusId: (originalStatus) => originalStatus.id, statusId: (originalStatus) => originalStatus.id,
contextualStatusId: ($currentInstance, timelineType, timelineValue, status) => `${$currentInstance}/${timelineType}/${timelineValue}/${status.id}`,
originalAccount: (originalStatus) => originalStatus.account, originalAccount: (originalStatus) => originalStatus.account,
isStatusInOwnThread: (timelineType, timelineValue, statusId) => timelineType === 'status' && timelineValue === statusId, isStatusInOwnThread: (timelineType, timelineValue, statusId) => timelineType === 'status' && timelineValue === statusId,
spoilerShown: ($spoilersShown, $currentInstance, statusId) => $spoilersShown && $spoilersShown[$currentInstance] && $spoilersShown[$currentInstance][statusId] spoilerShown: ($spoilersShown, contextualStatusId) => !!$spoilersShown[contextualStatusId]
} }
} }
</script> </script>

View file

@ -120,20 +120,13 @@
store: () => store, store: () => store,
computed: { computed: {
mediaAttachments: (status) => status.media_attachments, mediaAttachments: (status) => status.media_attachments,
sensitiveShown: ($sensitivesShown, $currentInstance, statusId) => { sensitiveShown: ($sensitivesShown, contextualStatusId) => !!$sensitivesShown[contextualStatusId]
return $sensitivesShown && $sensitivesShown[$currentInstance] && $sensitivesShown[$currentInstance][statusId]
},
statusId: (status) => status.id
}, },
methods: { methods: {
onClickSensitiveMediaButton() { onClickSensitiveMediaButton() {
let statusId = this.get('statusId') let contextualStatusId = this.get('contextualStatusId')
let instanceName = this.store.get('currentInstance')
let $sensitivesShown = this.store.get('sensitivesShown') || {} let $sensitivesShown = this.store.get('sensitivesShown') || {}
if (!$sensitivesShown[instanceName]) { $sensitivesShown[contextualStatusId] = !$sensitivesShown[contextualStatusId]
$sensitivesShown[instanceName] = {}
}
$sensitivesShown[instanceName][statusId] = !$sensitivesShown[instanceName][statusId]
this.store.set({'sensitivesShown': $sensitivesShown}) this.store.set({'sensitivesShown': $sensitivesShown})
this.fire('recalculateHeight') this.fire('recalculateHeight')
}, },

View file

@ -30,17 +30,13 @@
export default { export default {
store: () => store, store: () => store,
computed: { computed: {
statusId: (status) => status.id spoilerShown: ($spoilersShown, contextualStatusId) => !!$spoilersShown[contextualStatusId]
}, },
methods: { methods: {
onClickSpoilerButton() { onClickSpoilerButton() {
let statusId = this.get('statusId') let contextualStatusId = this.get('contextualStatusId')
let instanceName = this.store.get('currentInstance') let $spoilersShown = this.store.get('spoilersShown')
let $spoilersShown = this.store.get('spoilersShown') || {} $spoilersShown[contextualStatusId] = !$spoilersShown[contextualStatusId]
if (!$spoilersShown[instanceName]) {
$spoilersShown[instanceName] = {}
}
$spoilersShown[instanceName][statusId] = !$spoilersShown[instanceName][statusId]
this.store.set({'spoilersShown': $spoilersShown}) this.store.set({'spoilersShown': $spoilersShown})
this.fire('recalculateHeight') this.fire('recalculateHeight')
} }

View file

@ -26,7 +26,9 @@ const store = new PinaforeStore({
loggedInInstances: {}, loggedInInstances: {},
loggedInInstancesInOrder: [], loggedInInstancesInOrder: [],
instanceThemes: {}, instanceThemes: {},
autoplayGifs: false spoilersShown: {},
sensitivesShown: {},
autoplayGifs: false,
}) })
mixins(PinaforeStore) mixins(PinaforeStore)