{"size": 1463, "ext": "js", "max_stars_repo_path": "client/src/utils/anySlice.js", "max_stars_repo_name": "JichenZhang/AvidReaders", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/utils/anySlice.js", "max_issues_repo_name": "JichenZhang/AvidReaders", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "client/src/utils/anySlice.js", "max_forks_repo_name": "JichenZhang/AvidReaders", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.224137931, "max_line_length": 63, "alphanum_fraction": 0.4743677375}
/**
 * An redux slicce
 */
import { createSlice } from '@reduxjs/toolkit'

export const anySlice = createSlice({
    name: 'any',
    initialState: {
        User_ID: null,
        User_Name: null,
        wishlist: [] // list of Book_IDs
    },
    reducers: {
        setUserID: (state, action) => ({
            ...state,
            User_ID: action.payload
        }),
        setUserName: (state, action) => ({
            ...state,
            User_Name: action.payload
        }),
        initWishlist: (state, action) => ({
            ...state,
            wishlist: action.payload
        }),
        removeFromWishlist: (state, action) => {
            debugger
            let newlist = [...state.wishlist]
            newlist = newlist.filter(x => x !== action.payload)
            return {
                ...state,
                wishlist: newlist
            }
        },
        addToWishlist: (state, action) => {
            let newlist = [...state.wishlist]
            newlist.push(action.payload)
            return {
                ...state,
                wishlist: newlist
            }
        },
        updateWishlist: (state, action) => {
            return {
                ...state,
                wishlist: new Array(...action.payload)
            }
        }
    }
})

export const { setUserID,
    setUserName,
    initWishlist,
    removeFromWishlist,
    addToWishlist } = anySlice.actions

export default anySlice.reducer