2025-06-11 00:14:17 +02:00
|
|
|
import { LocalMessageNode } from '@colanode/client/types';
|
|
|
|
|
import { MessageAuthorAvatar } from '@colanode/ui/components/messages/message-author-avatar';
|
|
|
|
|
import { MessageAuthorName } from '@colanode/ui/components/messages/message-author-name';
|
|
|
|
|
import { MessageContent } from '@colanode/ui/components/messages/message-content';
|
|
|
|
|
import { useWorkspace } from '@colanode/ui/contexts/workspace';
|
2025-07-21 09:22:15 +02:00
|
|
|
import { useLiveQuery } from '@colanode/ui/hooks/use-live-query';
|
2024-12-02 00:44:02 +01:00
|
|
|
|
2025-01-09 11:13:22 +01:00
|
|
|
interface MessageReferenceProps {
|
|
|
|
|
messageId: string;
|
|
|
|
|
}
|
2024-11-22 13:40:58 +01:00
|
|
|
|
2025-01-09 11:13:22 +01:00
|
|
|
export const MessageReference = ({ messageId }: MessageReferenceProps) => {
|
|
|
|
|
const workspace = useWorkspace();
|
2025-07-21 09:22:15 +02:00
|
|
|
const nodeGetQuery = useLiveQuery({
|
2025-06-11 00:14:17 +02:00
|
|
|
type: 'node.get',
|
2025-02-05 22:40:35 +01:00
|
|
|
nodeId: messageId,
|
2025-11-11 07:00:14 -08:00
|
|
|
userId: workspace.userId,
|
2025-01-09 11:13:22 +01:00
|
|
|
});
|
2024-11-22 13:40:58 +01:00
|
|
|
|
2025-06-11 00:14:17 +02:00
|
|
|
if (nodeGetQuery.isPending) {
|
2025-01-09 11:13:22 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
2024-11-22 13:40:58 +01:00
|
|
|
|
2025-06-11 00:14:17 +02:00
|
|
|
const message = nodeGetQuery.data as LocalMessageNode;
|
2025-02-05 22:40:35 +01:00
|
|
|
|
2025-06-11 00:14:17 +02:00
|
|
|
if (!message) {
|
2025-01-09 11:13:22 +01:00
|
|
|
return (
|
|
|
|
|
<div className="flex flex-row gap-2 border-l-4 p-2">
|
|
|
|
|
<span className="text-sm text-muted-foreground">
|
|
|
|
|
Message not found or has been deleted
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-11-22 13:40:58 +01:00
|
|
|
|
2025-01-09 11:13:22 +01:00
|
|
|
return (
|
|
|
|
|
<div className="flex flex-row gap-2 border-l-4 p-2">
|
2025-02-05 22:40:35 +01:00
|
|
|
<MessageAuthorAvatar message={message} className="size-5 mt-1" />
|
2025-11-11 07:00:14 -08:00
|
|
|
<div className='"grow flex-col gap-1'>
|
2025-02-05 22:40:35 +01:00
|
|
|
<MessageAuthorName message={message} />
|
|
|
|
|
<MessageContent message={message} />
|
2025-01-09 11:13:22 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|