import { createSlice } from '@reduxjs/toolkit'
import { PayloadAction } from '@reduxjs/toolkit'

export interface Hot {
  id: string,
  pos: { x: number, y: number, z: number }
  title: string,
  content?: string
  meta: {
    type: string,
    url: string
  }
  link?: string
}

export type Hots = Hot[]

const initialState: Hots = []

const hotsSlice = createSlice({
  initialState,
  name: 'posts',
  reducers: {
    hotAdded(state, action: PayloadAction<Hot>) {
      console.log('push', action.payload)
      state.push(action.payload)
    }
  }
})

export const hotsReducer = hotsSlice.reducer

export const { 
  hotAdded 
} = hotsSlice.actions