Skip to content

Commit 1827853

Browse files
authored
add setting to let user decide home view (#109)
1 parent c6f9125 commit 1827853

File tree

6 files changed

+77
-20
lines changed

6 files changed

+77
-20
lines changed

src/contexts/RouterContext.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { App } from '@/App'
2-
import { isMobile } from '@/utils/dom'
3-
import { getPathName } from '@/utils/navigation'
2+
import { getHomeView, getPathName } from '@/utils/navigation'
43
import { ForgotPasswordView } from '@/views/Authorization/ForgotPasswordView'
54
import { LoginView } from '@/views/Authorization/LoginView'
65
import { SignupView } from '@/views/Authorization/Signup'
@@ -45,7 +44,9 @@ export class RouterContext extends React.Component<object, RouterContextState> {
4544
}
4645

4746
private getMainRoute = () => {
48-
if (isMobile()) {
47+
const home_view = getHomeView()
48+
49+
if (home_view === 'my_tasks') {
4950
return <MyTasks navigate={this.navigate} />
5051
}
5152

src/utils/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export const doLogin = async (email: string, password: string, navigate: (path:
1111
localStorage.removeItem('ca_redirect')
1212
navigate(redirectUrl)
1313
} else {
14-
navigate(NavigationPaths.DeviceAwareLoggedInLandingPage)
14+
navigate(NavigationPaths.HomeView())
1515
}
1616
}

src/utils/navigation.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isMobile } from "./dom"
2+
import { retrieveValue } from "./storage"
23

34
export const getPathName = () => document.location.pathname
45

@@ -12,13 +13,20 @@ export const NavigationPaths = {
1213
ResetPassword: '/forgot-password',
1314
MyTasks: '/my/tasks',
1415
TasksOverview: '/tasks',
15-
DeviceAwareLoggedInLandingPage: isMobile() ? '/my/tasks' : '/tasks',
16+
HomeView: () => getHomeView() === 'my_tasks' ? '/my/tasks' : '/tasks',
1617
Labels: '/labels',
18+
Settings: '/settings',
1719
TaskCreate: '/tasks/create',
1820
TaskEdit: (taskId: string) => `/tasks/${taskId}/edit`,
1921
TaskHistory: (taskId: string) => `/tasks/${taskId}/history`,
2022
}
2123

2224
export interface WithNavigate {
2325
navigate: (path: string) => void
24-
}
26+
}
27+
28+
export type HomeView = 'my_tasks' | 'tasks_overview'
29+
30+
export const getHomeView = (): HomeView => {
31+
return retrieveValue<HomeView>('home_view', isMobile() ? 'my_tasks' : 'tasks_overview')
32+
}

src/views/Navigation/NavBar.tsx

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {
22
MenuRounded,
3-
HomeOutlined,
4-
LabelOutlined,
5-
SettingsOutlined,
63
Logout,
4+
FormatListBulleted,
5+
LocalLibrary,
6+
Label,
7+
Settings,
78
} from '@mui/icons-material'
89
import {
910
IconButton,
@@ -109,18 +110,23 @@ export class NavBar extends React.Component<NavBarProps, NavBarState> {
109110
sx={{ borderRadius: 4, width: '100%', padding: 1 }}
110111
>
111112
<NavBarLink
112-
to={NavigationPaths.DeviceAwareLoggedInLandingPage}
113-
icon={<HomeOutlined />}
114-
label='Home'
113+
to={NavigationPaths.MyTasks}
114+
icon={<LocalLibrary />}
115+
label='My tasks'
115116
/>
116117
<NavBarLink
117-
to='/labels'
118-
icon={<LabelOutlined />}
118+
to={NavigationPaths.MyTasks}
119+
icon={<FormatListBulleted />}
120+
label='Tasks Overview'
121+
/>
122+
<NavBarLink
123+
to={NavigationPaths.Labels}
124+
icon={<Label />}
119125
label='Labels'
120126
/>
121127
<NavBarLink
122-
to='/settings'
123-
icon={<SettingsOutlined />}
128+
to={NavigationPaths.Settings}
129+
icon={<Settings />}
124130
label='Settings'
125131
/>
126132
</List>

src/views/Settings/Settings.tsx

+45-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
import { UpdatePassword } from '@/api/users'
2-
import { Container, Typography, Divider, Box, Button } from '@mui/joy'
2+
import { Container, Typography, Divider, Box, Button, Select, Option } from '@mui/joy'
33
import React from 'react'
44
import { PassowrdChangeModal } from '../Modals/Inputs/PasswordChangeModal'
55
import { APITokenSettings } from './APITokenSettings'
66
import { NotificationSetting } from '../Notifications/NotificationSettings'
77
import { ThemeToggle } from './ThemeToggle'
8+
import { storeValue } from '@/utils/storage'
9+
import { getHomeView, HomeView } from '@/utils/navigation'
10+
import { SelectValue } from '@mui/base'
11+
12+
type SettingsProps = object
13+
type SettingsState = {
14+
homeView: HomeView
15+
}
16+
17+
export class Settings extends React.Component<SettingsProps, SettingsState> {
18+
constructor(props: SettingsProps) {
19+
super(props)
20+
21+
this.state = {
22+
homeView: getHomeView(),
23+
}
24+
}
825

9-
export class Settings extends React.Component {
1026
private changePasswordModal = React.createRef<PassowrdChangeModal>()
1127

1228
private onPasswordChanged = async (password: string | null) => {
@@ -21,7 +37,18 @@ export class Settings extends React.Component {
2137
this.changePasswordModal.current?.open()
2238
}
2339

40+
private onHomeViewChange = async (e: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, option: SelectValue<HomeView, false>) => {
41+
const homeView = option as HomeView
42+
await this.setState({
43+
homeView,
44+
})
45+
46+
storeValue<HomeView>('home_view', homeView)
47+
}
48+
2449
render(): React.ReactNode {
50+
const { homeView } = this.state
51+
2552
return (
2653
<Container sx={{
2754
paddingBottom: '16px',
@@ -34,7 +61,22 @@ export class Settings extends React.Component {
3461
paddingBottom: '4',
3562
}}
3663
>
37-
<Typography level='h3'>Password</Typography>
64+
<Typography level='h3'>Preferred view</Typography>
65+
<Divider />
66+
<Typography>Choose your default view:</Typography>
67+
<Select
68+
value={homeView}
69+
sx={{
70+
maxWidth: '200px',
71+
}}
72+
onChange={this.onHomeViewChange}
73+
>
74+
<Option value='my_tasks'>My Tasks</Option>
75+
<Option value='tasks_overview'>Tasks Overview</Option>
76+
</Select>
77+
<Typography level='h3' sx={{
78+
mt: 2,
79+
}}>Password</Typography>
3880
<Divider />
3981
<Box sx={{
4082
mt: 1,

src/views/Tasks/TaskEdit.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class TaskEdit extends React.Component<TaskEditProps, TaskEditState> {
9191
private navigateAway = () => {
9292
const { navigate } = this.props
9393

94-
navigate(NavigationPaths.DeviceAwareLoggedInLandingPage)
94+
navigate(NavigationPaths.HomeView())
9595
}
9696

9797
private HandleValidateTask = () => {

0 commit comments

Comments
 (0)