Skip to content

Commit 48c46c9

Browse files
authored
refactor: widget and selectors (#1090)
1 parent a5cd05b commit 48c46c9

File tree

10 files changed

+26
-20
lines changed

10 files changed

+26
-20
lines changed

src/pages/about/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const Contributors = () => {
188188
const { contributors, isLoading, isError } = useContributions()
189189

190190
return (
191-
<Widget>
191+
<Widget marginBottom>
192192
<h2>{t('aboutPage.contributors')}</h2>
193193
<p>
194194
{t('aboutPage.contributorsText')}

src/pages/components/OperatorSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function OperatorSelector({
2323
getOperators(filter).then(setOperators)
2424
}, [filter])
2525

26-
const value = operators.find((operator) => operator.id === operatorId)
26+
const value = operators.find((operator) => operator.id === operatorId) || null
2727

2828
return (
2929
<Autocomplete

src/pages/components/RouteSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const getRouteTitle = (route: BusRoute, t: TFunction<'translation', undefined>)
2121

2222
const RouteSelector = ({ routes, routeKey, disabled, setRouteKey }: RouteSelectorProps) => {
2323
const { t } = useTranslation()
24-
const value = routes.find((route) => route.key === routeKey)
24+
const value = routes.find((route) => route.key === routeKey) || null
2525

2626
useEffect(() => {
2727
routes.sort((a, b) => {

src/pages/components/StopSelector.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ type StopSelectorProps = {
1010
}
1111

1212
const StopSelector = ({ stops, stopKey, setStopKey }: StopSelectorProps) => {
13-
const valueFinned = stops.find((stop) => stop.key === stopKey)
14-
const value = valueFinned ? valueFinned : null
13+
const value = stops.find((stop) => stop.key === stopKey) || null
1514
const { t } = useTranslation()
1615

1716
return (
1817
<Autocomplete
1918
disablePortal
2019
value={value}
21-
onChange={(e, value) => setStopKey(value ? value.key : '0')}
20+
onChange={(e, value) => setStopKey(value ? value.key : '')}
2221
id="stop-select"
2322
options={stops}
2423
renderInput={(params) => (
2524
<TextField {...params} label={formatted(t('choose_stop'), stops.length.toString())} />
2625
)}
2726
getOptionLabel={(stop) => stop.name}
27+
getOptionKey={(stop) => stop.key}
2828
/>
2929
)
3030
}

src/pages/dashboard/ArrivalByTimeChart/DayTimeChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const DayTimeChart: FC<DayTimeChartProps> = ({ startDate, endDate, operatorId })
4040
)
4141

4242
return (
43-
<Widget>
43+
<Widget marginBottom>
4444
<h2 className="title">
4545
{groupByHour ? t('dashboard_page_graph_title_hour') : t('dashboard_page_graph_title_day')}
4646
</h2>

src/pages/gapsPatterns/GapsPatternsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function GapsByHour({ lineRef, operatorRef, fromDate, toDate }: BusLineStatistic
7171

7272
return (
7373
lineRef > 0 && (
74-
<Widget>
74+
<Widget marginBottom>
7575
{isLoading && lineRef ? (
7676
<Skeleton active />
7777
) : (

src/pages/publicAppeal/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ const PublicAppeal = () => {
1717
{t(`${pageName}.title`)}
1818
</Title>
1919
{tasks.map((task, i) => (
20-
<Task title={task.title} description={task.description} index={i} key={i} />
20+
<Task {...task} marginBottom={tasks.length - 1 === i} key={i} />
2121
))}
2222
</Space>
2323
</PublicAppealStyle>
2424
)
2525
}
2626

2727
type TaskDetails = {
28-
index: number
2928
title: string
3029
description: string
30+
marginBottom?: boolean
3131
}
3232

33-
const Task = ({ index, title, description }: TaskDetails) => {
33+
const Task = ({ title, description, marginBottom }: TaskDetails) => {
3434
return (
35-
<Widget key={index}>
35+
<Widget marginBottom={marginBottom}>
3636
<h2 className="public">{title}</h2>
3737
<p>{description}</p>
3838
<a href="https://open-bus-stride-api.hasadna.org.il/docs">Open Bus Stride API</a>

src/pages/singleLineMap/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ const SingleLineMapPage = () => {
4545
}))
4646
})
4747
.catch((err) => {
48-
console.error(err)
49-
setSearch((current) => ({ ...current, routes: undefined, routeKey: undefined }))
48+
if (err?.cause?.name !== 'AbortError') {
49+
setSearch((current) => ({ ...current, routes: undefined, routeKey: undefined }))
50+
}
5051
})
5152

5253
return () => controller.abort()

src/shared/Widget.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { Card, CardContent } from '@mui/material'
22
import cn from 'classnames'
3-
43
import { useTheme } from 'src/layout/ThemeContext'
54

6-
const Widget = (props: { children?: React.ReactNode }) => {
5+
const Widget = ({
6+
marginBottom,
7+
children,
8+
}: {
9+
marginBottom?: boolean
10+
children?: React.ReactNode
11+
}) => {
712
const { isDarkTheme } = useTheme()
813
return (
9-
<Card className={cn('card widget', { dark: isDarkTheme })}>
10-
<CardContent>{props.children} </CardContent>
14+
<Card className={cn('card widget', { dark: isDarkTheme, marginBottom })}>
15+
<CardContent>{children}</CardContent>
1116
</Card>
1217
)
1318
}

src/shared/shared.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
border-radius: 4px;
33
}
44

5-
.widget:last-of-type {
6-
margin-bottom: 20px;
5+
.widget.marginBottom {
6+
margin-bottom: 16px;
77
}
88

99
.card.dark {

0 commit comments

Comments
 (0)