This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import QRCode from "qrcode.react"; | ||
import { useLocation } from "react-router-dom"; | ||
import { generateUUID } from "../utils/uuid"; | ||
|
||
type QRCodeGeneratorProps = { | ||
size?: number; | ||
}; | ||
|
||
const QRCodeGenerator: React.FC<QRCodeGeneratorProps> = ({ size = 128 }) => { | ||
const location = useLocation(); | ||
const baseUrl = `${window.location.origin}${location.pathname}`; | ||
const roomId = generateUUID(); | ||
const url = `${baseUrl}?room_id=${roomId}`; | ||
|
||
return ( | ||
<div> | ||
<QRCode value={url} size={size} renderAs="svg" /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default QRCodeGenerator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import QRCodeGenerator from "../../components/QRCodeGenerator"; | ||
|
||
const QRCodePage: React.FC = () => { | ||
return ( | ||
<div> | ||
<QRCodeGenerator size={256} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default QRCodePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export function generateQueryParams( | ||
params: Record<string, string | number>, | ||
): string { | ||
const searchParams = new URLSearchParams(); | ||
// biome-ignore lint/complexity/noForEach: <explanation> | ||
Object.entries(params).forEach(([key, value]) => { | ||
searchParams.append(key, String(value)); | ||
}); | ||
return searchParams.toString(); | ||
} | ||
|
||
export function appendQueryParamsToUrl( | ||
baseUrl: string, | ||
params: Record<string, string | number>, | ||
): string { | ||
const queryString = generateQueryParams(params); | ||
const separator = baseUrl.includes("?") ? "&" : "?"; | ||
return `${baseUrl}${separator}${queryString}`; | ||
} |