Skip to content

Commit

Permalink
Get colors from url parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgrozer committed Jun 30, 2024
1 parent f0c4fab commit e64b463
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/ShareModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default ({ modalIsOpen, closeModal }) => {
.map(color => color.substr(1))
.join('-')

const fullUrl = `${baseUrl}${colorsForUrl}`
const fullUrl = `${baseUrl}?colors=${colorsForUrl}`

return (
<Modal
Expand Down
21 changes: 20 additions & 1 deletion pages/index.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import Head from 'next/head'
import { useRouter } from 'next/router'
import { useState, useEffect } from 'react'

import App from '@components/App'

export default () => {
const router = useRouter()
const [urlColors, setUrlColors] = useState([])
const [isLoading, setIsLoading] = useState(true)

useEffect(() => {
if (router.isReady) {
const { colors } = router.query
if (colors) {
const colorString = Array.isArray(colors) ? colors.join('-') : colors
setUrlColors(colorString.split('-'))
}
setIsLoading(false)
}
}, [router.isReady, router.query])

if (isLoading) return null

return (
<>
<Head>
<title>Colors</title>
</Head>

<App urlColors={[]} />
<App urlColors={urlColors} />
</>
)
}

0 comments on commit e64b463

Please sign in to comment.