|
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; |
|
import { v4 as uuidv4 } from "uuid"; |
|
|
|
interface SessionState { |
|
sessionId: string; |
|
thinking: boolean; |
|
transcribing: boolean; |
|
connected: boolean; |
|
} |
|
|
|
const initialState: SessionState = { |
|
sessionId: localStorage.getItem("voiceSessionId") || uuidv4(), |
|
thinking: false, |
|
transcribing: false, |
|
connected: false, |
|
}; |
|
|
|
export const sessionSlice = createSlice({ |
|
name: "session", |
|
initialState, |
|
reducers: { |
|
setSessionId: (state, action: PayloadAction<string>) => { |
|
state.sessionId = action.payload; |
|
}, |
|
resetSessionId: (state, action) => { |
|
state.sessionId = action.payload; |
|
}, |
|
setTranscribing: (state, action) => { |
|
state.transcribing = action.payload; |
|
}, |
|
setConnected: (state, action) => { |
|
state.connected = action.payload; |
|
}, |
|
setThinking: (state, action) => { |
|
state.thinking = action.payload; |
|
state.transcribing = false; |
|
}, |
|
}, |
|
}); |
|
|
|
export const { setSessionId, resetSessionId, setTranscribing, setThinking , setConnected } = |
|
sessionSlice.actions; |
|
|
|
export default sessionSlice.reducer; |
|
|