Skip to content

Commit 874a096

Browse files
committed
Add QR code display modal and integrate into profile settings (closes #10)
1 parent a717550 commit 874a096

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

frontend/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@types/react-router-dom": "^5.3.3",
3131
"idb-keyval": "^6.2.1",
3232
"ionicons": "^7.0.0",
33+
"qrcode.react": "^4.2.0",
3334
"react": "^18.2.0",
3435
"react-dom": "^18.2.0",
3536
"react-router": "^5.3.4",

frontend/src/modal/QRCodeDisplay.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { IonModal, IonHeader, IonToolbar, IonButtons, IonButton, IonTitle, IonContent, IonCard } from "@ionic/react"
2+
import { QRCodeSVG } from "qrcode.react"
3+
4+
interface DisplayProps {
5+
title: string
6+
codeContent: string
7+
open: boolean
8+
onClose: () => void
9+
}
10+
11+
const QRCodeDialog: React.FC<DisplayProps> = ({ title, codeContent, open, onClose }) => (
12+
<IonModal isOpen={open} onDidDismiss={() => onClose()}>
13+
<IonHeader>
14+
<IonToolbar>
15+
<IonTitle>{title}</IonTitle>
16+
<IonButtons slot="start">
17+
<IonButton onClick={() => onClose()}>Close</IonButton>
18+
</IonButtons>
19+
</IonToolbar>
20+
</IonHeader>
21+
<IonContent className="ion-padding">
22+
<IonCard style={{ backgroundColor: "white", padding: 20 }}>
23+
<QRCodeSVG value={codeContent} width="100%" height="400" />
24+
</IonCard>
25+
</IonContent>
26+
</IonModal>
27+
)
28+
29+
export default QRCodeDialog

frontend/src/modal/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { default as BarcodeScanDialog } from "./Barcode"
22
export { default as ViewAlbumDetails } from "./ViewAlbumDetails"
3+
export { default as QRCodeDialog } from "./QRCodeDisplay"

frontend/src/pages/Settings/Profile.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@ import {
2020
IonAlert,
2121
getConfig,
2222
IonCardContent,
23+
IonButton,
24+
IonIcon,
2325
} from "@ionic/react"
2426
import { useQuery, useQueryClient } from "@tanstack/react-query"
25-
import { hourglass, library, eye } from "ionicons/icons"
27+
import { hourglass, library, eye, qrCodeOutline, qrCodeSharp } from "ionicons/icons"
2628
import "./Profile.css"
2729
import { useHistory } from "react-router"
30+
import { QRCodeDialog } from "@/modal"
31+
import { useState } from "react"
2832

2933
const SettingsProfilePage: React.FC = () => {
3034
const queryClient = useQueryClient()
3135
const history = useHistory()
3236
const [{ username, accessToken, secretToken }, _, clearAuth] = useAuth()
3337
const ionConfig = getConfig()
38+
const [openScanner, setOpenScanner] = useState<boolean>(false)
3439
const currentMode = ionConfig?.get("mode") || "ios"
3540

3641
const lightMode = currentMode === "ios" ? "light" : undefined
@@ -67,6 +72,11 @@ const SettingsProfilePage: React.FC = () => {
6772
<IonButtons slot="start" collapse={true}>
6873
<IonBackButton />
6974
</IonButtons>
75+
<IonButtons slot="primary">
76+
<IonButton onClick={() => setOpenScanner(true)}>
77+
<IonIcon slot="icon-only" ios={qrCodeOutline} md={qrCodeSharp} />
78+
</IonButton>
79+
</IonButtons>
7080
<IonTitle>Profile</IonTitle>
7181
</IonToolbar>
7282
<InfoBanners />
@@ -131,6 +141,12 @@ const SettingsProfilePage: React.FC = () => {
131141
]}
132142
/>
133143
</IonContent>
144+
<QRCodeDialog
145+
title="Share Profile"
146+
codeContent={`https://www.discogs.com/user/${data?.username}`}
147+
open={openScanner}
148+
onClose={() => setOpenScanner(false)}
149+
/>
134150
</IonPage>
135151
)
136152
}

0 commit comments

Comments
 (0)