Enhance market module with new chat and events features
- Introduce chat module with components, services, and composables for real-time messaging. - Implement events module with API service, components, and ticket purchasing functionality. - Update app configuration to include new modules and their respective settings. - Refactor existing components to integrate with the new chat and events features. - Enhance market store and services to support new functionalities and improve order management. - Update routing to accommodate new views for chat and events, ensuring seamless navigation.
This commit is contained in:
parent
519a9003d4
commit
e40ac91417
46 changed files with 6305 additions and 3264 deletions
82
src/modules/chat/composables/useChat.ts
Normal file
82
src/modules/chat/composables/useChat.ts
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
import { ref, computed } from 'vue'
|
||||
import { injectService } from '@/core/di-container'
|
||||
import type { ChatService } from '../services/chat-service'
|
||||
import type { ChatPeer } from '../types'
|
||||
|
||||
// Service token for chat service
|
||||
export const CHAT_SERVICE_TOKEN = Symbol('chatService')
|
||||
|
||||
export function useChat() {
|
||||
const chatService = injectService<ChatService>(CHAT_SERVICE_TOKEN)
|
||||
|
||||
if (!chatService) {
|
||||
throw new Error('ChatService not available. Make sure chat module is installed.')
|
||||
}
|
||||
|
||||
const selectedPeer = ref<string | null>(null)
|
||||
const isLoading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
// Computed properties
|
||||
const peers = computed(() => chatService.allPeers.value)
|
||||
const totalUnreadCount = computed(() => chatService.totalUnreadCount.value)
|
||||
|
||||
const currentMessages = computed(() => {
|
||||
return selectedPeer.value ? chatService.getMessages(selectedPeer.value) : []
|
||||
})
|
||||
|
||||
const currentPeer = computed(() => {
|
||||
return selectedPeer.value ? chatService.getPeer(selectedPeer.value) : undefined
|
||||
})
|
||||
|
||||
// Methods
|
||||
const selectPeer = (peerPubkey: string) => {
|
||||
selectedPeer.value = peerPubkey
|
||||
chatService.markAsRead(peerPubkey)
|
||||
}
|
||||
|
||||
const sendMessage = async (content: string) => {
|
||||
if (!selectedPeer.value || !content.trim()) {
|
||||
return
|
||||
}
|
||||
|
||||
isLoading.value = true
|
||||
error.value = null
|
||||
|
||||
try {
|
||||
await chatService.sendMessage(selectedPeer.value, content.trim())
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : 'Failed to send message'
|
||||
console.error('Send message error:', err)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const addPeer = (pubkey: string, name?: string): ChatPeer => {
|
||||
return chatService.addPeer(pubkey, name)
|
||||
}
|
||||
|
||||
const markAsRead = (peerPubkey: string) => {
|
||||
chatService.markAsRead(peerPubkey)
|
||||
}
|
||||
|
||||
return {
|
||||
// State
|
||||
selectedPeer,
|
||||
isLoading,
|
||||
error,
|
||||
|
||||
// Computed
|
||||
peers,
|
||||
totalUnreadCount,
|
||||
currentMessages,
|
||||
currentPeer,
|
||||
|
||||
// Methods
|
||||
selectPeer,
|
||||
sendMessage,
|
||||
addPeer,
|
||||
markAsRead
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue