mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-06-06 00:16:59 +00:00
added reaction popover
This commit is contained in:
parent
85500bdf8c
commit
c55bc3ec0c
@ -1,8 +1,8 @@
|
|||||||
import { Message } from "@chatscope/chat-ui-kit-react";
|
import { Message } from "@chatscope/chat-ui-kit-react";
|
||||||
import React, { useEffect } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useInView } from "react-intersection-observer";
|
import { useInView } from "react-intersection-observer";
|
||||||
import { MessageDisplay } from "./MessageDisplay";
|
import { MessageDisplay } from "./MessageDisplay";
|
||||||
import { Avatar, Box, ButtonBase, Typography } from "@mui/material";
|
import { Avatar, Box, Button, ButtonBase, List, ListItem, ListItemText, Popover, Typography } from "@mui/material";
|
||||||
import { formatTimestamp } from "../../utils/time";
|
import { formatTimestamp } from "../../utils/time";
|
||||||
import { getBaseApi } from "../../background";
|
import { getBaseApi } from "../../background";
|
||||||
import { getBaseApiReact } from "../../App";
|
import { getBaseApiReact } from "../../App";
|
||||||
@ -35,6 +35,8 @@ export const MessageItem = ({
|
|||||||
lastSignature,
|
lastSignature,
|
||||||
onEdit
|
onEdit
|
||||||
}) => {
|
}) => {
|
||||||
|
const [anchorEl, setAnchorEl] = useState(null);
|
||||||
|
const [selectedReaction, setSelectedReaction] = useState(null);
|
||||||
const { ref, inView } = useInView({
|
const { ref, inView } = useInView({
|
||||||
threshold: 0.7, // Fully visible
|
threshold: 0.7, // Fully visible
|
||||||
triggerOnce: false, // Only trigger once when it becomes visible
|
triggerOnce: false, // Only trigger once when it becomes visible
|
||||||
@ -243,17 +245,15 @@ export const MessageItem = ({
|
|||||||
// const myReaction = reactions
|
// const myReaction = reactions
|
||||||
if(numberOfReactions === 0) return null
|
if(numberOfReactions === 0) return null
|
||||||
return (
|
return (
|
||||||
<ButtonBase sx={{
|
<ButtonBase key={reaction} sx={{
|
||||||
height: '30px',
|
height: '30px',
|
||||||
minWidth: '45px',
|
minWidth: '45px',
|
||||||
background: 'var(--bg-2)',
|
background: 'var(--bg-2)',
|
||||||
borderRadius: '7px'
|
borderRadius: '7px'
|
||||||
}} onClick={()=> {
|
}} onClick={(event) => {
|
||||||
if(reactions[reaction] && reactions[reaction]?.find((item)=> item?.sender === myAddress)){
|
event.stopPropagation(); // Prevent event bubbling
|
||||||
handleReaction(reaction, message, false)
|
setAnchorEl(event.currentTarget);
|
||||||
} else {
|
setSelectedReaction(reaction);
|
||||||
handleReaction(reaction, message, true)
|
|
||||||
}
|
|
||||||
}}>
|
}}>
|
||||||
<div>{reaction}</div> {numberOfReactions > 1 && (
|
<div>{reaction}</div> {numberOfReactions > 1 && (
|
||||||
<Typography sx={{
|
<Typography sx={{
|
||||||
@ -264,6 +264,73 @@ export const MessageItem = ({
|
|||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</Box>
|
</Box>
|
||||||
|
{selectedReaction && (
|
||||||
|
<Popover
|
||||||
|
open={Boolean(anchorEl)}
|
||||||
|
anchorEl={anchorEl}
|
||||||
|
onClose={() => {
|
||||||
|
setAnchorEl(null);
|
||||||
|
setSelectedReaction(null);
|
||||||
|
}}
|
||||||
|
anchorOrigin={{
|
||||||
|
vertical: "top",
|
||||||
|
horizontal: "center",
|
||||||
|
}}
|
||||||
|
transformOrigin={{
|
||||||
|
vertical: "bottom",
|
||||||
|
horizontal: "center",
|
||||||
|
}}
|
||||||
|
PaperProps={{
|
||||||
|
style: {
|
||||||
|
backgroundColor: "#232428",
|
||||||
|
color: "white",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box sx={{ p: 2 }}>
|
||||||
|
<Typography variant="subtitle1" sx={{ marginBottom: 1 }}>
|
||||||
|
People who reacted with {selectedReaction}
|
||||||
|
</Typography>
|
||||||
|
<List sx={{
|
||||||
|
overflow: 'auto',
|
||||||
|
maxWidth: '80vw',
|
||||||
|
maxHeight: '300px'
|
||||||
|
}}>
|
||||||
|
{reactions[selectedReaction]?.map((reactionItem) => (
|
||||||
|
<ListItem key={reactionItem.sender}>
|
||||||
|
<ListItemText
|
||||||
|
primary={reactionItem.senderName || reactionItem.sender}
|
||||||
|
/>
|
||||||
|
</ListItem>
|
||||||
|
))}
|
||||||
|
</List>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={() => {
|
||||||
|
if (
|
||||||
|
reactions[selectedReaction]?.find(
|
||||||
|
(item) => item?.sender === myAddress
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
handleReaction(selectedReaction, message, false); // Remove reaction
|
||||||
|
} else {
|
||||||
|
handleReaction(selectedReaction, message, true); // Add reaction
|
||||||
|
}
|
||||||
|
setAnchorEl(null);
|
||||||
|
setSelectedReaction(null);
|
||||||
|
}}
|
||||||
|
sx={{ marginTop: 2 }}
|
||||||
|
>
|
||||||
|
{reactions[selectedReaction]?.find(
|
||||||
|
(item) => item?.sender === myAddress
|
||||||
|
)
|
||||||
|
? "Remove Reaction"
|
||||||
|
: "Add Reaction"}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</Popover>
|
||||||
|
)}
|
||||||
<Box sx={{
|
<Box sx={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user