mirror of
https://github.com/ArthurDanjou/artchat.git
synced 2026-01-27 01:54:09 +01:00
refactor: update ESLint configuration and remove unused dependencies
- Replaced Nuxt ESLint configuration with Antfu's ESLint config. - Removed 'nuxt-visitors' module from Nuxt configuration. - Added linting scripts to package.json for easier code quality checks. - Introduced a new API endpoint for fetching weather data from OpenWeather. - Enhanced chat types with new enums and properties for better state management. - Added OpenWeather response types for improved type safety. - Updated social links in types/index.ts to include an email contact.
This commit is contained in:
@@ -1,17 +1,50 @@
|
||||
import type { ChatMessage } from '~~/types'
|
||||
import type { ChatMessage, ChatType } from '~~/types'
|
||||
import { ChatFetchState, ChatSender, ChatState } from '~~/types'
|
||||
|
||||
export const useChatStore = defineStore('chat', () => {
|
||||
const messages = ref<ChatMessage[]>([])
|
||||
let id = 0
|
||||
|
||||
function addMessage(message: ChatMessage) {
|
||||
messages.value.push({ ...message, id: id++ })
|
||||
const canSend = computed(() => {
|
||||
return !messages.value.some(msg => msg.state === ChatState.LOADING)
|
||||
})
|
||||
|
||||
function addMessage(type: ChatType, content: string, sender: ChatSender, fetchStates: ChatFetchState[]) {
|
||||
if (sender === ChatSender.ARTHUR) {
|
||||
const message: ChatMessage = {
|
||||
id: id++,
|
||||
type,
|
||||
content: null,
|
||||
sender,
|
||||
state: ChatState.LOADING,
|
||||
fetchStates: [...fetchStates, ChatFetchState.DONE],
|
||||
}
|
||||
|
||||
messages.value.push(message)
|
||||
}
|
||||
else {
|
||||
messages.value.push({
|
||||
id: id++,
|
||||
type,
|
||||
content,
|
||||
sender,
|
||||
state: ChatState.SENT,
|
||||
fetchStates: [ChatFetchState.DONE],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function clearMessages() {
|
||||
messages.value = []
|
||||
messages.value.splice(0, messages.value.length)
|
||||
id = 0
|
||||
}
|
||||
|
||||
return { messages, addMessage, clearMessages }
|
||||
function setLoadingState(messageId: number, loadingState: ChatState) {
|
||||
const message = messages.value.find(msg => msg.id === messageId)
|
||||
if (message) {
|
||||
message.state = loadingState
|
||||
}
|
||||
}
|
||||
|
||||
return { messages, addMessage, clearMessages, canSend, setLoadingState }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user