Skip to content

Commit

Permalink
feat #396 - remove window from localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
mishevong committed Jul 21, 2021
1 parent ec583c4 commit 73c15b6
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/components/Plausible/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@ const useStyles = createUseStyles({
})

export const Plausible: FC = () => {
const [isExcluded, setIsExcluded] = useState(
window.localStorage.plausible_ignore
)
const [isExcluded, setIsExcluded] = useState(localStorage.plausible_ignore)
const classes = useStyles({ isExcluded })

const toggleExclusion = () => {
const exclusionState = window.localStorage.plausible_ignore === 'true'
const exclusionState = localStorage.plausible_ignore === 'true'

if (exclusionState) {
setIsExcluded(false)
delete window.localStorage.plausible_ignore
delete localStorage.plausible_ignore
} else {
setIsExcluded(true)
window.localStorage.plausible_ignore = 'true'
localStorage.plausible_ignore = 'true'
}
}

Expand All @@ -80,7 +78,7 @@ export const Plausible: FC = () => {
excluding your visits.
</div>
</div>
<Button classes={[classes.btn]} onClick={() => toggleExclusion()}>
<Button classes={[classes.btn]} onClick={toggleExclusion}>
{isExcluded ? 'Stop excluding my visits' : 'Exclude my visits'}
</Button>
</div>
Expand Down

0 comments on commit 73c15b6

Please sign in to comment.