This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(category): make categories page ok
- Loading branch information
1 parent
dc7a51e
commit 1362e27
Showing
10 changed files
with
250 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
.categories { | ||
display: grid; | ||
|
||
grid-template: | ||
'aside chart' | ||
/ 1fr 2fr; | ||
|
||
gap: 16px; | ||
|
||
@media (max-width: 1024px) { | ||
grid-template: | ||
'aside chart' | ||
/ 1fr 1fr; | ||
} | ||
|
||
@media (max-width: 768px) { | ||
grid-template: | ||
'aside' | ||
'chart'; | ||
} | ||
} | ||
|
||
.chart { | ||
grid-area: chart; | ||
|
||
& > * { | ||
@media (max-width: 768px) { | ||
margin-bottom: 32px; | ||
} | ||
} | ||
} | ||
|
||
.aside { | ||
grid-area: aside; | ||
|
||
& > *:not(:last-child) { | ||
margin-bottom: 16px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { GroupBy } from '@shared/enum/GroupBy' | ||
import { Button, ButtonType } from '@front/ui/components/form/button' | ||
import { Card } from '@front/ui/components/layout/card' | ||
import { pushRoute } from '@front/features/routing' | ||
|
||
interface Props { | ||
group?: GroupBy | ||
} | ||
|
||
export const GroupChooser = ({ group }: Props) => { | ||
const showYear = !group || group !== GroupBy.Year | ||
const showMonth = !group || group !== GroupBy.Month | ||
const showWhole = !!group | ||
|
||
return ( | ||
<Card | ||
title={'Group'} | ||
actions={[ | ||
showYear && ( | ||
<Button | ||
onClick={() => pushRoute('/app/stats/categories/year')} | ||
type={ButtonType.Text} | ||
> | ||
Show year | ||
</Button> | ||
), | ||
showMonth && ( | ||
<Button | ||
onClick={() => pushRoute('/app/stats/categories/month')} | ||
type={ButtonType.Text} | ||
> | ||
Show month | ||
</Button> | ||
), | ||
showWhole && ( | ||
<Button | ||
onClick={() => pushRoute('/app/stats/categories')} | ||
type={ButtonType.Text} | ||
> | ||
Show all time | ||
</Button> | ||
), | ||
].filter(Boolean)} | ||
> | ||
{!!group && <p>You see data for one {group}</p>} | ||
{!group && <p>You see data for all time</p>} | ||
</Card> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { format } from 'date-fns' | ||
import { GroupBy } from '@shared/enum/GroupBy' | ||
import { useCallback } from 'react' | ||
import { Button, ButtonType } from '@front/ui/components/form/button' | ||
import { Card } from '@front/ui/components/layout/card' | ||
|
||
interface Props { | ||
previousPeriodNumber: number | ||
setPreviousPeriodNumber: (t: (v: number) => number) => void | ||
from: Date | ||
to: Date | ||
group: GroupBy | ||
} | ||
|
||
export const PeriodChooser = ({ | ||
from, | ||
to, | ||
group, | ||
setPreviousPeriodNumber, | ||
previousPeriodNumber, | ||
}: Props) => { | ||
const back = useCallback(() => setPreviousPeriodNumber(v => v + 1), [ | ||
setPreviousPeriodNumber, | ||
]) | ||
const next = useCallback(() => setPreviousPeriodNumber(v => v - 1), [ | ||
setPreviousPeriodNumber, | ||
]) | ||
|
||
return ( | ||
<Card | ||
title={'Period'} | ||
actions={[ | ||
<Button | ||
onClick={back} | ||
type={ButtonType.Text} | ||
>{`Previous ${group}`}</Button>, | ||
previousPeriodNumber > 0 && ( | ||
<Button | ||
onClick={next} | ||
type={ButtonType.Text} | ||
>{`Next ${group}`}</Button> | ||
), | ||
].filter(Boolean)} | ||
> | ||
<p> | ||
List of categories for the period from{' '} | ||
<b>{format(from, 'YYYY.MM.DD')}</b> to <b>{format(to, 'YYYY.MM.DD')}</b> | ||
</p> | ||
</Card> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useMemo } from 'react' | ||
import { useMappedState } from 'redux-react-hook' | ||
|
||
import { createRangeForGroup } from '@front/helpers/createRangeForGroup' | ||
import { GroupBy } from '@shared/enum/GroupBy' | ||
import { getFirstTransactionDate } from '@front/domain/money/selectors/getFirstTransactionDate' | ||
|
||
export const useDateRange = (previousPeriodNumber: number, group?: GroupBy) => { | ||
const firstTransactionDate = useMappedState(getFirstTransactionDate) | ||
|
||
const { from, to } = useMemo(() => { | ||
if (group) { | ||
return createRangeForGroup(group, previousPeriodNumber) | ||
} | ||
|
||
return { | ||
from: firstTransactionDate, | ||
to: new Date(), | ||
} | ||
}, [group, previousPeriodNumber]) | ||
|
||
return { from, to } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
import { startOfMonth, startOfYear, endOfYear, endOfMonth } from 'date-fns' | ||
import { | ||
startOfMonth, | ||
startOfYear, | ||
endOfYear, | ||
endOfMonth, | ||
subYears, | ||
subMonths, | ||
} from 'date-fns' | ||
|
||
import { GroupBy } from '@shared/enum/GroupBy' | ||
|
||
import { wantUTC } from './wantUTC' | ||
|
||
export const createRangeForGroup = (group: GroupBy) => { | ||
const start = group === GroupBy.Month ? startOfMonth : startOfYear | ||
const end = group === GroupBy.Month ? endOfMonth : endOfYear | ||
export const createRangeForGroup = ( | ||
group: GroupBy, | ||
previousPeriodNumber = 0, | ||
) => { | ||
const minus = wantUTC(group === GroupBy.Month ? subMonths : subYears) | ||
const now = minus(new Date(), previousPeriodNumber) | ||
|
||
return { from: wantUTC(start)(new Date()), to: wantUTC(end)(new Date()) } | ||
const start = wantUTC(group === GroupBy.Month ? startOfMonth : startOfYear) | ||
const end = wantUTC(group === GroupBy.Month ? endOfMonth : endOfYear) | ||
|
||
return { from: start(now), to: end(now) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters