-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Expand file tree
/
Copy pathap-reply-box.tsx
More file actions
73 lines (65 loc) · 2.29 KB
/
Copy pathap-reply-box.tsx
File metadata and controls
73 lines (65 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React, {HTMLProps, useState} from 'react';
import APAvatar from './ap-avatar';
import NewNoteModal from '@components/modals/new-note-modal';
import getHandle from '../../utils/get-handle';
import {ActorProperties, ObjectProperties} from '@tryghost/admin-x-framework/api/activitypub';
import {useUserDataForUser} from '@hooks/use-activity-pub-queries';
export interface APTextAreaProps extends HTMLProps<HTMLDivElement> {
object: ObjectProperties;
onReply?: () => void;
onReplyError?: () => void;
}
const APReplyBox: React.FC<APTextAreaProps> = ({
object,
onReply,
onReplyError,
className,
...props
}) => {
const {data: user} = useUserDataForUser('index');
const [showReplyModal, setShowReplyModal] = useState(false);
if (!user) {
return null;
}
const attributedTo = object.attributedTo as ActorProperties | undefined;
let placeholder = 'Reply...';
if (attributedTo?.preferredUsername && attributedTo?.id) {
placeholder = `Reply to ${getHandle(attributedTo)}...`;
}
return (
<>
<div
className={`flex w-full cursor-pointer gap-x-3 py-6 ${className || ''}`}
onClick={() => setShowReplyModal(true)}
{...props}
>
<APAvatar author={user as ActorProperties} />
<div className='flex w-full items-center'>
<div className='w-full text-[1.5rem] text-gray-500 transition-colors dark:text-gray-700'>
{placeholder}
</div>
</div>
</div>
{showReplyModal && (
<NewNoteModal
open={showReplyModal}
replyTo={{
object: object,
actor: object.attributedTo as ActorProperties
}}
onOpenChange={(open) => {
setShowReplyModal(open);
}}
onReply={() => {
onReply?.();
setShowReplyModal(false);
}}
onReplyError={() => {
onReplyError?.();
}}
/>
)}
</>
);
};
export default APReplyBox;