Skip to content

Commit

Permalink
fix(human-app/frontend/jobs): improve sorting states on mobile drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperKoza343 committed Oct 28, 2024
1 parent cda0969 commit c699326
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 190 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/* eslint-disable camelcase --- response from api */
import Box from '@mui/material/Box';
import Drawer from '@mui/material/Drawer';
import CssBaseline from '@mui/material/CssBaseline';
import { Divider, IconButton, Stack, Typography } from '@mui/material';
import { useTranslation } from 'react-i18next';
import CloseIcon from '@mui/icons-material/Close';
import type { Dispatch, SetStateAction } from 'react';
import { Button } from '@/components/ui/button';
import { HumanLogoIcon, SortArrow } from '@/components/ui/icons';
import { useJobsFilterStore } from '@/hooks/use-jobs-filter-store';
import { HumanLogoIcon } from '@/components/ui/icons';
import { AvailableJobsNetworkFilterMobile } from '@/pages/worker/jobs/components/available-jobs/mobile/available-jobs-network-filter-mobile';
import { AvailableJobsStatusFilterMobile } from '@/pages/worker/jobs/components/available-jobs/mobile/available-jobs-status-filter-mobile';
import { AvailableJobsJobTypeFilterMobile } from '@/pages/worker/jobs/components/available-jobs/mobile/available-jobs-job-type-filter-mobile';
import { useColorMode } from '@/hooks/use-color-mode';
import { AvailableJobsRewardAmountSortMobile } from '@/pages/worker/jobs/components/available-jobs/mobile/available-jobs-reward-amount-sort-mobile';

interface DrawerMobileProps {
setIsMobileFilterDrawerOpen: Dispatch<SetStateAction<boolean>>;
Expand All @@ -22,7 +20,6 @@ export function AvailableJobsDrawerMobile({
}: DrawerMobileProps) {
const { colorPalette } = useColorMode();
const { t } = useTranslation();
const { setFilterParams, filterParams } = useJobsFilterStore();

return (
<Box sx={{ display: 'flex', position: 'relative' }}>
Expand Down Expand Up @@ -85,66 +82,7 @@ export function AvailableJobsDrawerMobile({
<Typography variant="mobileHeaderMid">
{t('worker.jobs.mobileFilterDrawer.sortBy')}
</Typography>
<Typography color={colorPalette.text.secondary} variant="body2">
{t('worker.jobs.rewardAmount')}
</Typography>
<Button
size="small"
sx={{
marginLeft: '16px',
maxWidth: 'fit-content',
}}
variant="text"
>
<SortArrow />
<Typography
onClick={() => {
setFilterParams({
...filterParams,
sort: 'desc',
sort_field: 'reward_amount',
});
}}
sx={{
marginLeft: '10px',
}}
variant="subtitle1"
>
{t('worker.jobs.sortDirection.fromHighest')}
</Typography>
</Button>
<Button
size="small"
sx={{
marginLeft: '16px',
maxWidth: 'fit-content',
marginBottom: '16px',
}}
variant="text"
>
<Box
sx={{
transform: 'rotate(180deg)',
}}
>
<SortArrow />
</Box>
<Typography
onClick={() => {
setFilterParams({
...filterParams,
sort: 'asc',
sort_field: 'reward_amount',
});
}}
sx={{
marginLeft: '10px',
}}
variant="subtitle1"
>
From lowest
</Typography>
</Button>
<AvailableJobsRewardAmountSortMobile />
<Typography variant="mobileHeaderLarge">
{t('worker.jobs.mobileFilterDrawer.filters')}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable camelcase */
import { t } from 'i18next';
import Typography from '@mui/material/Typography';
import { useColorMode } from '@/hooks/use-color-mode';
import { useJobsFilterStore } from '@/hooks/use-jobs-filter-store';
import { Sorting } from '@/pages/worker/jobs/components/sorting';

export function AvailableJobsRewardAmountSortMobile() {
const { setFilterParams, filterParams } = useJobsFilterStore();
const { colorPalette } = useColorMode();

return (
<Sorting
label={
<Typography color={colorPalette.text.secondary} variant="body2">
{t('worker.jobs.rewardAmount')}
</Typography>
}
fromHighestSelected={
filterParams.sort_field === 'reward_amount' &&
filterParams.sort === 'desc'
}
sortFromHighest={() => {
setFilterParams({
...filterParams,
sort: 'desc',
sort_field: 'reward_amount',
});
}}
fromLowestSelected={
filterParams.sort_field === 'reward_amount' &&
filterParams.sort === 'asc'
}
sortFromLowest={() => {
setFilterParams({
...filterParams,
sort: 'asc',
sort_field: 'reward_amount',
});
}}
clear={() => {
setFilterParams({
...filterParams,
sort: undefined,
sort_field: undefined,
});
}}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/* eslint-disable camelcase --- response from api */
import Box from '@mui/material/Box';
import Drawer from '@mui/material/Drawer';
import CssBaseline from '@mui/material/CssBaseline';
import { Divider, IconButton, Stack, Typography } from '@mui/material';
import { useTranslation } from 'react-i18next';
import CloseIcon from '@mui/icons-material/Close';
import type { Dispatch, SetStateAction } from 'react';
import { Button } from '@/components/ui/button';
import { HumanLogoIcon, SortArrow } from '@/components/ui/icons';
import { useMyJobsFilterStore } from '@/hooks/use-my-jobs-filter-store';
import { HumanLogoIcon } from '@/components/ui/icons';
import { useColorMode } from '@/hooks/use-color-mode';
import { MyJobsRewardAmountSortMobile } from '@/pages/worker/jobs/components/my-jobs/mobile/my-jobs-reward-amount-sort-mobile';
import { MyJobsExpiresAtSortMobile } from '@/pages/worker/jobs/components/my-jobs/mobile/my-jobs-expires-at-sort-mobile';
import { MyJobsNetworkFilterMobile } from './my-jobs-network-filter-mobile';
import { MyJobsJobTypeFilterMobile } from './my-jobs-job-type-filter-mobile';
import { MyJobsStatusFilterMobile } from './my-jobs-status-filter-mobile';
Expand All @@ -22,7 +21,6 @@ export function MyJobsDrawerMobile({
}: DrawerMobileProps) {
const { colorPalette } = useColorMode();
const { t } = useTranslation();
const { setFilterParams, filterParams } = useMyJobsFilterStore();

return (
<Box sx={{ display: 'flex', position: 'relative' }}>
Expand Down Expand Up @@ -85,126 +83,8 @@ export function MyJobsDrawerMobile({
<Typography variant="mobileHeaderMid">
{t('worker.jobs.mobileFilterDrawer.sortBy')}
</Typography>
<Typography color={colorPalette.text.secondary} variant="body2">
{t('worker.jobs.rewardAmount')}
</Typography>
<Button
size="small"
sx={{
marginLeft: '16px',
maxWidth: 'fit-content',
}}
variant="text"
>
<SortArrow />
<Typography
onClick={() => {
setFilterParams({
...filterParams,
sort: 'desc',
sort_field: 'reward_amount',
});
}}
sx={{
marginLeft: '10px',
}}
variant="subtitle1"
>
{t('worker.jobs.sortDirection.fromHighest')}
</Typography>
</Button>
<Button
size="small"
sx={{
marginLeft: '16px',
maxWidth: 'fit-content',
marginBottom: '16px',
}}
variant="text"
>
<Box
sx={{
transform: 'rotate(180deg)',
}}
>
<SortArrow />
</Box>
<Typography
onClick={() => {
setFilterParams({
...filterParams,
sort: 'asc',
sort_field: 'reward_amount',
});
}}
sx={{
marginLeft: '10px',
}}
variant="subtitle1"
>
From lowest
</Typography>
</Button>
<Typography color={colorPalette.text.secondary} variant="body2">
{t('worker.jobs.expiresAt')}
</Typography>
<Button
size="small"
sx={{
marginLeft: '16px',
maxWidth: 'fit-content',
}}
variant="text"
>
<SortArrow />
<Typography
onClick={() => {
setFilterParams({
...filterParams,
sort: 'desc',
sort_field: 'expires_at',
});
}}
sx={{
marginLeft: '10px',
}}
variant="subtitle1"
>
{t('worker.jobs.sortDirection.fromHighest')}
</Typography>
</Button>
<Button
size="small"
sx={{
marginLeft: '16px',
maxWidth: 'fit-content',
marginBottom: '16px',
}}
variant="text"
>
<Box
sx={{
transform: 'rotate(180deg)',
}}
>
<SortArrow />
</Box>
<Typography
onClick={() => {
setFilterParams({
...filterParams,
sort: 'asc',
sort_field: 'expires_at',
});
}}
sx={{
marginLeft: '10px',
}}
variant="subtitle1"
>
From lowest
</Typography>
</Button>
<MyJobsRewardAmountSortMobile />
<MyJobsExpiresAtSortMobile />
<Typography variant="mobileHeaderLarge">
{t('worker.jobs.mobileFilterDrawer.filters')}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable camelcase */
import Typography from '@mui/material/Typography';
import { t } from 'i18next';
import { useColorMode } from '@/hooks/use-color-mode';
import { useMyJobsFilterStore } from '@/hooks/use-my-jobs-filter-store';
import { Sorting } from '@/pages/worker/jobs/components/sorting';

export function MyJobsExpiresAtSortMobile() {
const { setFilterParams, filterParams } = useMyJobsFilterStore();
const { colorPalette } = useColorMode();

return (
<Sorting
label={
<Typography color={colorPalette.text.secondary} variant="body2">
{t('worker.jobs.expiresAt')}
</Typography>
}
fromHighestSelected={
filterParams.sort_field === 'expires_at' && filterParams.sort === 'desc'
}
sortFromHighest={() => {
setFilterParams({
...filterParams,
sort: 'desc',
sort_field: 'expires_at',
});
}}
fromLowestSelected={
filterParams.sort_field === 'expires_at' && filterParams.sort === 'asc'
}
sortFromLowest={() => {
setFilterParams({
...filterParams,
sort: 'asc',
sort_field: 'expires_at',
});
}}
clear={() => {
setFilterParams({
...filterParams,
sort: undefined,
sort_field: undefined,
});
}}
/>
);
}
Loading

0 comments on commit c699326

Please sign in to comment.