{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "realtime-chat-nuxtjs", "title": "Realtime Chat", "description": "Component which provides a realtime chat interface.", "dependencies": [ "@supabase/supabase-js@latest", "lucide-vue-next@latest" ], "registryDependencies": [ "button", "input" ], "files": [ { "path": "registry/default/realtime-chat/nuxtjs/app/components/realtime-chat.vue", "content": "\n\n\n \n \n \n \n No messages yet. Start the conversation!\n \n\n \n \n \n \n \n \n\n \n \n \n\n \n \n \n \n \n\n", "type": "registry:component", "target": "app/components/realtime-chat.vue" }, { "path": "registry/default/realtime-chat/nuxtjs/app/components/chat-message-item.vue", "content": "\n\n\n \n \n \n \n \n {{ message.user.name }}\n \n\n \n {{ formattedTime }}\n \n \n\n \n \n {{ message.content }}\n \n \n \n\n", "type": "registry:component", "target": "app/components/chat-message-item.vue" }, { "path": "registry/default/realtime-chat/nuxtjs/app/composables/useChatScroll.ts", "content": "import { ref } from 'vue'\n\nexport function useChatScroll() {\n const containerRef = ref(null)\n\n function scrollToBottom() {\n if (!containerRef.value) return\n\n const container = containerRef.value\n\n container.scrollTo({\n top: container.scrollHeight,\n behavior: 'smooth',\n })\n }\n\n return {\n containerRef,\n scrollToBottom,\n }\n}\n", "type": "registry:component", "target": "app/composables/useChatScroll.ts" }, { "path": "registry/default/realtime-chat/nuxtjs/app/composables/useRealtimeChat.ts", "content": "import { onUnmounted, ref, watch } from 'vue'\n\n// @ts-ignore\nimport { createClient } from '@/lib/supabase/client'\n\ninterface UseRealtimeChatProps {\n roomName: string\n username: string\n}\n\nexport interface ChatMessage {\n id: string\n content: string\n user: {\n name: string\n }\n createdAt: string\n}\n\nconst EVENT_MESSAGE_TYPE = 'message'\n\nexport function useRealtimeChat(props: UseRealtimeChatProps) {\n const supabase = createClient()\n\n const messages = ref([])\n const channel = ref | null>(null)\n const isConnected = ref(false)\n\n function cleanup() {\n if (channel.value) {\n supabase.removeChannel(channel.value)\n channel.value = null\n }\n }\n\n function setupChannel() {\n if (!props.roomName) return\n\n const newChannel = supabase.channel(props.roomName)\n\n newChannel\n .on('broadcast', { event: EVENT_MESSAGE_TYPE }, (payload: { payload: ChatMessage }) => {\n messages.value.push(payload.payload as ChatMessage)\n })\n .subscribe((status: string) => {\n isConnected.value = status === 'SUBSCRIBED'\n })\n\n channel.value = newChannel\n }\n\n watch(\n () => props.roomName,\n () => {\n cleanup()\n setupChannel()\n },\n { immediate: true }\n )\n\n onUnmounted(() => {\n cleanup()\n })\n\n async function sendMessage(content: string) {\n if (!channel.value || !isConnected.value) return\n\n const message: ChatMessage = {\n id: crypto.randomUUID(),\n content,\n user: {\n name: props.username,\n },\n createdAt: new Date().toISOString(),\n }\n\n // Optimistic update\n messages.value.push(message)\n\n await channel.value.send({\n type: 'broadcast',\n event: EVENT_MESSAGE_TYPE,\n payload: message,\n })\n }\n\n return {\n messages,\n sendMessage,\n isConnected,\n }\n}\n", "type": "registry:component", "target": "app/composables/useRealtimeChat.ts" } ], "type": "registry:block" }