-
-
Notifications
You must be signed in to change notification settings - Fork 42
feat: integrate AOSSIE-Org social share button in navbar #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,10 @@ | |
| <link rel="preconnect" href="https://fonts.googleapis.com"> | ||
| <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
| <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Montserrat:wght@600;700&display=swap" rel="stylesheet"> | ||
| <link | ||
| rel="stylesheet" | ||
| href="https://cdn.jsdelivr.net/gh/AOSSIE-Org/[email protected]/src/social-share-button.css" | ||
| /> | ||
| <script type="text/javascript"> | ||
| (function (l) { | ||
| if (l.search[1] === '/') { | ||
|
|
@@ -38,5 +42,6 @@ | |
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="/src/main.jsx"></script> | ||
| <script src="https://cdn.jsdelivr.net/gh/AOSSIE-Org/[email protected]/src/social-share-button.js"></script> | ||
|
amankv1234 marked this conversation as resolved.
|
||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { ConnectButton } from "@rainbow-me/rainbowkit"; | ||
| import NetworkSwitcher from "./NetworkSwitcher"; | ||
| import { useEffect, useState } from "react"; | ||
| import { useEffect, useState, useRef } from "react"; | ||
| import { Link, useNavigate, useLocation } from "react-router-dom"; | ||
| import { useAccount } from "wagmi"; | ||
| import AccountBalanceWalletIcon from "@mui/icons-material/AccountBalanceWallet"; | ||
|
|
@@ -18,6 +18,8 @@ function Navbar() { | |
| const [hasConnected, setHasConnected] = useState(false); | ||
| const [isScrolled, setIsScrolled] = useState(false); | ||
| const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); | ||
| const shareButtonRef = useRef(null); | ||
| const initRef = useRef(false); | ||
|
|
||
| // Improved active route detection | ||
| const isActive = (path) => { | ||
|
|
@@ -42,6 +44,44 @@ function Navbar() { | |
| window.addEventListener("scroll", handleScroll); | ||
| return () => window.removeEventListener("scroll", handleScroll); | ||
| }, [isConnected, hasConnected, navigate, location.pathname, address]); | ||
| useEffect(() => { | ||
| const initButton = () => { | ||
| if (initRef.current || !window.SocialShareButton) return; | ||
|
|
||
| shareButtonRef.current = new window.SocialShareButton({ | ||
| container: "#share-button", | ||
| }); | ||
| initRef.current = true; | ||
| }; | ||
|
|
||
| if (window.SocialShareButton) { | ||
| initButton(); | ||
| } | ||
|
|
||
| const checkInterval = setInterval(() => { | ||
| if (window.SocialShareButton) { | ||
| clearInterval(checkInterval); | ||
| initButton(); | ||
| } | ||
| }, 100); | ||
|
|
||
| return () => { | ||
| clearInterval(checkInterval); | ||
| if (shareButtonRef.current?.destroy) { | ||
| shareButtonRef.current.destroy(); | ||
| } | ||
| initRef.current = false; | ||
| }; | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| if (shareButtonRef.current?.updateOptions) { | ||
| shareButtonRef.current.updateOptions({ | ||
| url: window.location.href, | ||
| title: document.title, | ||
| }); | ||
| } | ||
| }, [location.pathname, location.hash]); | ||
|
amankv1234 marked this conversation as resolved.
Comment on lines
+47
to
+84
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CodeRabbit i think this is not needed in chainvoice(client) code, i think we are handling this inside https://github.com/AOSSIE-Org/SocialShareButton
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR description image shows a "Chainvoice" landing page in dark theme rendered at localhost:5173. The top navbar shows the Chainvoice logo/text on the left, and on the right: a "Share" button (with a share/link icon), an "About" button (with an info icon), and a green "Connect Wallet" button. The hero section shows "Web3 Invoicing Made Simple" headline, supporting text about end-to-end encryption and multi-chain support, three feature pill badges ("Lit Protocol Encrypted", "Multi-chain Support", "End-to-End Security"), and a preview card on the right showing an invoicing table with columns Client, Receiver, Amount, Status, Date, Actions, with a "Encrypted with Lit Protocol" callout badge at the bottom right. At the bottom, a centered tagline reads "Military-Grade Security Powered by Lit Protocol".
I'll skip flagging the lifecycle-management code going forward for this integration pattern. ✏️ Learnings added
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CodeRabbit suggest the changes need to be done for @amankv1234
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
--- a/frontend/src/components/Navbar.jsx
+++ b/frontend/src/components/Navbar.jsx
@@ -1,6 +1,6 @@
import { ConnectButton } from "`@rainbow-me/rainbowkit`";
import NetworkSwitcher from "./NetworkSwitcher";
-import { useEffect, useState, useRef } from "react";
+import { useEffect, useState } from "react";
import { Link, useNavigate, useLocation } from "react-router-dom";
import { useAccount } from "wagmi";
import AccountBalanceWalletIcon from "`@mui/icons-material/AccountBalanceWallet`";
@@ -16,8 +16,6 @@ function Navbar() {
const [hasConnected, setHasConnected] = useState(false);
const [isScrolled, setIsScrolled] = useState(false);
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
- const shareButtonRef = useRef(null);
- const initRef = useRef(false);
// Improved active route detection
const isActive = (path) => {
@@ -44,45 +42,6 @@ function Navbar() {
window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
}, [isConnected, hasConnected, navigate, location.pathname, address]);
- useEffect(() => {
- const initButton = () => {
- if (initRef.current || !window.SocialShareButton) return;
-
- shareButtonRef.current = new window.SocialShareButton({
- container: "`#share-button`",
- });
- initRef.current = true;
- };
-
- if (window.SocialShareButton) {
- initButton();
- }
-
- const checkInterval = setInterval(() => {
- if (window.SocialShareButton) {
- clearInterval(checkInterval);
- initButton();
- }
- }, 100);
-
- return () => {
- clearInterval(checkInterval);
- if (shareButtonRef.current?.destroy) {
- shareButtonRef.current.destroy();
- }
- initRef.current = false;
- };
- }, []);
-
- useEffect(() => {
- if (shareButtonRef.current?.updateOptions) {
- shareButtonRef.current.updateOptions({
- url: window.location.href,
- title: document.title,
- });
- }
- }, [location.pathname, location.hash]);This leaves only the If you'd like, let me know and I can kick off a formal plan for these code changes. 🧠 Learnings used
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CodeRabbit
Why does deleting the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
curl -sL "https://cdn.jsdelivr.net/gh/AOSSIE-Org/[email protected]/src/social-share-button.js" -o /tmp/ssb.js
wc -l /tmp/ssb.js
echo "---- full file ----"
cat -n /tmp/ssb.js
echo "---- searching for auto-init patterns ----"
grep -nE 'DOMContentLoaded|querySelector|data-social|auto|window\.addEventListener|new SocialShareButton|module.exports|export default' /tmp/ssb.jsLength of output: 21355
Here's the full picture from the source:
So to directly answer your question: no, there is no "native ruleset" or self-initialization logic hidden in this library that mounts, destroys, or updates the button on your behalf. It's intentionally minimal — it hands you a class with I'd still recommend restoring the (・_・;) — hope this settles the source-level question conclusively. 🧠 Learnings used
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CodeRabbit suggest what minimal we need to include in client codebase and for that minimal what we need to changes in social-button codebase. Because The main purpose for this library is to provide minimal code to our client and handling all the functioning on behalf of them, not everything in client codebase.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Here's the split of responsibilities I'd suggest: 1. Changes needed in
|
||
|
|
||
| const handleScroll = (sectionId) => { | ||
| if (location.pathname !== "/") { | ||
|
|
@@ -224,6 +264,15 @@ function Navbar() { | |
| </motion.div> | ||
| ))} | ||
|
|
||
| {/* ADD THIS: Social share button container left of About */} | ||
| <motion.div | ||
| whileHover={{ scale: 1.05 }} | ||
| whileTap={{ scale: 0.95 }} | ||
| className="mr-2" | ||
| > | ||
| <div id="share-button"></div> | ||
| </motion.div> | ||
|
|
||
|
amankv1234 marked this conversation as resolved.
|
||
| <motion.div | ||
| whileHover={{ scale: 1.05 }} | ||
| whileTap={{ scale: 0.95 }} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.