Skip to content

Commit

Permalink
fixed #734 keep in memory task tab
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxe35 committed Apr 2, 2023
1 parent 3e89767 commit ada575d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions apps/web/lib/features/task/task-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ type StatusFilter = { [x in IStatusType]: string };
*/
export function useTaskFilter(profile: I_UserProfilePage) {
const { trans } = useTranslation();
const [tab, setTab] = useState<ITab>('worked');

const defaultValue =
typeof window !== 'undefined'
? (window.localStorage.getItem('task-tab') as ITab) || null
: 'worked';

const [tab, setTab] = useState<ITab>(defaultValue || 'worked');
const [filterType, setFilterType] = useState<FilterType>(undefined);

const [statusFilter, setStatusFilter] = useState<StatusFilter>(
Expand Down Expand Up @@ -81,6 +87,10 @@ export function useTaskFilter(profile: I_UserProfilePage) {
},
];

useEffect(() => {
window.localStorage.setItem('task-tab', tab);
}, [tab]);

useEffect(() => {
setTaskName('');
}, [filterType]);
Expand Down Expand Up @@ -170,7 +180,12 @@ type Props = { hook: I_TaskFilter; profile: I_UserProfilePage };
export function TaskFilter({ className, hook, profile }: IClassName & Props) {
return (
<>
<div className={clsxm('flex justify-between xs:flex-row flex-col items-center', className)}>
<div
className={clsxm(
'flex justify-between xs:flex-row flex-col items-center',
className
)}
>
<TabsNav hook={hook} />
<InputFilters profile={profile} hook={hook} />
</div>
Expand Down

0 comments on commit ada575d

Please sign in to comment.