Skip to content

Commit

Permalink
add place qrcode
Browse files Browse the repository at this point in the history
  • Loading branch information
aeltorio committed Jun 29, 2024
1 parent 69cf9f8 commit 654a692
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Tabs from './Components/Tabs'
import TextForm from './Components/Forms/Text'
import UrlForm from './Components/Forms/Url'
import SmsForm from './Components/Forms/Sms'
import GeoForm from './Components/Forms/Geo'
import TelForm from './Components/Forms/Tel'
import EmailForm from './Components/Forms/Email'
import VCardForm from './Components/Forms/VCard'
Expand All @@ -32,6 +33,10 @@ const tabs = [
label: 'VCard',
Component: VCardForm
},
{
label: 'Place',
Component: GeoForm
},
{
label: 'WiFi',
Component: WiFiForm
Expand Down
62 changes: 62 additions & 0 deletions src/Components/Forms/Geo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React, { useState, useContext } from 'react'
import { AppContext } from '../../Context'
import Submit from '../Submit'

const initialValues = {
latitude: '45.926436',
longitude: '6.8676'
}
function GeoForm() {
const [values, setValues] = useState(initialValues)
const { qrCode } = useContext(AppContext)

const handleChange = (event: React.ChangeEvent<HTMLInputElement & HTMLSelectElement>) => {
const { name, value, checked } = event.target
const type:React.HTMLInputTypeAttribute = event.target.type

setValues((prev) => ({
...prev,
[name]: type === 'checkbox' as React.HTMLInputTypeAttribute ? checked : value
}))
}

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault()

qrCode.update({
data: `GEO:${values.latitude},${values.longitude}`
})
}

return (
<form className='qrForm-url' onSubmit={handleSubmit}>
<div className='form-floating mb-3'>
<input
id='latitude'
className='form-control'
type='number'
name='latitude'
value={values.latitude}
onChange={handleChange}
placeholder='Latitude (in decimal)'
required
/>
<label htmlFor='number'>Latitude (in decimal)</label>
<input
id='longitude'
className='form-control'
type='text'
name='longitude'
value={values.longitude}
onChange={handleChange}
placeholder='Longitude (in decimal)'
required
/>
<label htmlFor='longitude'>Longitude (in decimal)</label>
</div>
<Submit />
</form>
)
}

export default GeoForm

0 comments on commit 654a692

Please sign in to comment.