-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathReactionAssociation.tsx
More file actions
167 lines (156 loc) · 7.08 KB
/
Copy pathReactionAssociation.tsx
File metadata and controls
167 lines (156 loc) · 7.08 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import {
type Association,
type ReactionAssociationSchema,
type Message,
type ReplyMessageSchema,
type MarkdownMessageSchema,
type User,
MediaMessageSchema,
UserProfile
} from '@concrnt/worldlib'
import { ContentWithCCAvatar } from '../ContentWithCCAvatar'
import { Box, IconButton, ListItemIcon, ListItemText, Menu, MenuItem, Typography } from '@mui/material'
import { TimeDiff } from '../ui/TimeDiff'
import { useEffect, useState } from 'react'
import { CfmRendererLite } from '../ui/CfmRendererLite'
import MoreHorizIcon from '@mui/icons-material/MoreHoriz'
import DeleteForeverIcon from '@mui/icons-material/DeleteForever'
import { useClient } from '../../context/ClientContext'
import { FaTheaterMasks } from 'react-icons/fa'
import { CCLink } from '../ui/CCLink'
import { CCImage } from '../ui/CCImage'
import { useTranslation } from 'react-i18next'
export interface ReactionAssociationProps {
association: Association<ReactionAssociationSchema>
perspective?: string
withoutContent?: boolean
}
export const ReactionAssociation = (props: ReactionAssociationProps): JSX.Element => {
const { client } = useClient()
const { t } = useTranslation('', { keyPrefix: 'pages.associations' })
const [target, setTarget] = useState<Message<
MarkdownMessageSchema | ReplyMessageSchema | MediaMessageSchema
> | null>(null)
const isMeToOther = props.association?.authorUser?.ccid !== props.perspective
const Nominative = props.association?.authorProfile.username ?? 'anonymous'
const Possessive = (target?.authorProfile.username ?? 'anonymous') + "'s"
const actionUser: User | undefined = isMeToOther ? props.association.authorUser : target?.authorUser
const actionUserProfile: UserProfile = isMeToOther ? props.association.authorProfile : target?.authorProfile!
const [menuAnchor, setMenuAnchor] = useState<null | HTMLElement>(null)
const masked =
(isMeToOther ? props.association.authorProfile.original : target?.authorProfile.original) !== undefined
const targetLink = target ? `/${target.author}/${target.id}` : '#' // Link to reacted message
useEffect(() => {
props.association.getTargetMessage().then(setTarget)
}, [props.association])
if (!target) {
return <></>
}
return (
<ContentWithCCAvatar author={actionUser} linkTo={targetLink} profile={actionUserProfile}>
<Box display="flex" justifyContent="space-between" alignItems="center">
<Box display="flex" overflow="hidden">
<Box display="flex" alignItems="center" flexShrink={0} gap={0.5}>
<CCLink
underline="hover"
color="inherit"
to={props.association.author ? `/${props.association.author}` : '#'}
>
<Typography style={{ fontWeight: isMeToOther ? 600 : 'inherit' }}>{Nominative}</Typography>
</CCLink>
{masked && <FaTheaterMasks />}
<Typography>reacted</Typography>
<Typography style={{ fontWeight: !isMeToOther ? 600 : 'inherit' }}>{Possessive}</Typography>
<Typography>message with </Typography>
<img
height="13px"
src={props.association.document.body.imageUrl}
alt={props.association.document.body.shortcode}
/>
</Box>
</Box>
<Box display="flex" gap={0.5}>
{(props.association.author === client?.ccid || props.association.owner === client?.ccid) && (
<IconButton
sx={{
width: { xs: '12px', sm: '18px' },
height: { xs: '12px', sm: '18px' },
color: 'text.disabled'
}}
onClick={(e) => {
e.stopPropagation()
setMenuAnchor(e.currentTarget)
}}
>
<MoreHorizIcon sx={{ fontSize: '80%' }} />
</IconButton>
)}
<CCLink fontSize="0.75rem" to={targetLink}>
<TimeDiff date={new Date(props.association.cdate)} />
</CCLink>
</Box>
</Box>
{(target && !props.withoutContent && (
<>
<blockquote style={{ margin: 0, paddingLeft: '1rem', borderLeft: '4px solid #ccc' }}>
<CfmRendererLite
messagebody={target?.document.body.body ?? 'no content'}
emojiDict={target?.document.body.emojis ?? {}}
/>
</blockquote>
{'medias' in target.document.body && (
<Box
display="flex"
gap={1}
flexWrap="wrap"
justifyContent="flex-start"
sx={{
marginTop: '0.5rem',
marginBottom: '0.5rem'
}}
>
{target.document.body.medias?.map((media, i) => (
<CCImage
key={i}
src={media.mediaURL}
blurhash={media.blurhash}
sx={{
width: '75px',
height: '75px'
}}
forceBlur={!!media.flag}
/>
))}
</Box>
)}
</>
)) ||
undefined}
<Box
onClick={(e) => {
e.stopPropagation() // prevent to navigate other page
}}
>
<Menu
anchorEl={menuAnchor}
open={Boolean(menuAnchor)}
onClose={() => {
setMenuAnchor(null)
}}
>
<MenuItem
onClick={() => {
props.association.delete()
setMenuAnchor(null)
}}
>
<ListItemIcon>
<DeleteForeverIcon sx={{ color: 'text.primary' }} />
</ListItemIcon>
<ListItemText>{t('removeAssociation')}</ListItemText>
</MenuItem>
</Menu>
</Box>
</ContentWithCCAvatar>
)
}