Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/clear input button #151

Merged
merged 17 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.14.14",
"@mui/material": "^5.14.7",
"@mui/x-date-pickers": "^6.12.1",
"@types/leaflet.markercluster": "^1.5.2",
Expand Down
9 changes: 7 additions & 2 deletions src/pages/GapsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ const GapsPage = () => {
}, [operatorId, routeKey, timestamp])

useEffect(() => {
if (!operatorId || !lineNumber) {
if (!operatorId || operatorId === '0' || !lineNumber) {
setSearch((current) => ({
...current,
routes: undefined,
routeKey: undefined,
}))
return
}
getRoutesAsync(moment(timestamp), moment(timestamp), operatorId, lineNumber)
Expand Down Expand Up @@ -156,7 +161,7 @@ const GapsPage = () => {
)}
</Grid>
</Grid>
{!gapsIsLoading && routeKey && (
{!gapsIsLoading && routeKey && routeKey !== '0' && (
<>
<FormControlLabel
control={
Expand Down
31 changes: 17 additions & 14 deletions src/pages/GapsPatternsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ const GapsPatternsPage = () => {
}

useEffect(() => {
if (!operatorId || !lineNumber) {
if (!operatorId || operatorId === '0' || !lineNumber) {
setSearch((current) => ({ ...current, routeKey: undefined, routes: undefined }))
return
}
loadSearchData()
Expand Down Expand Up @@ -217,21 +218,23 @@ const GapsPatternsPage = () => {
(routes.length === 0 ? (
<NotFound>{TEXTS.line_not_found}</NotFound>
) : (
<RouteSelector
routes={routes}
routeKey={routeKey}
setRouteKey={(key) => setSearch((current) => ({ ...current, routeKey: key }))}
/>
<>
<RouteSelector
routes={routes}
routeKey={routeKey}
setRouteKey={(key) => setSearch((current) => ({ ...current, routeKey: key }))}
/>
<Grid xs={12}>
<GapsByHour
lineRef={routes?.find((route) => route.key === routeKey)?.lineRef || 0}
operatorRef={operatorId || ''}
fromDate={startDate}
toDate={endDate}
/>
</Grid>
</>
))}
</Grid>
<Grid xs={12}>
<GapsByHour
lineRef={routes?.find((route) => route.key === routeKey)?.lineRef || 0}
operatorRef={operatorId || ''}
fromDate={startDate}
toDate={endDate}
/>
</Grid>
</Grid>
</PageContainer>
)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/RealtimeMapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default function RealtimeMapPage() {
<MinuteSelector
num={to.diff(from) / 1000 / 60}
setNum={(num) => {
setTo(moment(from).add(Math.abs(+num) || 1, 'minutes'))
setTo(moment(from).add(Math.abs(+num) || 0, 'minutes'))
}}
/>
</Grid>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/SingleLineMapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const SingleLineMapPage = () => {
}, [])

useEffect(() => {
if (!operatorId || !lineNumber) {
if (!operatorId || operatorId === '0' || !lineNumber) {
setSearch((current) => ({ ...current, routes: undefined, routeKey: undefined }))
return
}
getRoutesAsync(moment(timestamp), moment(timestamp), operatorId, lineNumber).then((routes) =>
Expand Down
19 changes: 16 additions & 3 deletions src/pages/TimelinePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@ const TimelinePage = () => {
const [hitsIsLoading, setHitsIsLoading] = useState(false)

const clearRoutes = useCallback(() => {
setState((current) => ({ ...current, routes: undefined, routeKey: undefined }))
}, [setState])
setSearch((current) => ({ ...current, routes: undefined, routeKey: undefined }))
setRoutesIsLoading(false)
}, [setSearch])

const clearStops = useCallback(() => {
setState((current) => ({
...current,
stops: undefined,
stopName: undefined,
stopKey: undefined,
gtfsHitTimes: undefined,
siriHitTimes: undefined,
}))
setStopsIsLoading(false)
setHitsIsLoading(false)
}, [setState])

useEffect(() => {
Expand All @@ -58,7 +62,7 @@ const TimelinePage = () => {

useEffect(() => {
clearStops()
if (!operatorId || !lineNumber) {
if (!operatorId || operatorId === '0' || !lineNumber) {
return
}
setRoutesIsLoading(true)
Expand All @@ -79,6 +83,9 @@ const TimelinePage = () => {

useEffect(() => {
clearStops()
if (!operatorId || operatorId === '0' || !lineNumber) {
return
}
if (!routeKey || !selectedRouteIds) {
return
}
Expand All @@ -89,6 +96,9 @@ const TimelinePage = () => {
}, [selectedRouteIds, routeKey, clearStops])

useEffect(() => {
if (!operatorId || operatorId === '0' || !lineNumber) {
return
}
if (!stopKey || !stops || !selectedRoute) {
return
}
Expand All @@ -107,6 +117,9 @@ const TimelinePage = () => {
}, [stopKey, stops, timestamp, selectedRoute])

useEffect(() => {
if (!operatorId || operatorId === '0' || !lineNumber) {
return
}
if (!stopName || !stops || stopKey) {
return
}
Expand Down
21 changes: 21 additions & 0 deletions src/pages/components/ClearButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'
import ClearIcon from '@mui/icons-material/Clear'
ArkadiK94 marked this conversation as resolved.
Show resolved Hide resolved
import { IconButton } from '@mui/material'

const ClearButton = ({ onClearInput }: { onClearInput: () => void }) => {
return (
<IconButton
onClick={onClearInput}
size="small"
className="clearIndicatorDirty"
sx={{
visibility: 'hidden',
position: 'absolute',
right: '32px',
}}>
<ClearIcon fontSize="small" />
</IconButton>
)
}

export default ClearButton
17 changes: 15 additions & 2 deletions src/pages/components/LineSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback, useLayoutEffect, useState } from 'react'
import { TEXTS } from 'src/resources/texts'
import debounce from 'lodash.debounce'
import { TextField } from '@mui/material'
import ClearButton from './ClearButton'

type LineSelectorProps = {
lineNumber: string | undefined
Expand All @@ -16,12 +17,23 @@ const LineSelector = ({ lineNumber, setLineNumber }: LineSelectorProps) => {
setValue(lineNumber)
}, [])

const handleClearInput = () => {
setValue('')
setLineNumber('')
}

return (
<TextField
sx={{ width: '100%' }}
className="textInput"
sx={{
width: '100%',
'&:hover .clearIndicatorDirty, & .Mui-focused .clearIndicatorDirty': {
visibility: value ? 'visible' : 'hidden',
},
}}
label={TEXTS.choose_line}
type="number"
value={value}
value={value && +value < 0 ? 0 : value}
onChange={(e) => {
setValue(e.target.value)
debouncedSetLineNumber(e.target.value)
Expand All @@ -31,6 +43,7 @@ const LineSelector = ({ lineNumber, setLineNumber }: LineSelectorProps) => {
}}
InputProps={{
placeholder: TEXTS.line_placeholder,
endAdornment: <ClearButton onClearInput={handleClearInput} />,
}}
/>
)
Expand Down
15 changes: 14 additions & 1 deletion src/pages/components/MinuteSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
import React from 'react'
import { TEXTS } from 'src/resources/texts'
import { TextField } from '@mui/material'
import ClearButton from './ClearButton'

type MinuteSelectorProps = {
num: number
setNum: (num: string) => void
}

const MinuteSelector = ({ num, setNum }: MinuteSelectorProps) => {
const handleClearInput = () => {
setNum('0')
ArkadiK94 marked this conversation as resolved.
Show resolved Hide resolved
}

return (
<TextField
sx={{ width: '100%' }}
sx={{
width: '100%',
'&:hover .clearIndicatorDirty , & .Mui-focused .clearIndicatorDirty ': {
visibility: num ? 'visible' : 'hidden',
},
}}
ArkadiK94 marked this conversation as resolved.
Show resolved Hide resolved
label={TEXTS.minutes}
type="number"
value={num}
onChange={(e) => setNum(e.target.value)}
InputLabelProps={{
shrink: true,
}}
InputProps={{
endAdornment: <ClearButton onClearInput={handleClearInput} />,
}}
/>
)
}
Expand Down
Loading
Loading