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

Add a setting for Home View #109

Merged
merged 1 commit into from
Mar 4, 2025
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
7 changes: 4 additions & 3 deletions src/contexts/RouterContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { App } from '@/App'
import { isMobile } from '@/utils/dom'
import { getPathName } from '@/utils/navigation'
import { getHomeView, getPathName } from '@/utils/navigation'
import { ForgotPasswordView } from '@/views/Authorization/ForgotPasswordView'
import { LoginView } from '@/views/Authorization/LoginView'
import { SignupView } from '@/views/Authorization/Signup'
Expand Down Expand Up @@ -45,7 +44,9 @@ export class RouterContext extends React.Component<object, RouterContextState> {
}

private getMainRoute = () => {
if (isMobile()) {
const home_view = getHomeView()

if (home_view === 'my_tasks') {
return <MyTasks navigate={this.navigate} />
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export const doLogin = async (email: string, password: string, navigate: (path:
localStorage.removeItem('ca_redirect')
navigate(redirectUrl)
} else {
navigate(NavigationPaths.DeviceAwareLoggedInLandingPage)
navigate(NavigationPaths.HomeView())
}
}
12 changes: 10 additions & 2 deletions src/utils/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isMobile } from "./dom"
import { retrieveValue } from "./storage"

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

Expand All @@ -12,13 +13,20 @@ export const NavigationPaths = {
ResetPassword: '/forgot-password',
MyTasks: '/my/tasks',
TasksOverview: '/tasks',
DeviceAwareLoggedInLandingPage: isMobile() ? '/my/tasks' : '/tasks',
HomeView: () => getHomeView() === 'my_tasks' ? '/my/tasks' : '/tasks',
Labels: '/labels',
Settings: '/settings',
TaskCreate: '/tasks/create',
TaskEdit: (taskId: string) => `/tasks/${taskId}/edit`,
TaskHistory: (taskId: string) => `/tasks/${taskId}/history`,
}

export interface WithNavigate {
navigate: (path: string) => void
}
}

export type HomeView = 'my_tasks' | 'tasks_overview'

export const getHomeView = (): HomeView => {
return retrieveValue<HomeView>('home_view', isMobile() ? 'my_tasks' : 'tasks_overview')
}
26 changes: 16 additions & 10 deletions src/views/Navigation/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
MenuRounded,
HomeOutlined,
LabelOutlined,
SettingsOutlined,
Logout,
FormatListBulleted,
LocalLibrary,
Label,
Settings,
} from '@mui/icons-material'
import {
IconButton,
Expand Down Expand Up @@ -109,18 +110,23 @@ export class NavBar extends React.Component<NavBarProps, NavBarState> {
sx={{ borderRadius: 4, width: '100%', padding: 1 }}
>
<NavBarLink
to={NavigationPaths.DeviceAwareLoggedInLandingPage}
icon={<HomeOutlined />}
label='Home'
to={NavigationPaths.MyTasks}
icon={<LocalLibrary />}
label='My tasks'
/>
<NavBarLink
to='/labels'
icon={<LabelOutlined />}
to={NavigationPaths.MyTasks}
icon={<FormatListBulleted />}
label='Tasks Overview'
/>
<NavBarLink
to={NavigationPaths.Labels}
icon={<Label />}
label='Labels'
/>
<NavBarLink
to='/settings'
icon={<SettingsOutlined />}
to={NavigationPaths.Settings}
icon={<Settings />}
label='Settings'
/>
</List>
Expand Down
48 changes: 45 additions & 3 deletions src/views/Settings/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import { UpdatePassword } from '@/api/users'
import { Container, Typography, Divider, Box, Button } from '@mui/joy'
import { Container, Typography, Divider, Box, Button, Select, Option } from '@mui/joy'
import React from 'react'
import { PassowrdChangeModal } from '../Modals/Inputs/PasswordChangeModal'
import { APITokenSettings } from './APITokenSettings'
import { NotificationSetting } from '../Notifications/NotificationSettings'
import { ThemeToggle } from './ThemeToggle'
import { storeValue } from '@/utils/storage'
import { getHomeView, HomeView } from '@/utils/navigation'
import { SelectValue } from '@mui/base'

type SettingsProps = object
type SettingsState = {
homeView: HomeView
}

export class Settings extends React.Component<SettingsProps, SettingsState> {
constructor(props: SettingsProps) {
super(props)

this.state = {
homeView: getHomeView(),
}
}

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

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

private onHomeViewChange = async (e: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, option: SelectValue<HomeView, false>) => {
const homeView = option as HomeView
await this.setState({
homeView,
})

storeValue<HomeView>('home_view', homeView)
}

render(): React.ReactNode {
const { homeView } = this.state

return (
<Container sx={{
paddingBottom: '16px',
Expand All @@ -34,7 +61,22 @@ export class Settings extends React.Component {
paddingBottom: '4',
}}
>
<Typography level='h3'>Password</Typography>
<Typography level='h3'>Preferred view</Typography>
<Divider />
<Typography>Choose your default view:</Typography>
<Select
value={homeView}
sx={{
maxWidth: '200px',
}}
onChange={this.onHomeViewChange}
>
<Option value='my_tasks'>My Tasks</Option>
<Option value='tasks_overview'>Tasks Overview</Option>
</Select>
<Typography level='h3' sx={{
mt: 2,
}}>Password</Typography>
<Divider />
<Box sx={{
mt: 1,
Expand Down
2 changes: 1 addition & 1 deletion src/views/Tasks/TaskEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class TaskEdit extends React.Component<TaskEditProps, TaskEditState> {
private navigateAway = () => {
const { navigate } = this.props

navigate(NavigationPaths.DeviceAwareLoggedInLandingPage)
navigate(NavigationPaths.HomeView())
}

private HandleValidateTask = () => {
Expand Down