globalColorConfig.js 763 Bytes
Newer Older
Muhammadali's avatar
Muhammadali committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/** @format */

import {create} from 'zustand';



export const useColorConfig = create((set, get) => ({
    state: {},
    getColors: () => {
        const res = localStorage.getItem('boxdialer-style')
        if (!!res) {
            let jsonRes = JSON.parse(res)
            set(() => ({state: jsonRes}))
        }
    },
    setColor: ({name, value}) => {
        const state = get()
        if (!!name) {
            set((state) => ({
                state: {
                    ...state.state,
                    [name]: value
                }
            }))
            state.saveToHistory()
        }
    },
    saveToHistory: () => {
        const state = get()
        localStorage.setItem('boxdialer-style', JSON.stringify(state.state))
    }
}));