Skip to content

Commit

Permalink
Merge branch 'main' into feature/falling-fruit#495-change-outdated-tw…
Browse files Browse the repository at this point in the history
…itter-logo
  • Loading branch information
ahmedhalac committed Nov 15, 2024
2 parents dc4fb56 + f79ae73 commit ed37f3a
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 38 deletions.
13 changes: 13 additions & 0 deletions src/components/auth/LoginPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ const LoginPage = () => {
})}
onSubmit={(values, { setSubmitting }) => {
dispatch(login(values))
.unwrap()
.catch((error) => {
// Here, set the error message based on the error received
setStatus(
'general',
`Sign in failed: ${
error.message || 'Unexpected error occurred'
}`,
)
})
.finally(() => {
setSubmitting(false)
})
setSubmitting(false)
}}
>
Expand Down
30 changes: 30 additions & 0 deletions src/components/connect/ConnectInitLocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useEffect } from 'react'
import { useDispatch } from 'react-redux'
import { useLocation } from 'react-router-dom'

import { setIsBeingInitializedMobile } from '../../redux/locationSlice'
import { useAppHistory } from '../../utils/useAppHistory'
import { useIsDesktop } from '../../utils/useBreakpoint'

const ConnectInitLocation = () => {
const isDesktop = useIsDesktop()
const history = useAppHistory()
const dispatch = useDispatch()
const location = useLocation()
const isSettingsPage = location.pathname.startsWith('/settings')

useEffect(() => {
if (!isSettingsPage) {
if (isDesktop) {
history.push('/locations/new')
return
}

dispatch(setIsBeingInitializedMobile(true))
}
}, [history, isDesktop, dispatch, isSettingsPage])

return null
}

export default ConnectInitLocation
3 changes: 1 addition & 2 deletions src/components/connect/ConnectMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useDispatch, useSelector } from 'react-redux'

import { setInitialView } from '../../redux/mapSlice'
import { parseCurrentUrl } from '../../utils/appUrl'
import ConnectPath from './ConnectPath'

const DEFAULT_LAT = 40.1125785
const DEFAULT_LNG = -88.2287926
Expand All @@ -25,7 +24,7 @@ const ConnectMap = () => {
}
}, [dispatch, hasInitialView]) //eslint-disable-line

return <ConnectPath />
return null
}

export default ConnectMap
16 changes: 16 additions & 0 deletions src/components/connect/DisconnectInitLocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useEffect } from 'react'
import { useDispatch } from 'react-redux'

import { setIsBeingInitializedMobile } from '../../redux/locationSlice'

const DisconnectInitLocation = () => {
const dispatch = useDispatch()

useEffect(() => {
dispatch(setIsBeingInitializedMobile(false))
}, [dispatch])

return null
}

export default DisconnectInitLocation
33 changes: 30 additions & 3 deletions src/components/connect/connectRoutes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Route } from 'react-router-dom'

import ConnectInitLocation from './ConnectInitLocation'
import ConnectList from './ConnectList'
import ConnectLocation from './ConnectLocation'
import ConnectMap from './ConnectMap'
Expand All @@ -8,6 +9,7 @@ import ConnectOverscroll from './ConnectOverscroll'
import ConnectPath from './ConnectPath'
import ConnectReview from './ConnectReview'
import ConnectTypes from './ConnectTypes'
import DisconnectInitLocation from './DisconnectInitLocation'
import DisconnectLocation from './DisconnectLocation'
import DisconnectReview from './DisconnectReview'

Expand Down Expand Up @@ -35,7 +37,7 @@ const connectRoutes = [
* - get the view from URL or default to our chosen location centred on U of Illinois
* - if this is the first render, dispatch a Redux update
*/
<Route key="connect-view" path={['/map', '/settings']}>
<Route key="connect-view" path={['/map', '/settings', '/locations/init']}>
<ConnectMap />
</Route>,
/*
Expand Down Expand Up @@ -63,6 +65,20 @@ const connectRoutes = [
<Route key="connect-new-location" path="/locations/new">
<ConnectNewLocation />
</Route>,
/*
* ConnectInitLocation
* why:
* - mobile only URL
* - map needs to know we're in this state rather than generic map state
*
*
* actions:
* - if on desktop because of screen resize, go to /locations/new
* - set a flag in redux
*/
<Route key="connect-init-location" path={['/locations/init', '/settings']}>
<ConnectInitLocation />
</Route>,
/*
* ConnectLocation
* why:
Expand Down Expand Up @@ -95,7 +111,8 @@ const connectRoutes = [
>
{({ match }) =>
match &&
match.params.locationId !== 'new' && (
match.params.locationId !== 'new' &&
match.params.locationId !== 'init' && (
<ConnectLocation
locationId={match.params.locationId}
isBeingEdited={match.params.nextSegment === 'edit'}
Expand Down Expand Up @@ -137,7 +154,7 @@ const connectRoutes = [
*
* action: clear location in Redux
*/
<Route key="disconnect-location" path={['/map']}>
<Route key="disconnect-location" path={['/map', '/locations/init']}>
{({ match }) => match && <DisconnectLocation />}
</Route>,
/*
Expand Down Expand Up @@ -174,6 +191,16 @@ const connectRoutes = [
<Route key="disconnect-review" path={['/map', '/locations']}>
{({ match }) => match && <DisconnectReview />}
</Route>,

/*
* DisconnectInitLocation
* why: need to clear the mobile initialization state when navigating to main views
*
* action: clear isBeingInitializedMobile in Redux when on /map or /list
*/
<Route key="disconnect-init-location" path={['/map', '/list']}>
<DisconnectInitLocation />
</Route>,
]

export default connectRoutes
4 changes: 3 additions & 1 deletion src/components/desktop/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ const StyledHeader = styled.header`
color: ${({ theme }) => theme.orange};
}
}
.signin,
.signup {
min-width: auto;
}
}
}
`

const Dropdown = ({ className, children, label, isMatch }) => (
<div className={className}>
<div className={`button${isMatch ? ' active' : ''}`}>
Expand Down
15 changes: 8 additions & 7 deletions src/components/list/Locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import { ReactComponent as LeafIcon } from './leaf.svg'

const TypeNameTagWrapper = styled.span`
display: inline-block;
margin-right: 1em;
margin-bottom: 0.5em;
opacity: ${({ isSelected }) => (isSelected ? 1 : 0.5)};
font-size: 0.875rem;
&:not(:nth-last-child(2))::after {
content: '·';
margin: 0 0.5em;
color: ${({ theme }) => theme.secondaryText};
}
`
const CommonName = styled.span`
font-weight: bold;
Expand All @@ -25,16 +30,12 @@ const ScientificName = styled.span`
color: ${({ theme }) => theme.secondaryText};
`

const TypeNameWrapper = styled.div`
font-size: 0.875rem;
`

const TypeName = ({ commonName, scientificName }) => (
<TypeNameWrapper>
<span>
{commonName && <CommonName>{commonName}</CommonName>}
{commonName && scientificName && <span style={{ margin: '0 0.25em' }} />}
{scientificName && <ScientificName>{scientificName}</ScientificName>}
</TypeNameWrapper>
</span>
)

const LocationItem = styled.li`
Expand Down
11 changes: 7 additions & 4 deletions src/components/map/MapPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const MapPage = ({ isDesktop }) => {
location: selectedLocation,
isLoading: locationIsLoading,
streetViewOpen: showStreetView,
isBeingInitializedMobile,
} = useSelector((state) => state.location)
const {
mapType,
Expand All @@ -195,7 +196,7 @@ const MapPage = ({ isDesktop }) => {
)
: locations

const isAddingLocation = locationId === 'new'
const isAddingLocation = locationId === 'new' || isBeingInitializedMobile
const isViewingLocation =
locationId !== null && !isEditingLocation && !isAddingLocation
const showLabels = settingsShowLabels || isAddingLocation || isEditingLocation
Expand Down Expand Up @@ -264,7 +265,7 @@ const MapPage = ({ isDesktop }) => {

const handleAddLocationClick = () => {
if (currentZoom >= VISIBLE_CLUSTER_ZOOM_LIMIT) {
history.push('/locations/new')
history.push('/locations/init')
} else {
toast.info(t('menu.zoom_in_to_add_location'))
}
Expand Down Expand Up @@ -293,7 +294,7 @@ const MapPage = ({ isDesktop }) => {
>
{(mapIsLoading || locationIsLoading) && <BottomLeftLoadingIndicator />}
{isAddingLocation && !isDesktop && <AddLocationCentralUnmovablePin />}
{!locationId && !isDesktop && (
{!isAddingLocation && !isEditingLocation && !isDesktop && (
<AddLocationButton onClick={handleAddLocationClick} />
)}
{isEditingLocation && !isDesktop && <EditLocationCentralUnmovablePin />}
Expand Down Expand Up @@ -428,7 +429,9 @@ const MapPage = ({ isDesktop }) => {
// confusingly it doesn't work from inside the component
$geoService={getGoogleMaps && getGoogleMaps().Geocoder}
onChange={setDraggedPosition}
onDragEnd={(newPosition) => dispatch(updatePosition(newPosition))}
onDragEnd={(newPosition) => {
dispatch(updatePosition(newPosition))
}}
/>
)}
</GoogleMapReact>
Expand Down
8 changes: 4 additions & 4 deletions src/components/mobile/LocationNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ const LocationNav = () => {
path="/locations/:locationId/edit/position"
component={LocationPositionNav}
/>
<Route path="/locations/new/details">
<Route path="/locations/new">
<TopBarNav
onBack={() => history.push('/locations/new')}
onBack={() => history.push('/locations/init')}
title="New location"
/>
</Route>
<Route path="/locations/new">
<Route path="/locations/init">
<TopBarNav
left={
<Instructions>
Expand All @@ -81,7 +81,7 @@ const LocationNav = () => {
raised
size={54}
color={theme.green}
onClick={() => history.push('/locations/new/details')}
onClick={() => history.push('/locations/new')}
/>
</>
}
Expand Down
10 changes: 4 additions & 6 deletions src/components/mobile/MobileLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ const shouldDisplayMapPage = (pathname) => {
strict: false,
})

const isPlacingNewLocationMarker =
match?.params.locationId === 'new' &&
match?.params.nextSegment !== 'details'
const isPlacingNewLocationMarker = match?.params.locationId === 'init'

const locationId =
match?.params.locationId && parseInt(match.params.locationId)
Expand Down Expand Up @@ -104,12 +102,12 @@ const MobileLayout = () => {
<EditLocationForm editingId={match.params.locationId} />
)}
</Route>
<Route path="/locations/new/details">
<Route path="/locations/new">
<LocationForm />
</Route>
<Route path={['/map', '/locations', '/list', '/settings']}>
<Switch>
<Route path="/locations/new" />
<Route path="/locations/init" />
<Route path="/locations/:locationId/edit/position" />
<Route path="/locations/:locationId">
{!streetView && <EntryMobile />}
Expand All @@ -135,7 +133,7 @@ const MobileLayout = () => {
'/reviews/:reviewId/edit',
'/locations/:locationId/review',
'/locations/:locationId/edit/details',
'/locations/new/details',
'/locations/new',
]}
/>
<Route>
Expand Down
13 changes: 8 additions & 5 deletions src/components/mobile/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ const Tabs = () => {
const { t } = useTranslation()
const { pathname } = useLocation()
const history = useAppHistory()
const { locationId, isBeingEdited, streetViewOpen } = useSelector(
(state) => state.location,
)
const {
isBeingInitializedMobile,
locationId,
isBeingEdited,
streetViewOpen,
} = useSelector((state) => state.location)
const isLoggedIn = useSelector((state) => !!state.auth.user)

const tabs = [
Expand Down Expand Up @@ -71,10 +74,10 @@ const Tabs = () => {
}, [pathname])

const handleTabChange = (newTabIndex) => {
if (newTabIndex === 1 && locationId === 'new') {
if (newTabIndex === 1 && isBeingInitializedMobile) {
// If switching to the Map tab and adding the location, reopen that view
// to allow e.g. switching satellite view on
history.push(`/locations/new`)
history.push(`/locations/init`)
} else if (newTabIndex === 1 && locationId && isBeingEdited) {
// We could also be editing position of the location
history.push(`/locations/${locationId}/edit/position`)
Expand Down
1 change: 1 addition & 0 deletions src/components/mobile/TopBarSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const TopBarSwitch = () => (
'/locations/:locationId/review',
'/locations/:locationId/edit',
'/locations/new',
'/locations/init',
]}
>
<TopBar>
Expand Down
Loading

0 comments on commit ed37f3a

Please sign in to comment.