mirror of
https://github.com/vercel/commerce.git
synced 2025-06-30 10:21:22 +00:00
Changes
This commit is contained in:
parent
7bf4978ac8
commit
cbff49b91e
@ -1,17 +1,17 @@
|
|||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { getRandomPairOfColors } from '@lib/colors'
|
|
||||||
import { useUI } from '@components/ui/context'
|
import { useUI } from '@components/ui/context'
|
||||||
|
import { getRandomPairOfColors } from '@lib/colors'
|
||||||
|
|
||||||
export const useUserAvatar = (name = 'userAvatar') => {
|
export const useUserAvatar = (name = 'userAvatar') => {
|
||||||
const { userAvatar, setUserAvatar } = useUI()
|
const { userAvatar, setUserAvatar } = useUI()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!userAvatar && localStorage.getItem(name)) {
|
if (!userAvatar && localStorage.getItem(name)) {
|
||||||
// get bg value locally.
|
// Get bg from localStorage and push it to the context.
|
||||||
setUserAvatar(localStorage.getItem(name))
|
setUserAvatar(localStorage.getItem(name))
|
||||||
}
|
}
|
||||||
if (!localStorage.getItem(name)) {
|
if (!localStorage.getItem(name)) {
|
||||||
// local not set, set.
|
// bg not set locally, generating one, setting localStorage and context to persist.
|
||||||
const bg = getRandomPairOfColors()
|
const bg = getRandomPairOfColors()
|
||||||
const value = `linear-gradient(140deg, ${bg[0]}, ${bg[1]} 100%)`
|
const value = `linear-gradient(140deg, ${bg[0]}, ${bg[1]} 100%)`
|
||||||
localStorage.setItem(name, value)
|
localStorage.setItem(name, value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user