diff --git a/resources/js/components/NotificationBell.vue b/resources/js/components/NotificationBell.vue index 17182e9b..527c4825 100644 --- a/resources/js/components/NotificationBell.vue +++ b/resources/js/components/NotificationBell.vue @@ -44,7 +44,7 @@ const channelName = computed(() => ); if (channelName.value) { - useEcho(channelName.value, '.NotificationCreated', (e: { notification: Notification }) => { + useEcho(channelName.value, '.notification.created', (e: { notification: Notification }) => { const exists = notifications.value.some((n) => n.id === e.notification.id); if (exists) return; diff --git a/resources/js/components/posts/ai/AiGenerateDialog.vue b/resources/js/components/posts/ai/AiGenerateDialog.vue index f081de88..788190c1 100644 --- a/resources/js/components/posts/ai/AiGenerateDialog.vue +++ b/resources/js/components/posts/ai/AiGenerateDialog.vue @@ -6,7 +6,7 @@ import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; -import { useAiStream } from '@/composables/useAiStream'; +import { useAiStream } from '@/composables/echo/useAiStream'; import { generate as generatePostAi } from '@/routes/app/posts/ai'; const props = defineProps<{ diff --git a/resources/js/components/posts/create/AiPostWizard.vue b/resources/js/components/posts/create/AiPostWizard.vue index 86dea005..8770abed 100644 --- a/resources/js/components/posts/create/AiPostWizard.vue +++ b/resources/js/components/posts/create/AiPostWizard.vue @@ -229,7 +229,7 @@ const subscribeToCreation = (userId: string, creationId: string) => { const channelName = `users.${userId}.ai-creation.${creationId}`; subscribedChannelName = channelName; - echoChannel = echo().private(channelName).listen('.PostCreationReady', (e: any) => { + echoChannel = echo().private(channelName).listen('.ai.creation.completed', (e: any) => { if (e.error) { previewStatus.value = 'error'; previewError.value = e.error; diff --git a/resources/js/composables/echo/usePostEcho.ts b/resources/js/composables/echo/usePostEcho.ts new file mode 100644 index 00000000..8daa46ac --- /dev/null +++ b/resources/js/composables/echo/usePostEcho.ts @@ -0,0 +1,9 @@ +import { useEcho } from '@laravel/echo-vue'; + +export const usePostEcho = ( + postId: string, + event: string | string[], + callback: (payload: T) => void, +) => { + return useEcho(`post.${postId}`, event, callback); +}; diff --git a/resources/js/composables/echo/useWorkspaceEcho.ts b/resources/js/composables/echo/useWorkspaceEcho.ts new file mode 100644 index 00000000..51ce7d87 --- /dev/null +++ b/resources/js/composables/echo/useWorkspaceEcho.ts @@ -0,0 +1,18 @@ +import { usePage } from '@inertiajs/vue3'; +import { useEcho } from '@laravel/echo-vue'; + +import type { Auth } from '@/types'; + +export const useWorkspaceEcho = ( + event: string | string[], + callback: (payload: T) => void, +) => { + const page = usePage(); + const workspaceId = (page.props.auth as Auth | undefined)?.currentWorkspace?.id; + + if (!workspaceId) { + return; + } + + return useEcho(`workspace.${workspaceId}`, event, callback); +}; diff --git a/resources/js/pages/posts/Edit.vue b/resources/js/pages/posts/Edit.vue index 25025849..1ca1b293 100644 --- a/resources/js/pages/posts/Edit.vue +++ b/resources/js/pages/posts/Edit.vue @@ -1,6 +1,5 @@