Skip to content
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

Qr toggle and button styling #340

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"@types/node": "^20.2.5",
"@types/react": "^18.2.9",
"@types/react-dom": "^18.2.4",
"qrcode.react": "^3.1.0",
"react": "^16.13.1",
"react-bootstrap": "^1.5.2",
"react-dom": "^16.13.1",
"react-icons": "^3.10.0",
"react-router-dom": "^5.2.0",
"react-scripts": "5.0.1",
"react-scripts": "^5.0.1",
"typescript-plugin-css-modules": "^5.0.1"
},
"devDependencies": {
Expand Down
33 changes: 33 additions & 0 deletions client/src/components/LinkDisplay/Style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,36 @@
width: 100%;
}
}

.qrCodeContainer {
margin-top: 20px;
display: flex;
justify-content: center;
}


.qrButton {
border-width: 1px;
font-family: inherit;
font-size: 18px;
width: 110px;
height: 40px;
border-radius: 5px;
cursor: pointer;
outline: none;
border-color: #434343;
background: #4bb2f9;
color: white;
margin-left: 5px;
}

.qrButton:hover {
background-color: #0056b3;
}

.QrCodeContent{
display: flex;
align-items: center;
}


42 changes: 32 additions & 10 deletions client/src/components/LinkDisplay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React, { useRef, useState, useContext } from 'react';
import { FiLink, FiCopy, FiExternalLink } from 'react-icons/fi';
import styles from './Style.module.css';
import { ThemeContext } from '../../ThemeContext';
import { LinkObjType } from '@chat-e2ee/service';
import React, { useRef, useState, useContext } from "react";
import { FiLink, FiCopy, FiExternalLink, FiArrowDown, FiArrowUp } from "react-icons/fi";
import styles from "./Style.module.css";
import { ThemeContext } from "../../ThemeContext";
import { LinkObjType } from "@chat-e2ee/service";
import QRCode from "qrcode.react";

const LinkDisplay: React.FC<{ content: LinkObjType}> = ( { content } ) => {
const chatLink = content.absoluteLink || `${window.location.protocol}//${window.location.host}/chat/${content.hash}`;
const LinkDisplay: React.FC<{ content: LinkObjType }> = ({ content }) => {
const chatLink =
content.absoluteLink ||
`${window.location.protocol}//${window.location.host}/chat/${content.hash}`;
const textAreaRef = useRef<HTMLInputElement | null>(null);
const [buttonText, setButtonText] = useState("Copy");
const [showQR, setShowQR] = useState(false);
const [darkMode] = useContext(ThemeContext);

const copyCodeToClipboard = () => {
Expand All @@ -23,9 +27,7 @@ const LinkDisplay: React.FC<{ content: LinkObjType}> = ( { content } ) => {
return (
<div className={styles.fullWidth}>
<div className={styles.divider} />
<span className={styles.pinDisplayMsg}>
Anyone with the Link can join your chat
</span>
<span className={styles.pinDisplayMsg}>Anyone with the Link can join your chat</span>
<div
className={`${styles.copyToClipboardContainer}
${!darkMode && styles.lightModeContainer}`}
Expand All @@ -50,6 +52,21 @@ const LinkDisplay: React.FC<{ content: LinkObjType}> = ( { content } ) => {
>
<FiCopy className={styles.copyIcon} /> {buttonText}
</button>
<button
type="button"
className={`${styles.qrButton} ${!darkMode && styles.lightModeButton}`}
onClick={() => setShowQR(!showQR)}
>
{showQR ? (
<div className={styles.QrCodeContent}>
QR Code <FiArrowUp className={styles.qrIcon} />
</div>
) : (
<div className={styles.QrCodeContent}>
QR Code <FiArrowDown className={styles.qrIcon} />
</div>
)}
</button>
</div>
</div>
<div className={styles.divider} />
Expand All @@ -61,6 +78,11 @@ const LinkDisplay: React.FC<{ content: LinkObjType}> = ( { content } ) => {
Open chat <FiExternalLink />
</a>
</div>
{showQR && (
<div className={styles.qrCodeContainer}>
<QRCode value={chatLink} size={128} />
</div>
)}
</div>
);
};
Expand Down
Loading