Skip to content

Commit 6402fc9

Browse files
committed
feat: sort timezones by city
1 parent ecb3a3a commit 6402fc9

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

src/App.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ import { GlobalStyle } from './style/Global'
77
import { Schedule } from './Schedule'
88
import { format } from 'date-fns'
99
import { ThemeProvider } from 'styled-components'
10-
import { Button, Input, DateEditor, StyledDaySelector } from './style/Form'
10+
import {
11+
Button,
12+
Input,
13+
DateEditor,
14+
StyledDaySelector,
15+
StyledTimeZoneSelector,
16+
} from './style/Form'
1117
import { Editor } from './Editor'
1218
import { ThemeSwitcher } from './ThemeSwitcher'
13-
import { TimeZoneSelector } from './timezones'
1419

1520
import LockIcon from 'feather-icons/dist/icons/lock.svg'
1621
import UnLockIcon from 'feather-icons/dist/icons/unlock.svg'
@@ -99,7 +104,7 @@ export const App = () => {
99104
onChange={({ target: { value } }) => updateName(value)}
100105
/>
101106
<StyledDaySelector day={updatedDay} onUpdate={updateDay} />
102-
<TimeZoneSelector
107+
<StyledTimeZoneSelector
103108
value={updatedTimeZone}
104109
onChange={({ target: { value } }) => updateTimeZone(value)}
105110
/>

src/style/Form.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import styled from 'styled-components'
22
import { DaySelector } from '../DaySelector'
3+
import { TimeZoneSelector } from '../timezones'
34
import { wideBreakpoint, mobileBreakpoint } from './settings'
45

56
export const Button = styled.button`
@@ -46,6 +47,18 @@ export const StyledDaySelector = styled(DaySelector)`
4647
}
4748
`
4849

50+
export const StyledTimeZoneSelector = styled(TimeZoneSelector)`
51+
background-color: transparent;
52+
border: 1px solid ${(props) => props.theme.colors.text};
53+
padding: 0.25rem 0.5rem;
54+
height: 40px;
55+
color: ${(props) => props.theme.colors.text};
56+
option {
57+
color: black;
58+
}
59+
margin: 0;
60+
`
61+
4962
export const NumberInput = styled(Input)`
5063
width: 30px;
5164
@media (min-width: ${mobileBreakpoint}) {
@@ -57,17 +70,7 @@ export const DateEditor = styled.div`
5770
display: flex;
5871
flex-direction: column;
5972
align-items: center;
60-
select {
61-
height: 30px;
62-
}
63-
${Input} + ${Input}, ${Input} + select {
64-
margin-top: 0.5rem;
65-
}
6673
@media (min-width: ${wideBreakpoint}) {
6774
flex-direction: row;
68-
${Input} + ${Input}, ${Input} + select {
69-
margin-left: 0.5rem;
70-
margin-top: 0;
71-
}
7275
}
7376
`

src/timezones.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export const timezones = [
349349
'Pacific/Tongatapu',
350350
'Pacific/Wake',
351351
'Pacific/Wallis',
352-
] as const
352+
]
353353

354354
export const TimeZoneSelector = (
355355
props: React.DetailedHTMLProps<
@@ -358,8 +358,19 @@ export const TimeZoneSelector = (
358358
>,
359359
) => (
360360
<select {...props}>
361-
{timezones.map((tz) => (
362-
<option key={tz}>{tz}</option>
363-
))}
361+
{timezones
362+
.sort((a, b) => {
363+
const [, a2, a3] = a.split('/')
364+
const [, b2, b3] = b.split('/')
365+
return (a3 ?? a2).localeCompare(b3 ?? b2)
366+
})
367+
.map((tz) => {
368+
const [t1, t2, t3] = tz.split('/')
369+
return (
370+
<option key={tz} value={tz}>
371+
{t3 ?? t2} ({t3 === undefined ? t1 : `${t1}/${t2}`})
372+
</option>
373+
)
374+
})}
364375
</select>
365376
)

0 commit comments

Comments
 (0)