feat: useWorkspaceEcho / usePostEcho composables and realtime list refresh
Two new composables under resources/js/composables/echo/ that abstract channel naming for the two Reverb subscription patterns we now use: - useWorkspaceEcho — list/dashboard views: 1 subscription per workspace delivers events for many entities. Resolves currentWorkspace.id from Inertia shared props; no-ops when there is no workspace yet. - usePostEcho — focused views (Show, Edit): per-post channel. Posts index now subscribes via useWorkspaceEcho to the 3 lifecycle events (post.created / post.deleted / post.platform.status.updated) and reloads the posts prop on receipt. `reset: ['posts']` is required on the reload — without it, InfiniteScroll's merge prop appends every broadcast onto the existing list and produces duplicates. Show / Edit migrated from raw useEcho to usePostEcho; AiGenerateDialog, NotificationBell and AiPostWizard updated to the new event names from the namespaced convention. AiStream composable moved into the same echo/ folder for organisation; its bound event names (TextDelta / StreamEnd / Error) come from the laravel/ai package and stay as-is. Bonus: comments tab send button was overriding shadcn's size="icon" (40px) with class="size-9" (36px), which left it visibly shorter than the textarea. Removed the override and matched the textarea's min-h to size-10 so both render at 40px.
This commit is contained in:
parent
c627c532b3
commit
554b86d223
8 changed files with 46 additions and 8 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
9
resources/js/composables/echo/usePostEcho.ts
Normal file
9
resources/js/composables/echo/usePostEcho.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { useEcho } from '@laravel/echo-vue';
|
||||
|
||||
export const usePostEcho = <T = unknown>(
|
||||
postId: string,
|
||||
event: string | string[],
|
||||
callback: (payload: T) => void,
|
||||
) => {
|
||||
return useEcho<T>(`post.${postId}`, event, callback);
|
||||
};
|
||||
18
resources/js/composables/echo/useWorkspaceEcho.ts
Normal file
18
resources/js/composables/echo/useWorkspaceEcho.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { usePage } from '@inertiajs/vue3';
|
||||
import { useEcho } from '@laravel/echo-vue';
|
||||
|
||||
import type { Auth } from '@/types';
|
||||
|
||||
export const useWorkspaceEcho = <T = unknown>(
|
||||
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<T>(`workspace.${workspaceId}`, event, callback);
|
||||
};
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import { Head, router } from '@inertiajs/vue3';
|
||||
import { useEcho } from '@laravel/echo-vue';
|
||||
import {
|
||||
IconCalendar,
|
||||
IconCircleCheck,
|
||||
|
|
@ -18,6 +17,7 @@ import PostEditorSidebar from '@/components/posts/editor/PostEditorSidebar.vue';
|
|||
import PickTimePopover from '@/components/posts/PickTimePopover.vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
import { usePostEcho } from '@/composables/echo/usePostEcho';
|
||||
import { getMediaItemIssue } from '@/composables/useMedia';
|
||||
import { getMediaRulesForContentType } from '@/composables/useMediaRules';
|
||||
import dayjs from '@/dayjs';
|
||||
|
|
@ -422,13 +422,13 @@ const unschedulePost = () => {
|
|||
// Event fires when any post_platform completes publishing (success or fail).
|
||||
// Full reload of the post prop so the new status + post_platforms propagate and
|
||||
// the overlay dismisses.
|
||||
useEcho(`post.${post.value.id}`, '.PostPlatformStatusUpdated', () => {
|
||||
usePostEcho(post.value.id, '.post.platform.status.updated', () => {
|
||||
router.reload({ only: ['post'] });
|
||||
});
|
||||
|
||||
|
||||
// Echo: listen for real-time comments
|
||||
useEcho(`post.${post.value.id}`, '.PostCommentCreated', (e: any) => {
|
||||
usePostEcho(post.value.id, '.post.comment.created', (e: any) => {
|
||||
if (e.mentioned_users) {
|
||||
editorSidebarRef.value?.registerMentionedUsers(e.mentioned_users);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import {
|
|||
TableRow,
|
||||
} from '@/components/ui/table';
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
import { useWorkspaceEcho } from '@/composables/echo/useWorkspaceEcho';
|
||||
import { getPlatformLabel, getPlatformLogo } from '@/composables/usePlatformLogo';
|
||||
import { getPostStatusConfig } from '@/composables/usePostStatus';
|
||||
import dayjs from '@/dayjs';
|
||||
|
|
@ -143,6 +144,16 @@ const handleDuplicate = (post: Post) => {
|
|||
const handleCopyId = (post: Post) => copyToClipboard(post.id, trans('posts.actions.copied'));
|
||||
|
||||
const hasActiveSearch = computed(() => Boolean(searchQuery.value?.trim()));
|
||||
|
||||
// `reset: ['posts']` forces a replace on the InfiniteScroll merge prop —
|
||||
// without it, every broadcast would append a fresh page 1 onto the
|
||||
// existing list and produce duplicates.
|
||||
const refreshPosts = () => router.reload({ only: ['posts'], reset: ['posts'] });
|
||||
|
||||
useWorkspaceEcho(
|
||||
['.post.created', '.post.deleted', '.post.platform.status.updated'],
|
||||
refreshPosts,
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import { Head, Link, router } from '@inertiajs/vue3';
|
||||
import { useEcho } from '@laravel/echo-vue';
|
||||
import { IconArrowLeft, IconCalendar, IconExternalLink, IconLoader2, IconX } from '@tabler/icons-vue';
|
||||
import { trans } from 'laravel-vue-i18n';
|
||||
import { computed, ref } from 'vue';
|
||||
|
|
@ -12,6 +11,7 @@ import { Badge } from '@/components/ui/badge';
|
|||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
import { usePostEcho } from '@/composables/echo/usePostEcho';
|
||||
import { getPlatformLabel, getPlatformLogo } from '@/composables/usePlatformLogo';
|
||||
import { getPlatformStatusConfig, getPostStatusConfig } from '@/composables/usePostStatus';
|
||||
import dayjs from '@/dayjs';
|
||||
|
|
@ -104,7 +104,7 @@ const openLightbox = (i: number) => {
|
|||
lightboxOpen.value = true;
|
||||
};
|
||||
|
||||
useEcho(`post.${props.post.id}`, '.PostPlatformStatusUpdated', () => {
|
||||
usePostEcho(props.post.id, '.post.platform.status.updated', () => {
|
||||
router.reload({ only: ['post'] });
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in a new issue