diff --git a/src/common/hook/useCopy.js b/src/common/hook/useCopy.js index f9245236..ee1168da 100644 --- a/src/common/hook/useCopy.js +++ b/src/common/hook/useCopy.js @@ -1,7 +1,17 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import { copyImageToClipboard } from "copy-image-clipboard"; +import toast from "react-hot-toast"; + +const useCopy = (config) => { + const { enableToast = true } = config || {}; + + const [copied, setCopied] = useState(false); + useEffect(() => { + if (copied && enableToast) { + toast.success("Copied!"); + } + }, [copied]); -const useCopy = () => { const copyToClipboard = (str) => { const el = document.createElement("textarea"); el.value = str; @@ -23,10 +33,9 @@ const useCopy = () => { return success; }; - const [copied, setCopied] = useState(false); - const copy = (text, isImage = false) => { let inter = 0; + console.log("copy", text, isImage); if (!copied) { if (!isImage) { setCopied(copyToClipboard(text)); @@ -47,7 +56,7 @@ const useCopy = () => { }; }; - return [copied, copy]; + return { copied, copy }; }; export default useCopy; diff --git a/src/routes/chat/ChannelChat/index.js b/src/routes/chat/ChannelChat/index.js index 2f505f48..2f757cad 100644 --- a/src/routes/chat/ChannelChat/index.js +++ b/src/routes/chat/ChannelChat/index.js @@ -86,7 +86,7 @@ export default function ChannelChat({ cid = "", dropFiles = [] }) { const addVisible = loginUser?.is_admin || owner == loginUid; const readIndex = footprint.readChannels[cid]; const pinCount = data?.pinned_messages?.length || 0; - const finalHasMore = selects ? false : hasMore; + // const finalHasMore = selects ? false : hasMore; return ( <> {addMemberModalVisible && ( @@ -212,6 +212,7 @@ export default function ChannelChat({ cid = "", dropFiles = [] }) { owner={owner == uid} key={uid} uid={uid} + cid={cid} dm popover /> diff --git a/src/routes/chat/Layout/index.js b/src/routes/chat/Layout/index.js index 76b3e757..cc93aef1 100644 --- a/src/routes/chat/Layout/index.js +++ b/src/routes/chat/Layout/index.js @@ -8,6 +8,7 @@ import Send from "../../../common/component/Send"; import Styled from "./styled"; import Operations from "./Operations"; import useUploadFile from "../../../common/hook/useUploadFile"; +import { ChatPrefixs } from "../../../app/config"; export default function Layout({ children, @@ -21,9 +22,13 @@ export default function Layout({ const { addStageFile } = useUploadFile({ context, id: to }); const messagesContainer = useRef(null); const [previewImage, setPreviewImage] = useState(null); - const selects = useSelector( - (store) => store.ui.selectMessages[`${context}_${to}`] - ); + const { selects, channelsData, contactsData } = useSelector((store) => { + return { + selects: store.ui.selectMessages[`${context}_${to}`], + channelsData: store.channels.byId, + contactsData: store.contacts.byId, + }; + }); const [{ isActive }, drop] = useDrop( () => ({ accept: [NativeTypes.FILE], @@ -81,7 +86,8 @@ export default function Layout({ ); } }, []); - + const name = + context == "channel" ? channelsData[to]?.name : contactsData[to]?.name; return ( <> {previewImage && ( @@ -111,7 +117,7 @@ export default function Layout({ }`} >