From 2960899c96b657bc9683528811972fb2cdeaebe0 Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Thu, 7 Oct 2021 10:20:09 +0530 Subject: [PATCH 1/7] Add Share Component --- client/src/components/Chat.js | 6 +- client/src/components/InfoBar.js | 11 ++- client/src/components/Share.js | 118 +++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 client/src/components/Share.js diff --git a/client/src/components/Chat.js b/client/src/components/Chat.js index 27a0326..80bb5cd 100644 --- a/client/src/components/Chat.js +++ b/client/src/components/Chat.js @@ -41,7 +41,7 @@ const Chat = ({ location }) => { }); }, []); - const sendMesssage = (event) => { + const sendMessage = (event) => { event.preventDefault(); if (message) { socket.emit("sendMessage", message, () => setMessage("")); @@ -52,12 +52,12 @@ const Chat = ({ location }) => { return (
- +
); diff --git a/client/src/components/InfoBar.js b/client/src/components/InfoBar.js index 844a9f8..e2363c5 100644 --- a/client/src/components/InfoBar.js +++ b/client/src/components/InfoBar.js @@ -1,17 +1,24 @@ import React from "react"; import closeIcon from "../../icons/closeIcon.png"; import onlineIcon from "../../icons/onlineIcon.png"; +import { ShareButton } from "./Share"; -const InfoBar = ({ room }) => { +const InfoBar = ({ room, name }) => { return (
-
+
online

{room}

+
diff --git a/client/src/components/Share.js b/client/src/components/Share.js new file mode 100644 index 0000000..138cb2a --- /dev/null +++ b/client/src/components/Share.js @@ -0,0 +1,118 @@ +import React, { useState, useEffect } from "react"; + +const SHARE_OPTIONS = [ + { + type: "LinkedIn", + url: (url, text) => + `https://www.linkedin.com/shareArticle?mini=true&title=${text}&source=Chatcus&url=${url}`, + }, + { + type: "Facebook", + url: (url) => `https://www.facebook.com/sharer/sharer.php?u=${url}`, + }, + { + type: "Twitter", + url: (url, text) => + `https://twitter.com/intent/tweet?text=${text}&url=${url}`, + }, + { + type: "Reddit", + url: (url, text) => + `https://www.reddit.com/submit?title=${text}&url=${url}`, + }, +]; + +export const ShareButton = ({ link, text }) => { + const [dropdownState, setDropdownState] = useState(false); + const [linkCopied, setLinkCopied] = useState(false); + const shareViaNavigator = () => { + if (navigator.share) { + navigator + .share({ + title: text, + url: link, + }) + .then(() => { + console.log("Thanks for sharing!"); + }) + .catch(console.error); + } + }; + const copyToClipboard = () => { + navigator.clipboard.writeText(decodeURIComponent(link)).then(() => { + setLinkCopied(true); + }); + }; + useEffect(() => { + if (!dropdownState) setLinkCopied(false); + }, [dropdownState]); + return ( +
+
+ +
+ +
+
+ ); +}; From 36429148f950a2220116ea1285f4c7696c4149fc Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Thu, 7 Oct 2021 10:20:44 +0530 Subject: [PATCH 2/7] Modify Join component to parse room from query string --- client/src/components/Join.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/client/src/components/Join.js b/client/src/components/Join.js index 816760e..c417fa3 100644 --- a/client/src/components/Join.js +++ b/client/src/components/Join.js @@ -1,10 +1,17 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; +import queryString from "query-string"; import { Link } from "react-router-dom"; -const Join = () => { +const Join = ({ location }) => { const [name, setName] = useState(""); const [room, setRoom] = useState(""); - + useEffect(() => { + const { room } = queryString.parse(location.search); + console.log(queryString.parse(location.search)); + if (room) { + setRoom(room); + } + }, []); return (

@@ -23,6 +30,7 @@ const Join = () => { placeholder="Room" className="w-70 p-2 bg-green-100 outline-none" type="text" + value={room} onChange={(event) => { setRoom(event.target.value); }} From 46d4c93d1105c369d1d56baec8acb5bf3ddb302b Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Thu, 7 Oct 2021 11:55:52 +0530 Subject: [PATCH 3/7] Update URL from static to origin URL --- client/src/components/InfoBar.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/src/components/InfoBar.js b/client/src/components/InfoBar.js index e2363c5..ccecc48 100644 --- a/client/src/components/InfoBar.js +++ b/client/src/components/InfoBar.js @@ -14,9 +14,7 @@ const InfoBar = ({ room, name }) => { />

{room}

From 7a79cd25c3ae122a057e026b8c1ca9599f6c4c9b Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Thu, 7 Oct 2021 12:27:00 +0530 Subject: [PATCH 4/7] Update Share text message in InfoBar --- client/src/components/InfoBar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/components/InfoBar.js b/client/src/components/InfoBar.js index ccecc48..5ea1909 100644 --- a/client/src/components/InfoBar.js +++ b/client/src/components/InfoBar.js @@ -15,7 +15,7 @@ const InfoBar = ({ room, name }) => {

{room}

From ffff6f372062262e29ef2a3e047fc96cc6d1f4ec Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Thu, 7 Oct 2021 12:57:06 +0530 Subject: [PATCH 5/7] fix:Close sharepopup when clicked outside --- client/src/components/Share.js | 124 ++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 58 deletions(-) diff --git a/client/src/components/Share.js b/client/src/components/Share.js index 138cb2a..4c08abb 100644 --- a/client/src/components/Share.js +++ b/client/src/components/Share.js @@ -47,72 +47,80 @@ export const ShareButton = ({ link, text }) => { if (!dropdownState) setLinkCopied(false); }, [dropdownState]); return ( -
-
- -
- -
-
+ +
+
- {SHARE_OPTIONS.map((option, i) => ( - + +
+
+ + {linkCopied ? "Copied to Clipboard" : "Copy Link"} + + {SHARE_OPTIONS.map((option, i) => ( + + Share to {option.type} + + ))} + +
-
+
setDropdownState(false)} + className="w-full h-full fixed left-0 top-0" + >
+
); }; From 97d6211df1c2238aa8bb2279e6f72f22528b58e0 Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Thu, 7 Oct 2021 13:46:21 +0530 Subject: [PATCH 6/7] fix:decode URI when sharing through navigator --- client/src/components/Share.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/components/Share.js b/client/src/components/Share.js index 4c08abb..a6496ca 100644 --- a/client/src/components/Share.js +++ b/client/src/components/Share.js @@ -30,7 +30,7 @@ export const ShareButton = ({ link, text }) => { navigator .share({ title: text, - url: link, + url: decodeURIComponent(link), }) .then(() => { console.log("Thanks for sharing!"); From 99305124a4e2837688da9c33c103aa86e456a09d Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Thu, 7 Oct 2021 13:50:42 +0530 Subject: [PATCH 7/7] Code refactoring --- client/src/components/InfoBar.js | 2 +- client/src/components/Share.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/src/components/InfoBar.js b/client/src/components/InfoBar.js index 5ea1909..72f7b8f 100644 --- a/client/src/components/InfoBar.js +++ b/client/src/components/InfoBar.js @@ -14,7 +14,7 @@ const InfoBar = ({ room, name }) => { />

{room}

diff --git a/client/src/components/Share.js b/client/src/components/Share.js index a6496ca..6b676b1 100644 --- a/client/src/components/Share.js +++ b/client/src/components/Share.js @@ -30,7 +30,7 @@ export const ShareButton = ({ link, text }) => { navigator .share({ title: text, - url: decodeURIComponent(link), + url: link, }) .then(() => { console.log("Thanks for sharing!"); @@ -39,7 +39,7 @@ export const ShareButton = ({ link, text }) => { } }; const copyToClipboard = () => { - navigator.clipboard.writeText(decodeURIComponent(link)).then(() => { + navigator.clipboard.writeText(link).then(() => { setLinkCopied(true); }); }; @@ -93,7 +93,7 @@ export const ShareButton = ({ link, text }) => { {SHARE_OPTIONS.map((option, i) => (