import { createSlice , PayloadAction } from "@reduxjs/toolkit" ; import { QuickChatOption } from "@creature-chess/models" ; export type QuickChat = { [ id ] : { value : QuickChatOption ; receivedAt : number ; } ; } ; export type QuickChatAction = { sendingPlayerId : string ; chatValue : QuickChatOption ; } ; export type ClearQuickChatAction = { sendingPlayerId : string ; } ; const initialState = { } ; export const { reducer , actions : commands } = createSlice ( { name : "quickChat" , initialState , reducers : { setPlayerChat : ( state , { payload : { sendingPlayerId , chatValue } } ) => ( { ... state , [ sendingPlayerId ] : { value : chatValue , receivedAt : Date . now ( ) } } ) , clearPlayerChat : ( state , { payload : { sendingPlayerId } } ) => { const newState = { ... state } ; delete newState [ sendingPlayerId ] ; return newState ; } } } ) ;