Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/connect/ConnectLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const LessPaddingButton = styled(Button)`
padding: 0 10px;
`

const ToastContent = () => {
const ToastContent = ({ location }) => {
const { t } = useTranslation()
const history = useAppHistory()
const dispatch = useDispatch()
Expand Down Expand Up @@ -57,7 +57,7 @@ const ToastContent = () => {
<LessPaddingButton
type="button"
onClick={() => {
dispatch(duplicateIntoNewLocation())
dispatch(duplicateIntoNewLocation(location))
history.push(`/locations/init`)
}}
>
Expand Down Expand Up @@ -225,7 +225,7 @@ const ConnectLocation = ({
}
} else if (isSuccessfullyAdded) {
toastIdRef.current = toast.success(
<ToastContent locationId={locationId} />,
<ToastContent locationId={locationId} location={location} />,
{
autoClose: false,
style: { width: '100%' },
Expand Down
8 changes: 7 additions & 1 deletion src/components/connect/ConnectNewLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ const ConnectNewLocation = () => {
// Should only happen for an artificially constructed URL
history.push('/map')
}
}, [dispatch, locationId, hasInitialView, isDesktop]) //eslint-disable-line
/*
* Mount-only: after a successful submit, locationId changes from 'new' to

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment helped me understand how the change worked, thanks! I'm trying to keep the codebase relatively comment free. Can we take it out before merging? Maybe see if the doc in connectRoutes.js needs revising.

* the new location's id while this component is still mounted. Re-running
* would call initNewLocation and wipe the just-added location from Redux,
* which the success page and 'Add similar' still need.
*/
}, []) //eslint-disable-line
return null
}

Expand Down
10 changes: 9 additions & 1 deletion src/redux/locationSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@ const locationSlice = createSlice({
clearLocation: (state) => {
Object.assign(state, initialState)
},
duplicateIntoNewLocation: (state) => {
duplicateIntoNewLocation: (state, action) => {
/*
* The location captured when the success toast was created. Restore it
* in case something (e.g. the mobile drawer closing through /map)
* cleared the slice before the user tapped 'Add similar'.
*/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you check if changing the effect array in ConnectNewLocation is enough? This might not be necessary.

if (action.payload) {
state.location = action.payload
}
state.isLoading = false
state.isBeingEdited = false
state.locationId = 'new'
Expand Down