@@ -2,8 +2,8 @@ import React, { useState, useRef, useLayoutEffect } from "react"
22import { Global } from "@emotion/core"
33import { Box , Flex } from "theme-ui"
44import { Sidenav , Pagination } from "@theme-ui/sidenav"
5+ import { useAuth } from "react-use-auth"
56import {
6- EditLink ,
77 Footer ,
88 Head ,
99 Header ,
@@ -15,16 +15,17 @@ import QuickThanks from "../../../components/quickthanks"
1515
1616const Paywall = ( { page } ) => {
1717 const copyDiv = useRef ( null )
18+ const { isAuthorized } = useAuth ( )
1819
19- const updateLockedContent = ( ) => {
20+ const updateLockedContent = ( show ) => {
2021 if ( typeof window !== "undefined" ) {
2122 let children = document . getElementById ( "content" ) . children
2223
2324 let isLocked = false
2425 for ( let child of children ) {
2526 if ( child . id === "lock" ) isLocked = true
2627 if ( isLocked === true ) {
27- child . style . display = "none"
28+ child . style . display = show ? "block" : "none"
2829 }
2930 }
3031 }
@@ -33,13 +34,26 @@ const Paywall = ({ page }) => {
3334 useLayoutEffect ( ( ) => {
3435 if ( typeof window !== "undefined" ) {
3536 window . requestAnimationFrame ( ( ) => {
36- if (
37- window . localStorage . getItem ( "unlock_handbook" ) &&
38- window . localStorage . getItem ( "sale_id" )
39- ) {
37+ const unlocked =
38+ isAuthorized ( [ "ServerlessHandbook" ] ) ||
39+ ( window . localStorage . getItem ( "unlock_handbook" ) &&
40+ window . localStorage . getItem ( "sale_id" ) )
41+
42+ console . log ( copyDiv )
43+
44+ if ( unlocked ) {
4045 copyDiv . current . style = `display: none`
46+ const overlay =
47+ typeof window !== "undefined" &&
48+ document . querySelector ( "#fadeout-overlay" )
49+
50+ if ( overlay ) {
51+ overlay . style = "display: none"
52+ }
53+
54+ updateLockedContent ( unlocked )
4155 } else {
42- updateLockedContent ( )
56+ updateLockedContent ( unlocked )
4357
4458 const overlay =
4559 typeof window !== "undefined" && document . createElement ( "div" )
@@ -55,6 +69,7 @@ const Paywall = ({ page }) => {
5569 position: absolute;
5670 `
5771 overlay . style = style
72+ overlay . id = "fadeout-overlay"
5873
5974 main . style = "position: relative;"
6075 main . appendChild ( overlay )
@@ -69,7 +84,7 @@ const Paywall = ({ page }) => {
6984 }
7085 } )
7186 }
72- } , [ page ] )
87+ } , [ page , isAuthorized ( "ServerlessHandbook" ) ] )
7388
7489 return (
7590 < Box id = "paywall-copy" ref = { copyDiv } >
0 commit comments