| 1 |
import React, { useState } from 'react'; |
| 2 |
|
| 3 |
const ManualLocationInput = ({ onLocationSubmit, disabled }) => { |
| 4 |
const [input, setInput] = useState(''); |
| 5 |
|
| 6 |
const handleSubmit = (e) => { |
| 7 |
e.preventDefault(); |
| 8 |
const location = input.trim(); |
| 9 |
|
| 10 |
if (location) { |
| 11 |
// Parse the input - could be "City", "City, State", or "City, Country" |
| 12 |
const parts = location.split(',').map(p => p.trim()); |
| 13 |
|
| 14 |
onLocationSubmit({ |
| 15 |
city: parts[0], |
| 16 |
state: parts[1] || null, |
| 17 |
country: parts[2] || null |
| 18 |
}); |
| 19 |
|
| 20 |
setInput(''); |
| 21 |
} |
| 22 |
}; |
| 23 |
|
| 24 |
return ( |
| 25 |
<div className="manual-input"> |
| 26 |
<p>Can't detect location? Enter it manually:</p> |
| 27 |
<form onSubmit={handleSubmit}> |
| 28 |
<input |
| 29 |
type="text" |
| 30 |
value={input} |
| 31 |
onChange={(e) => setInput(e.target.value)} |
| 32 |
placeholder="Enter city or region" |
| 33 |
disabled={disabled} |
| 34 |
/> |
| 35 |
<button type="submit" disabled={disabled || !input.trim()}> |
| 36 |
Roast! 🎯 |
| 37 |
</button> |
| 38 |
</form> |
| 39 |
</div> |
| 40 |
); |
| 41 |
}; |
| 42 |
|
| 43 |
export default ManualLocationInput; |