-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show location on map when editing a review
* Rename id to locationId and reviewId * Toast errors when getting review/location fails * Pull locationId through redux into MapPage and show the marker (#386) The side pane and map components are only loosely coupled and make use of global state through redux. Extend this design instead of storing review id in the URL like the previous attempt.
- Loading branch information
Showing
14 changed files
with
180 additions
and
124 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useEffect, useState } from 'react' | ||
import { useParams } from 'react-router-dom' | ||
import { toast } from 'react-toastify' | ||
|
||
import { getLocationById } from '../../utils/api' | ||
import { useAppHistory } from '../../utils/useAppHistory' | ||
import { Page } from '../entry/Entry' | ||
import { LocationForm, locationToForm } from './LocationForm' | ||
|
||
export const EditLocationForm = (props) => { | ||
const { locationId } = useParams() | ||
const history = useAppHistory() | ||
const [location, setLocation] = useState(null) | ||
|
||
useEffect(() => { | ||
const loadFormData = async () => { | ||
try { | ||
const location = await getLocationById(locationId) | ||
setLocation(location) | ||
} catch (error) { | ||
toast.error(`Location #${locationId} not found`) | ||
} | ||
} | ||
|
||
loadFormData() | ||
}, [locationId]) | ||
|
||
const handleSubmit = () => { | ||
if (location) { | ||
history.push(`/locations/${location.id}`) | ||
} | ||
} | ||
|
||
return ( | ||
location && ( | ||
<LocationForm | ||
initialValues={locationToForm(location)} | ||
editingId={locationId} | ||
onSubmit={handleSubmit} | ||
{...props} | ||
/> | ||
) | ||
) | ||
} | ||
|
||
export const EditLocationPage = () => ( | ||
<Page> | ||
<h3 style={{ marginLeft: 10 }}>Editing Location</h3> | ||
<EditLocationForm /> | ||
</Page> | ||
) |
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,61 @@ | ||
import { useEffect, useState } from 'react' | ||
import { useDispatch } from 'react-redux' | ||
import { useParams } from 'react-router-dom' | ||
import { toast } from 'react-toastify' | ||
|
||
import { rememberLocationIdForReviewId } from '../../redux/miscSlice' | ||
import { getReviewById } from '../../utils/api' | ||
import { useAppHistory } from '../../utils/useAppHistory' | ||
import { Page } from '../entry/Entry' | ||
import { ReviewForm, reviewToForm } from './ReviewForm' | ||
|
||
export const EditReviewForm = (props) => { | ||
const { reviewId } = useParams() | ||
const history = useAppHistory() | ||
const dispatch = useDispatch() | ||
const [review, setReview] = useState(null) | ||
|
||
useEffect(() => { | ||
const loadFormData = async () => { | ||
try { | ||
const review = await getReviewById(reviewId) | ||
dispatch( | ||
rememberLocationIdForReviewId({ | ||
reviewId, | ||
locationId: review.location_id, | ||
}), | ||
) | ||
setReview(review) | ||
} catch (error) { | ||
toast.error(`Review #${reviewId} not found`) | ||
} | ||
} | ||
|
||
loadFormData() | ||
}, [reviewId, dispatch]) | ||
|
||
const afterSubmit = () => { | ||
if (review) { | ||
history.push(`/locations/${review.location_id}`) | ||
} | ||
} | ||
return ( | ||
review && ( | ||
<ReviewForm | ||
initialValues={{ review: reviewToForm(review) }} | ||
editingId={reviewId} | ||
onSubmit={afterSubmit} | ||
{...props} | ||
/> | ||
) | ||
) | ||
} | ||
|
||
export const EditReviewPage = () => ( | ||
<Page> | ||
<div style={{ paddingLeft: 10, paddingRight: 10 }}> | ||
<h3>Editing My Review</h3> | ||
<EditReviewForm /> | ||
</div> | ||
</Page> | ||
) |
This file was deleted.
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
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
Oops, something went wrong.