Fixed location editor
This commit is contained in:
1 parent
4869756957
commit
ac4b50293e
3 files changed
+38
-22
No files matched your search
+35
-22
@@ -288,6 +288,7 @@ type FlockNoteFormState = {
|
||||
};
|
||||
|
||||
type BirdFormState = {
|
||||
locationDate: string;
|
||||
name: string;
|
||||
tagId: string;
|
||||
species: string;
|
||||
@@ -841,6 +842,7 @@ const VerifiedLocationSearchField = ({
|
||||
};
|
||||
|
||||
const emptyBirdForm: BirdFormState = {
|
||||
locationDate: '',
|
||||
name: '',
|
||||
tagId: '',
|
||||
species: '',
|
||||
@@ -1007,6 +1009,7 @@ const ProviderIcon = ({ providerKey }: { providerKey: AuthProvider['providerKey'
|
||||
const sortBirdsByName = (nextBirds: Bird[]) => [...nextBirds].sort((left, right) => left.name.localeCompare(right.name));
|
||||
|
||||
const toBirdForm = (bird: Bird): BirdFormState => ({
|
||||
locationDate: '',
|
||||
name: bird.name,
|
||||
tagId: bird.tagId ?? '',
|
||||
species: bird.species,
|
||||
@@ -4302,7 +4305,7 @@ function App() {
|
||||
const response = await apiFetch(isEditing ? `/birds/${editingBirdId}` : '/birds', authToken, {
|
||||
method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ...birdForm, hatchDay: birdForm.dateOfBirth, locationLabel }),
|
||||
body: JSON.stringify({ ...birdForm, hatchDay: birdForm.dateOfBirth, locationLabel, locationDate: birdForm.locationDate || getLocalDateString() }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -7130,27 +7133,6 @@ function App() {
|
||||
) : null}
|
||||
</div>
|
||||
</label>
|
||||
<div className="settings-inline-header wide-field">
|
||||
<p className="eyebrow">Location</p>
|
||||
<h3>Mappable location</h3>
|
||||
</div>
|
||||
<VerifiedLocationSearchField
|
||||
label="Location"
|
||||
location={birdForm.locationDetails}
|
||||
fallbackLabel={birdForm.locationLabel}
|
||||
searchState={birdLocationSearch}
|
||||
onSearchStateChange={setBirdLocationSearch}
|
||||
onSearch={() => searchVerifiedLocations(birdLocationSearch, setBirdLocationSearch)}
|
||||
onSelect={(location) => {
|
||||
const locationLabel = formatVerifiedLocationLabel(location);
|
||||
setBirdForm({ ...birdForm, locationDetails: location, locationLabel });
|
||||
setBirdLocationSearch({ ...emptyLocationSearchState, query: locationLabel });
|
||||
}}
|
||||
onClear={() => {
|
||||
setBirdForm({ ...birdForm, locationDetails: emptyVerifiedLocationDetails, locationLabel: '' });
|
||||
setBirdLocationSearch(emptyLocationSearchState);
|
||||
}}
|
||||
/>
|
||||
<div className="segmented-field wide-field">
|
||||
<span>Gender</span>
|
||||
<div className="segmented-control" role="radiogroup" aria-label="Bird gender">
|
||||
@@ -7289,6 +7271,37 @@ function App() {
|
||||
))}
|
||||
</div>
|
||||
</label>
|
||||
<div className="settings-inline-header wide-field">
|
||||
<p className="eyebrow">Location</p>
|
||||
<h3>Mappable location</h3>
|
||||
</div>
|
||||
<VerifiedLocationSearchField
|
||||
label="Location"
|
||||
location={birdForm.locationDetails}
|
||||
fallbackLabel={birdForm.locationLabel}
|
||||
searchState={birdLocationSearch}
|
||||
onSearchStateChange={setBirdLocationSearch}
|
||||
onSearch={() => searchVerifiedLocations(birdLocationSearch, setBirdLocationSearch)}
|
||||
onSelect={(location) => {
|
||||
const locationLabel = formatVerifiedLocationLabel(location);
|
||||
setBirdForm({ ...birdForm, locationDetails: location, locationLabel });
|
||||
setBirdLocationSearch({ ...emptyLocationSearchState, query: locationLabel });
|
||||
}}
|
||||
onClear={() => {
|
||||
setBirdForm({ ...birdForm, locationDetails: emptyVerifiedLocationDetails, locationLabel: '' });
|
||||
setBirdLocationSearch(emptyLocationSearchState);
|
||||
}}
|
||||
/>
|
||||
<label>
|
||||
Location date
|
||||
<input
|
||||
type="date"
|
||||
value={birdForm.locationDate || getLocalDateString()}
|
||||
onChange={(event) => setBirdForm({ ...birdForm, locationDate: event.target.value })}
|
||||
required
|
||||
/>
|
||||
<span className="muted">Date this location took effect. Used when adding a bird or changing its location.</span>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
<section className="settings-nested-card">
|
||||
|
||||
Reference in new issue
Block a user