Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-scheurer committed Jun 6, 2024
1 parent 0c16a4c commit 7818d54
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions components/blocks/BlocksView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class="justify-center my-0"
>
<v-col
v-if="!block.hiddenByPaywall"
class="col-auto w-100 px-sm-0"
:class="{
'max-width-520': isBoxed520(block),
Expand Down
17 changes: 17 additions & 0 deletions components/wepPublication/WepPublication.vue
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ export default Vue.extend({
return this.publication?.preTitle
}
return undefined
},
loggedIn (): boolean {
return this.$store.getters['auth/hasAccess']
}
},
watch: {
Expand Down Expand Up @@ -325,6 +328,12 @@ export default Vue.extend({
},
deep: false,
immediate: true
},
loggedIn: {
handler () {
this.removeBlocksForPaywall()
},
deep: true
}
},
async mounted () {
Expand Down Expand Up @@ -370,6 +379,8 @@ export default Vue.extend({
// remove blocks and add fadeout overlay
removeBlocksForPaywall (): void {
if (!this.paywallRulesGiven()) {
// fix from https://wepublish.atlassian.net/browse/HAS-25
this.revealRemovedBlocks()
return
}
const blocks = this.publication.blocks
Expand All @@ -392,6 +403,12 @@ export default Vue.extend({
this.showPaywall = false
}
},
revealRemovedBlocks (): void {
this.publication.blocks?.revealRemovedBlocks()
this.showPaywall = false
// remove articleId param in case logged-in user want's to share the article with non-logged-in users
this.$router.replace(this.$route.path)
},
addPaywallBlock (paywalls: Paywalls): void {
if (!this.paywallRulesGiven()) {
return
Expand Down
5 changes: 4 additions & 1 deletion sdk/wep/models/block/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ export type BlockTypename =

export interface BlockProps {
__typename: BlockTypename
hiddenByPaywall?: boolean
}

export default class Block {
public __typename: BlockTypename
public hiddenByPaywall?: boolean

constructor({__typename}: BlockProps) {
constructor({__typename, hiddenByPaywall}: BlockProps) {
this.__typename = __typename
this.hiddenByPaywall = !!hiddenByPaywall
}
}
12 changes: 9 additions & 3 deletions sdk/wep/models/block/Blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@ export default class Blocks {
}

public removeBlocks(blocksLeft: number): void {
while (this.blocks.length > blocksLeft) {
this.blocks.pop()
}
this.blocks.forEach((block, blockIndex) => {
if (blockIndex >= blocksLeft) {
block.hiddenByPaywall = true
}
})
}

public revealRemovedBlocks (): void {
this.blocks.forEach((block) => block.hiddenByPaywall = false)
}

public getLastBlock(): BlockTypes {
Expand Down

0 comments on commit 7818d54

Please sign in to comment.