Skip to content

Commit

Permalink
Add experimental mode cookie in SRC
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanmills committed May 10, 2021
1 parent e48abb8 commit 055c46c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/containers/ExperimentalMode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```jsx

<ExperimentalMode />

```
37 changes: 37 additions & 0 deletions src/lib/containers/ExperimentalMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as React from 'react'
import { Button } from 'react-bootstrap'
import { useEffect, useState } from 'react'

const ExperimentalMode: React.FC = () => {
const [isExperimentalModeOn, setIsExperimentalModeOn] = useState<boolean>(false)
let mounted = true

useEffect(() => {
if (mounted) {
if (document.cookie.indexOf("SynapseTestWebsite") !== -1) {
setIsExperimentalModeOn(true)
}
}
return () => {
mounted = false
}
}, [])

const createExperimentalModeCookie = () => {
document.cookie = "SynapseTestWebsite=true"
setIsExperimentalModeOn(true)
}

const deleteExperimentalModeCookie = () => {
document.cookie = "SynapseTestWebsite= ; expires = Thu, 01 Jan 1970 00:00:00 GMT"
setIsExperimentalModeOn(false)
}

return (<>
<Button variant="primary" onClick={isExperimentalModeOn ? deleteExperimentalModeCookie: createExperimentalModeCookie}>
Experimental mode is {isExperimentalModeOn ? "on" : "off"}
</Button>
</>)
}

export default ExperimentalMode
5 changes: 5 additions & 0 deletions styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ module.exports = {
description: 'Content depends on if you are logged in',
components: ['src/lib/containers/**/Login.tsx','src/lib/containers/**/Logout.tsx'],
},
{
name: 'Experimental Mode',
description: 'For components that are in experimental mode',
components: 'src/lib/containers/**/ExperimentalMode.tsx'
},
{
name: 'Home Page',
// content: 'docs/homepage.md'
Expand Down

0 comments on commit 055c46c

Please sign in to comment.