Skip to content

Commit

Permalink
Fix initial colors
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgrozer committed Jun 30, 2024
1 parent ae0e123 commit 2112f3c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions components/Colors.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ const reorder = (list, startIndex, endIndex) => {
return result
}

export default ({ colors: urlColors }) => {
export default ({ urlColors }) => {
const { state, setState } = useAppContext()
const { colors, cookiesLoaded } = state
const { colors, cookiesLoaded, initialColorsUpdated } = state

useEffect(() => {
if (!cookiesLoaded) return
if (colors.length) return
const initialColors = urlColors.length
? urlColors.map((color) => `#${color}`)
: niceColors[Math.floor(Math.random() * niceColors.length)]
setState({ colors: initialColors })
}, [colors, urlColors, cookiesLoaded])
if (initialColorsUpdated) return

if (urlColors.length) {
const newColors = urlColors.map((color) => `#${color}`)
setState({ colors: newColors, initialColorsUpdated: true })
} else if (colors.length) {
setState({ initialColorsUpdated: true })
} else {
const newColors = niceColors[Math.floor(Math.random() * niceColors.length)]
setState({ colors: newColors, initialColorsUpdated: true })
}
}, [urlColors, cookiesLoaded, initialColorsUpdated])

const [displayColorPicker, setDisplayColorPicker] = useState({})

Expand Down

0 comments on commit 2112f3c

Please sign in to comment.