feat: format with prettier

This commit is contained in:
swve 2024-02-09 21:22:15 +01:00
parent 03fb09c3d6
commit a147ad6610
164 changed files with 11257 additions and 8154 deletions

View file

@ -1,76 +1,74 @@
'use client';
import { AIMessage } from '@components/Objects/Activities/AI/AIActivityAsk';
'use client'
import { AIMessage } from '@components/Objects/Activities/AI/AIActivityAsk'
import React, { createContext, useContext, useReducer } from 'react'
export const AIChatBotContext = createContext(null) as any;
export const AIChatBotDispatchContext = createContext(null) as any;
export const AIChatBotContext = createContext(null) as any
export const AIChatBotDispatchContext = createContext(null) as any
export type AIChatBotStateTypes = {
messages: AIMessage[],
isModalOpen: boolean,
aichat_uuid: string,
isWaitingForResponse: boolean,
chatInputValue: string
error: AIError
messages: AIMessage[]
isModalOpen: boolean
aichat_uuid: string
isWaitingForResponse: boolean
chatInputValue: string
error: AIError
}
type AIError = {
isError: boolean
status: number
error_message: string
isError: boolean
status: number
error_message: string
}
function AIChatBotProvider({ children }: { children: React.ReactNode }) {
const [aiChatBotState, dispatchAIChatBot] = useReducer(aiChatBotReducer,
{
messages: [] as AIMessage[],
isModalOpen: false,
aichat_uuid: null,
isWaitingForResponse: false,
chatInputValue: '',
error: { isError: false, status: 0, error_message: ' ' } as AIError
}
);
return (
<AIChatBotContext.Provider value={aiChatBotState}>
<AIChatBotDispatchContext.Provider value={dispatchAIChatBot}>
{children}
</AIChatBotDispatchContext.Provider>
</AIChatBotContext.Provider>
)
const [aiChatBotState, dispatchAIChatBot] = useReducer(aiChatBotReducer, {
messages: [] as AIMessage[],
isModalOpen: false,
aichat_uuid: null,
isWaitingForResponse: false,
chatInputValue: '',
error: { isError: false, status: 0, error_message: ' ' } as AIError,
})
return (
<AIChatBotContext.Provider value={aiChatBotState}>
<AIChatBotDispatchContext.Provider value={dispatchAIChatBot}>
{children}
</AIChatBotDispatchContext.Provider>
</AIChatBotContext.Provider>
)
}
export default AIChatBotProvider
export function useAIChatBot() {
return useContext(AIChatBotContext);
return useContext(AIChatBotContext)
}
export function useAIChatBotDispatch() {
return useContext(AIChatBotDispatchContext);
return useContext(AIChatBotDispatchContext)
}
function aiChatBotReducer(state: any, action: any) {
switch (action.type) {
case 'setMessages':
return { ...state, messages: action.payload };
case 'addMessage':
return { ...state, messages: [...state.messages, action.payload] };
case 'setIsModalOpen':
return { ...state, isModalOpen: true };
case 'setIsModalClose':
return { ...state, isModalOpen: false };
case 'setAichat_uuid':
return { ...state, aichat_uuid: action.payload };
case 'setIsWaitingForResponse':
return { ...state, isWaitingForResponse: true };
case 'setIsNoLongerWaitingForResponse':
return { ...state, isWaitingForResponse: false };
case 'setChatInputValue':
return { ...state, chatInputValue: action.payload };
case 'setError':
return { ...state, error: action.payload };
switch (action.type) {
case 'setMessages':
return { ...state, messages: action.payload }
case 'addMessage':
return { ...state, messages: [...state.messages, action.payload] }
case 'setIsModalOpen':
return { ...state, isModalOpen: true }
case 'setIsModalClose':
return { ...state, isModalOpen: false }
case 'setAichat_uuid':
return { ...state, aichat_uuid: action.payload }
case 'setIsWaitingForResponse':
return { ...state, isWaitingForResponse: true }
case 'setIsNoLongerWaitingForResponse':
return { ...state, isWaitingForResponse: false }
case 'setChatInputValue':
return { ...state, chatInputValue: action.payload }
case 'setError':
return { ...state, error: action.payload }
default:
throw new Error(`Unhandled action type: ${action.type}`)
}
}
default:
throw new Error(`Unhandled action type: ${action.type}`)
}
}