diff --git a/package.json b/package.json index 14b0238..fbc8877 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "instagram-live-streamer", "description": "Create streaming links to instagram live", - "version": "0.1.6", + "version": "0.1.7-beta", "private": true, "copyright": "Copyright © 2020 Musthaq Ahamad", "licence": "MIT", diff --git a/src/Pages/Comments/index.jsx b/src/Pages/Comments/index.jsx index f987fac..ba1cc22 100644 --- a/src/Pages/Comments/index.jsx +++ b/src/Pages/Comments/index.jsx @@ -9,6 +9,7 @@ import CloseIcon from "../../images/down-arrow.svg"; import SendIcon from "../../images/direct.svg"; import Toggle from "../../components/Toggle"; import MuteIcon from "../../images/mute.svg"; +import PinIcon from "../../images/pin.svg"; function Comments({ broadcastId, @@ -20,10 +21,12 @@ function Comments({ }) { const [isMuted, setMuted] = useState(false); const [inProgress, setInProgress] = useState(false); - const [userComment, setUserComment] = useState(''); + const [userComment, setUserComment] = useState(""); const [isCommenting, setCommenting] = useState(false); + const [pinnedComment, setPinnedComment] = useState(); const client = getClient(); - let lastCommentTs = comments && comments.length>0? comments[0].created_at : 0; + let lastCommentTs = + comments && comments.length > 0 ? comments[0].created_at : 0; const startComments = async () => { setInProgress(true); @@ -62,15 +65,34 @@ function Comments({ } }; + const pinComment = async (comment) => { + // check if current comment is pinned + if (pinnedComment && pinnedComment.pk === comment.pk) { + try { + setPinnedComment(null); + await client.live.unpinComment(broadcastId, comment.pk); + } catch (error) { + console.error(error); + } + } else { + try { + setPinnedComment(comment); + await client.live.pinComment(broadcastId, comment.pk); + } catch (error) { + console.error(error); + } + } + }; + const addComment = async () => { console.log("adding comments..."); const comment = userComment; // do not comment, if there is no comment text available if (!(comment && comment.length > 0)) return; - setUserComment('') + setUserComment(""); setCommenting(true); await client.live.comment(broadcastId, comment); - } + }; const toggleComments = async () => { try { @@ -101,6 +123,7 @@ function Comments({ }, []); const renderComments = (comments) => { + console.log(comments); return comments.map((comment) => (
{comment.text}