-
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.
Enable event sharing functionality via QR Code
- Loading branch information
Showing
7 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
4 changes: 3 additions & 1 deletion
4
src/components/routes/event-details/share-event/ShareEventDetails.js
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 |
---|---|---|
@@ -1,19 +1,21 @@ | ||
import React from 'react'; | ||
import { Container, makeStyles } from '@material-ui/core'; | ||
import { ShareEventLink } from './ShareEventLink'; | ||
import { ShareEventQRCode } from './ShareEventQRCode'; | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
root: { | ||
padding: theme.spacing(1) | ||
} | ||
})); | ||
|
||
export const ShareEventDetails = () => { | ||
export const ShareEventDetails = ({ event }) => { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<Container className={classes.root}> | ||
<ShareEventLink /> | ||
<ShareEventQRCode event={event} /> | ||
</Container> | ||
); | ||
}; |
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
62 changes: 62 additions & 0 deletions
62
src/components/routes/event-details/share-event/ShareEventQRCode.js
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,62 @@ | ||
import React from 'react'; | ||
import QRCode from 'qrcode.react'; | ||
import { Container, makeStyles, Button } from '@material-ui/core'; | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
root: { | ||
padding: 0, | ||
display: 'grid', | ||
justifyItems: 'center' | ||
}, | ||
qrCode: { | ||
margin: `${theme.spacing(2)}px 0px`, | ||
borderRadius: 5, | ||
width: 256, | ||
height: 256, | ||
maxWidth: '70vw' | ||
}, | ||
saveButton: { | ||
width: 256, | ||
maxWidth: '70vw' | ||
} | ||
})); | ||
|
||
const downloadQRCode = ({ eventId }) => { | ||
const img = document.createElement('img'); | ||
const canvas = document.createElement('canvas'); | ||
|
||
// Get SVG data and convert it to base64 formst | ||
const svg = document.getElementById('qr-code'); | ||
const xml = new XMLSerializer().serializeToString(svg); | ||
const svg64 = 'data:image/svg+xml;base64,' + btoa(xml); | ||
|
||
img.onload = () => { | ||
canvas.getContext('2d').drawImage(img, 0, 0); | ||
const link = document.createElement('a'); | ||
link.download = `raven_${eventId}.png`; | ||
link.href = canvas.toDataURL(); | ||
link.click(); | ||
}; | ||
img.src = svg64; | ||
}; | ||
|
||
export const ShareEventQRCode = ({ event: { id } }) => { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<Container className={classes.root}> | ||
<QRCode | ||
value={window.location.href} | ||
renderAs="svg" | ||
id="qr-code" | ||
className={classes.qrCode} | ||
/> | ||
<Button | ||
className={classes.saveButton} | ||
onClick={() => downloadQRCode({ eventId: id })} | ||
> | ||
Download QR Code | ||
</Button> | ||
</Container> | ||
); | ||
}; |