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

Fix inputs design direction #53

Merged
merged 6 commits into from
Sep 18, 2023
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"recharts": "^2.4.3",
"sass": "^1.58.3",
"styled-components": "^5.3.5",
"stylis-plugin-rtl": "^2.1.1",
"typescript": "^4.7.4",
"underscore.string": "^3.3.6",
"usehooks-ts": "^2.9.1",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="he" dir="rtl">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
Expand Down
89 changes: 57 additions & 32 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ import RealtimeMapPage from './pages/RealtimeMapPage'
import SingleLineMapPage from './pages/SingleLineMapPage'
import { useLocation } from 'react-router-dom'
import ReactGA from 'react-ga4'
import { LocalizationProvider } from '@mui/x-date-pickers'
import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment'
import { CacheProvider } from '@emotion/react'
import createCache from '@emotion/cache'
import rtlPlugin from 'stylis-plugin-rtl'
import 'moment/locale/he'
import { heIL as heILmui } from '@mui/x-date-pickers/locales'
import { ThemeProvider, createTheme } from '@mui/material'
import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment'
import { LocalizationProvider } from '@mui/x-date-pickers'
import About from './pages/About'

const { Content } = Layout
Expand Down Expand Up @@ -73,12 +78,22 @@ const PAGES = [
},
]

const theme = createTheme({
palette: {
primary: {
main: '#5f5bff',
const theme = createTheme(
{
direction: 'rtl',
palette: {
primary: {
main: '#5f5bff',
},
},
},
heILmui,
)

// Create rtl cache
const cacheRtl = createCache({
key: 'muirtl',
stylisPlugins: [rtlPlugin],
})

const App = () => {
Expand Down Expand Up @@ -118,32 +133,42 @@ const App = () => {
}, [])

return (
<ThemeProvider theme={theme}>
<LocalizationProvider dateAdapter={AdapterMoment}>
<SearchContext.Provider value={{ search, setSearch: safeSetSearch }}>
<ConfigProvider direction="rtl" locale={heIL}>
<StyledLayout className="main">
<Header pages={PAGES} />
<Layout>
<StyledContent>
<StyledBody>
<Routes>
<Route path={PAGES[0].key} element={<DashboardPage />} />
<Route path={PAGES[1].key} element={<TimelinePage />} />
<Route path={PAGES[2].key} element={<GapsPage />} />
<Route path={PAGES[3].key} element={<RealtimeMapPage />} />
<Route path={PAGES[4].key} element={<SingleLineMapPage />} />
<Route path={PAGES[5].key} element={<About />} />
<Route path="*" element={<Navigate to={PAGES[0].key} replace />} />
</Routes>
</StyledBody>
</StyledContent>
</Layout>
</StyledLayout>
</ConfigProvider>
</SearchContext.Provider>
</LocalizationProvider>
</ThemeProvider>
<SearchContext.Provider value={{ search, setSearch: safeSetSearch }}>
<CacheProvider value={cacheRtl}>
<ThemeProvider theme={theme}>
<LocalizationProvider dateAdapter={AdapterMoment} adapterLocale="he">
<ConfigProvider direction="rtl" locale={heIL}>
<StyledLayout className="main">
<Header pages={PAGES} />
<Layout>
<StyledContent>
<StyledBody>
<Routes>
<Route path={PAGES[0].key} element={<DashboardPage />} />
<Route path={PAGES[1].key} element={<TimelinePage />} />
<Route path={PAGES[2].key} element={<GapsPage />} />
<Route path={PAGES[3].key} element={<RealtimeMapPage />} />
<Route path={PAGES[4].key} element={<SingleLineMapPage />} />
<Route path={PAGES[5].key} element={<About />} />
<Route
path="*"
element={
<div>
<a href={PAGES[0].key}>click to navigate to dashboard.</a>
<Navigate to={PAGES[0].key} replace />
</div>
}
/>
Comment on lines +152 to +161
Copy link
Member

Choose a reason for hiding this comment

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

missed it

</Routes>
</StyledBody>
</StyledContent>
</Layout>
</StyledLayout>
</ConfigProvider>
</LocalizationProvider>
</ThemeProvider>
</CacheProvider>
</SearchContext.Provider>
)
}

Expand Down
4 changes: 1 addition & 3 deletions src/pages/SingleLineMapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ const SingleLineMapPage = () => {
<Label text={TEXTS.choose_datetime} />
<DataAndTimeSelector
timestamp={moment(timestamp)}
setTimestamp={(ts) =>
setSearch((current) => ({ ...current, timestamp: ts ? ts.valueOf() : 0 }))
}
setTimestamp={(ts) => setSearch((current) => ({ ...current, timestamp: ts.valueOf() }))}
/>
</Row>
{/* choose operator */}
Expand Down
21 changes: 14 additions & 7 deletions src/pages/components/DataAndTimeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react'
import React, { useEffect, useState } from 'react'
import { INPUT_SIZE } from 'src/resources/sizes'
import { DatePicker } from '@mui/x-date-pickers/DatePicker'
import { TEXTS } from 'src/resources/texts'
import moment from 'moment'
import moment, { Moment } from 'moment'
import { TimePicker, renderTimeViewClock } from '@mui/x-date-pickers'

type DataAndTimeSelectorProps = {
timestamp: moment.Moment
setTimestamp: (timestamp: moment.Moment | null) => void
setTimestamp: (timestamp: moment.Moment) => void
showTimePicker?: boolean
}

Expand All @@ -16,12 +16,19 @@ export function DataAndTimeSelector({
setTimestamp,
showTimePicker,
}: DataAndTimeSelectorProps) {
const [timeSelected, setTimeSelected] = useState<moment.Moment | null>(timestamp)

useEffect(() => {
if (timeSelected != null && timeSelected.isValid() && timeSelected.isSameOrBefore(new Date()))
setTimestamp(timeSelected)
}, [timeSelected])

return (
<>
<DatePicker
sx={{ width: INPUT_SIZE }}
value={timestamp}
onChange={(ts) => setTimestamp(ts)}
value={timeSelected}
onChange={(ts) => setTimeSelected(ts)}
format="DD/MM/YYYY"
label={TEXTS.choose_datetime}
disableFuture
Expand All @@ -30,8 +37,8 @@ export function DataAndTimeSelector({
<TimePicker
sx={{ width: INPUT_SIZE }}
label={TEXTS.choose_datetime}
value={timestamp}
onChange={(ts) => setTimestamp(ts)}
value={timeSelected}
onChange={(ts) => setTimeSelected(ts)}
ampm={false}
viewRenderers={{
hours: renderTimeViewClock,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dashboard/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ const DashboardPage = () => {
value={startDate}
onChange={(data) => setStartDate(data)}
format="DD/MM/YYYY"
label="start"
label={TEXTS.start}
/>
-
<DatePicker
value={endDate}
onChange={(data) => setEndDate(data)}
format="DD/MM/YYYY"
label="end"
label={TEXTS.end}
/>
<FormControlLabel
control={
Expand Down
2 changes: 2 additions & 0 deletions src/resources/texts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export const TEXTS = {
from_time_x_to_time_y: 'משעה XXX עד שעה YYY',
choose_start_time: 'בחירת שעת התחלה',
group_by_hour_tooltip_content: 'קיבוץ לפי שעה',
start: 'התחלה',
end: 'סיום',
about_title: 'אודות',
donate_title: 'לתרומות',
report_a_bug_title: 'דיווח על באג',
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3999,6 +3999,11 @@ cssesc@^3.0.0:
resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee"
integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==

cssjanus@^2.0.1:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cssjanus/-/cssjanus-2.1.0.tgz#6f99070e0b7cc79f826ea48c63c03cb250713af1"
integrity sha512-kAijbny3GmdOi9k+QT6DGIXqFvL96aksNlGr4Rhk9qXDZYWUojU4bRc3IHWxdaLNOqgEZHuXoe5Wl2l7dxLW5g==

cssnano-preset-default@^5.2.14:
version "5.2.14"
resolved "https://registry.yarnpkg.com/cssnano-preset-default/-/cssnano-preset-default-5.2.14.tgz#309def4f7b7e16d71ab2438052093330d9ab45d8"
Expand Down Expand Up @@ -9693,6 +9698,13 @@ stylehacks@^5.1.1:
browserslist "^4.21.4"
postcss-selector-parser "^6.0.4"

stylis-plugin-rtl@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/stylis-plugin-rtl/-/stylis-plugin-rtl-2.1.1.tgz#16707809c878494835f77e5d4aadaae3db639b5e"
integrity sha512-q6xIkri6fBufIO/sV55md2CbgS5c6gg9EhSVATtHHCdOnbN/jcI0u3lYhNVeuI65c4lQPo67g8xmq5jrREvzlg==
dependencies:
cssjanus "^2.0.1"

[email protected]:
version "4.2.0"
resolved "https://registry.yarnpkg.com/stylis/-/stylis-4.2.0.tgz#79daee0208964c8fe695a42fcffcac633a211a51"
Expand Down
Loading