Skip to content

Commit

Permalink
feat: filter tasks by previous month, previous week (#161)
Browse files Browse the repository at this point in the history
* feat: filter tasks by previous month, previous week

* chore: remove session.nvim

* fix: previous month, week only

* remove the operator select
---------

Co-authored-by: huypl53 <[email protected]>
  • Loading branch information
hudy9x and huypl53 authored Apr 12, 2024
1 parent bda24a6 commit 55ec4fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
36 changes: 15 additions & 21 deletions packages/shared-libs/src/lib/date-string-converter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addDays, lastDayOfMonth, setHours, subDays } from 'date-fns'
import { addDays, lastDayOfMonth, setHours, subDays, subMonths } from 'date-fns'

export const extractDueDate = ({
dateOperator,
Expand Down Expand Up @@ -157,6 +157,13 @@ export const fromDateStringToDateObject = (
}
}

if (['prev-week'].includes(dateStr)) {
const [mon, sat] = getMondayNSaturdayInWeek(subDays(new Date(), 7))

config.startDate = mon
config.endDate = sat
}

if (['month', 'this-month'].includes(dateStr)) {
const [firstDate, lastDate] = getStartNEndDateOfMonth(new Date())

Expand All @@ -179,26 +186,13 @@ export const fromDateStringToDateObject = (
}

if (['prev-month'].includes(dateStr)) {
const date = new Date()
const lastDateOfPrevMonth = new Date(
date.getFullYear(),
date.getMonth(),
1,
0,
0,
0
)
lastDateOfPrevMonth.setDate(lastDateOfPrevMonth.getDate() - 1)

config.startDate = new Date(
date.getFullYear(),
date.getMonth() - 1,
1,
0,
0,
0
)
config.endDate = lastDateOfPrevMonth
const date = subMonths(new Date(), 1)
const [firstDate, lastDate] = getStartNEndDateOfMonth(date)

to00h00m(firstDate)
to23h59m(lastDate)
config.startDate = firstDate
config.endDate = lastDate
}

return config
Expand Down
32 changes: 17 additions & 15 deletions packages/ui-app/app/_features/TaskFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,21 @@ export default function TaskFilter({
<CalendarModeFilter />
) : (
<>
{date && showOperator.includes(date) && (
<ListPreset
value={dateOperator}
onChange={val => {
setFilterValue('dateOperator', val)
}}
className="w-[100px] mr-1"
width={100}
options={[
{ id: '=', title: 'Equal' },
{ id: '>', title: 'After' },
{ id: '<', title: 'Before' }
]}
/>
)}
{/* {date && showOperator.includes(date) && ( */}
{/* <ListPreset */}
{/* value={dateOperator} */}
{/* onChange={val => { */}
{/* setFilterValue('dateOperator', val) */}
{/* }} */}
{/* className="w-[100px] mr-1" */}
{/* width={100} */}
{/* options={[ */}
{/* { id: '=', title: 'Equal' }, */}
{/* { id: '>', title: 'After' }, */}
{/* { id: '<', title: 'Before' } */}
{/* ]} */}
{/* /> */}
{/* )} */}
<ListPreset
className="w-[150px]"
value={date}
Expand All @@ -126,7 +126,9 @@ export default function TaskFilter({
{ id: 'yesterday', title: 'πŸ“† Yesterday' },
{ id: 'tomorrow', title: 'πŸ“† Tomorrow' },
{ id: 'this-week', title: 'πŸ“† This week' },
{ id: 'prev-week', title: 'πŸ“† Previous week' },
{ id: 'this-month', title: 'πŸ“† This month' },
{ id: 'prev-month', title: 'πŸ“† Previous month' },
{ id: 'not-set', title: 'πŸ“† Not set' },
{ id: 'date-range', title: 'πŸ“† Date range' }
]}
Expand Down

0 comments on commit 55ec4fe

Please sign in to comment.