2024-06-30 18:55:39 -04:00
|
|
|
import {
|
2024-09-06 01:22:10 -04:00
|
|
|
Add,
|
|
|
|
CancelRounded,
|
|
|
|
EditCalendar,
|
|
|
|
FilterAlt,
|
2024-11-28 21:21:23 -05:00
|
|
|
PriorityHigh,
|
|
|
|
Style,
|
2024-09-06 01:22:10 -04:00
|
|
|
} from '@mui/icons-material'
|
|
|
|
import {
|
2024-06-30 18:55:39 -04:00
|
|
|
Box,
|
2024-11-28 21:21:23 -05:00
|
|
|
Button,
|
2024-09-06 01:22:10 -04:00
|
|
|
Chip,
|
2024-06-30 18:55:39 -04:00
|
|
|
Container,
|
|
|
|
IconButton,
|
2024-07-06 03:49:51 -04:00
|
|
|
Input,
|
2024-06-30 18:55:39 -04:00
|
|
|
List,
|
|
|
|
Menu,
|
|
|
|
MenuItem,
|
|
|
|
Snackbar,
|
|
|
|
Typography,
|
|
|
|
} from '@mui/joy'
|
2024-07-06 03:49:51 -04:00
|
|
|
import Fuse from 'fuse.js'
|
2024-06-30 18:55:39 -04:00
|
|
|
import { useContext, useEffect, useRef, useState } from 'react'
|
|
|
|
import { useNavigate } from 'react-router-dom'
|
|
|
|
import { UserContext } from '../../contexts/UserContext'
|
2024-11-23 20:23:59 -05:00
|
|
|
import { useChores } from '../../queries/ChoreQueries'
|
|
|
|
import { GetAllUsers, GetUserProfile } from '../../utils/Fetcher'
|
2024-11-28 21:21:23 -05:00
|
|
|
import Priorities from '../../utils/Priorities'
|
2024-07-16 19:37:18 -04:00
|
|
|
import LoadingComponent from '../components/Loading'
|
2024-11-23 20:23:59 -05:00
|
|
|
import { useLabels } from '../Labels/LabelQueries'
|
2024-06-30 18:55:39 -04:00
|
|
|
import ChoreCard from './ChoreCard'
|
2024-11-28 21:21:23 -05:00
|
|
|
import IconButtonWithMenu from './IconButtonWithMenu'
|
2024-06-30 18:55:39 -04:00
|
|
|
|
|
|
|
const MyChores = () => {
|
|
|
|
const { userProfile, setUserProfile } = useContext(UserContext)
|
|
|
|
const [isSnackbarOpen, setIsSnackbarOpen] = useState(false)
|
|
|
|
const [snackBarMessage, setSnackBarMessage] = useState(null)
|
|
|
|
const [chores, setChores] = useState([])
|
|
|
|
const [filteredChores, setFilteredChores] = useState([])
|
|
|
|
const [selectedFilter, setSelectedFilter] = useState('All')
|
2024-07-06 03:49:51 -04:00
|
|
|
const [searchTerm, setSearchTerm] = useState('')
|
2024-06-30 18:55:39 -04:00
|
|
|
const [activeUserId, setActiveUserId] = useState(0)
|
|
|
|
const [performers, setPerformers] = useState([])
|
|
|
|
const [anchorEl, setAnchorEl] = useState(null)
|
|
|
|
const menuRef = useRef(null)
|
|
|
|
const Navigate = useNavigate()
|
2024-11-23 20:23:59 -05:00
|
|
|
const { data: userLabels, isLoading: userLabelsLoading } = useLabels()
|
|
|
|
const { data: choresData, isLoading: choresLoading } = useChores()
|
2024-06-30 18:55:39 -04:00
|
|
|
const choreSorter = (a, b) => {
|
|
|
|
// 1. Handle null due dates (always last):
|
|
|
|
if (!a.nextDueDate && !b.nextDueDate) return 0 // Both null, no order
|
|
|
|
if (!a.nextDueDate) return 1 // a is null, comes later
|
|
|
|
if (!b.nextDueDate) return -1 // b is null, comes earlier
|
|
|
|
|
|
|
|
const aDueDate = new Date(a.nextDueDate)
|
|
|
|
const bDueDate = new Date(b.nextDueDate)
|
|
|
|
const now = new Date()
|
|
|
|
|
|
|
|
const oneDayInMs = 24 * 60 * 60 * 1000
|
|
|
|
|
|
|
|
// 2. Prioritize tasks due today +- 1 day:
|
|
|
|
const aTodayOrNear = Math.abs(aDueDate - now) <= oneDayInMs
|
|
|
|
const bTodayOrNear = Math.abs(bDueDate - now) <= oneDayInMs
|
|
|
|
if (aTodayOrNear && !bTodayOrNear) return -1 // a is closer
|
|
|
|
if (!aTodayOrNear && bTodayOrNear) return 1 // b is closer
|
|
|
|
|
|
|
|
// 3. Handle overdue tasks (excluding today +- 1):
|
|
|
|
const aOverdue = aDueDate < now && !aTodayOrNear
|
|
|
|
const bOverdue = bDueDate < now && !bTodayOrNear
|
|
|
|
if (aOverdue && !bOverdue) return -1 // a is overdue, comes earlier
|
|
|
|
if (!aOverdue && bOverdue) return 1 // b is overdue, comes earlier
|
|
|
|
|
|
|
|
// 4. Sort future tasks by due date:
|
|
|
|
return aDueDate - bDueDate // Sort ascending by due date
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (userProfile === null) {
|
|
|
|
GetUserProfile()
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
|
|
|
setUserProfile(data.res)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
GetAllUsers()
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
|
|
|
setPerformers(data.res)
|
|
|
|
})
|
|
|
|
|
|
|
|
const currentUser = JSON.parse(localStorage.getItem('user'))
|
|
|
|
if (currentUser !== null) {
|
|
|
|
setActiveUserId(currentUser.id)
|
|
|
|
}
|
|
|
|
}, [])
|
2024-11-23 20:23:59 -05:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (choresData) {
|
|
|
|
const sortedChores = choresData.res.sort(choreSorter)
|
|
|
|
setChores(sortedChores)
|
|
|
|
setFilteredChores(sortedChores)
|
|
|
|
}
|
|
|
|
}, [choresData, choresLoading])
|
|
|
|
|
2024-06-30 18:55:39 -04:00
|
|
|
useEffect(() => {
|
|
|
|
document.addEventListener('mousedown', handleMenuOutsideClick)
|
|
|
|
return () => {
|
|
|
|
document.removeEventListener('mousedown', handleMenuOutsideClick)
|
|
|
|
}
|
|
|
|
}, [anchorEl])
|
|
|
|
const handleMenuOutsideClick = event => {
|
|
|
|
if (
|
|
|
|
anchorEl &&
|
|
|
|
!anchorEl.contains(event.target) &&
|
|
|
|
!menuRef.current.contains(event.target)
|
|
|
|
) {
|
|
|
|
handleFilterMenuClose()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const handleFilterMenuOpen = event => {
|
|
|
|
event.preventDefault()
|
|
|
|
setAnchorEl(event.currentTarget)
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleFilterMenuClose = () => {
|
|
|
|
setAnchorEl(null)
|
|
|
|
}
|
2024-11-28 21:21:23 -05:00
|
|
|
|
|
|
|
const handleLabelFiltering = chipClicked => {
|
|
|
|
console.log('chipClicked', chipClicked)
|
|
|
|
|
|
|
|
if (chipClicked.label) {
|
|
|
|
const label = chipClicked.label
|
|
|
|
const labelFiltered = [...chores].filter(chore =>
|
|
|
|
chore.labelsV2.some(l => l.id === label.id),
|
|
|
|
)
|
|
|
|
console.log('labelFiltered', labelFiltered)
|
|
|
|
setFilteredChores(labelFiltered)
|
|
|
|
setSelectedFilter('Label: ' + label.name)
|
|
|
|
} else if (chipClicked.priority) {
|
|
|
|
const priority = chipClicked.priority
|
|
|
|
const priorityFiltered = chores.filter(
|
|
|
|
chore => chore.priority === priority,
|
|
|
|
)
|
|
|
|
setFilteredChores(priorityFiltered)
|
|
|
|
setSelectedFilter('Priority: ' + priority)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-30 18:55:39 -04:00
|
|
|
const handleChoreUpdated = (updatedChore, event) => {
|
|
|
|
const newChores = chores.map(chore => {
|
|
|
|
if (chore.id === updatedChore.id) {
|
|
|
|
return updatedChore
|
|
|
|
}
|
|
|
|
return chore
|
|
|
|
})
|
|
|
|
|
|
|
|
const newFilteredChores = filteredChores.map(chore => {
|
|
|
|
if (chore.id === updatedChore.id) {
|
|
|
|
return updatedChore
|
|
|
|
}
|
|
|
|
return chore
|
|
|
|
})
|
|
|
|
setChores(newChores)
|
|
|
|
setFilteredChores(newFilteredChores)
|
|
|
|
switch (event) {
|
|
|
|
case 'completed':
|
|
|
|
setSnackBarMessage('Completed')
|
|
|
|
break
|
|
|
|
case 'skipped':
|
|
|
|
setSnackBarMessage('Skipped')
|
|
|
|
break
|
|
|
|
case 'rescheduled':
|
|
|
|
setSnackBarMessage('Rescheduled')
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
setSnackBarMessage('Updated')
|
|
|
|
}
|
|
|
|
setIsSnackbarOpen(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleChoreDeleted = deletedChore => {
|
|
|
|
const newChores = chores.filter(chore => chore.id !== deletedChore.id)
|
|
|
|
const newFilteredChores = filteredChores.filter(
|
|
|
|
chore => chore.id !== deletedChore.id,
|
|
|
|
)
|
|
|
|
setChores(newChores)
|
|
|
|
setFilteredChores(newFilteredChores)
|
|
|
|
}
|
|
|
|
|
2024-07-06 03:49:51 -04:00
|
|
|
const searchOptions = {
|
|
|
|
// keys to search in
|
2024-11-23 20:23:59 -05:00
|
|
|
keys: ['name', 'raw_label'],
|
2024-07-06 03:49:51 -04:00
|
|
|
includeScore: true, // Optional: if you want to see how well each result matched the search term
|
|
|
|
isCaseSensitive: false,
|
|
|
|
findAllMatches: true,
|
|
|
|
}
|
2024-11-23 20:23:59 -05:00
|
|
|
|
|
|
|
const fuse = new Fuse(
|
|
|
|
chores.map(c => ({
|
|
|
|
...c,
|
|
|
|
raw_label: c.labelsV2
|
2024-11-28 21:21:23 -05:00
|
|
|
.map(l => userLabels.find(x => x.id === l.id).name)
|
2024-11-23 20:23:59 -05:00
|
|
|
.join(' '),
|
|
|
|
})),
|
|
|
|
searchOptions,
|
|
|
|
)
|
2024-07-06 03:49:51 -04:00
|
|
|
|
|
|
|
const handleSearchChange = e => {
|
2024-11-28 21:21:23 -05:00
|
|
|
if (selectedFilter !== 'All') {
|
|
|
|
setSelectedFilter('All')
|
|
|
|
}
|
2024-07-06 03:49:51 -04:00
|
|
|
const search = e.target.value
|
|
|
|
if (search === '') {
|
|
|
|
setFilteredChores(chores)
|
|
|
|
setSearchTerm('')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const term = search.toLowerCase()
|
|
|
|
setSearchTerm(term)
|
|
|
|
setFilteredChores(fuse.search(term).map(result => result.item))
|
|
|
|
}
|
|
|
|
|
2024-11-23 20:23:59 -05:00
|
|
|
if (
|
|
|
|
userProfile === null ||
|
|
|
|
userLabelsLoading ||
|
|
|
|
performers.length === 0 ||
|
|
|
|
choresLoading
|
|
|
|
) {
|
2024-07-16 19:37:18 -04:00
|
|
|
return <LoadingComponent />
|
2024-06-30 18:55:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container maxWidth='md'>
|
|
|
|
{/* <Typography level='h3' mb={1.5}>
|
|
|
|
My Chores
|
|
|
|
</Typography> */}
|
|
|
|
{/* <Sheet> */}
|
2024-09-06 01:22:10 -04:00
|
|
|
{/* Search box to filter */}
|
|
|
|
<Box
|
2024-06-30 18:55:39 -04:00
|
|
|
sx={{
|
2024-09-06 01:22:10 -04:00
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
alignContent: 'center',
|
|
|
|
alignItems: 'center',
|
2024-11-28 21:21:23 -05:00
|
|
|
gap: 0.5,
|
2024-06-30 18:55:39 -04:00
|
|
|
}}
|
|
|
|
>
|
2024-07-06 03:49:51 -04:00
|
|
|
<Input
|
|
|
|
placeholder='Search'
|
|
|
|
value={searchTerm}
|
2024-09-06 01:22:10 -04:00
|
|
|
fullWidth
|
2024-07-06 03:49:51 -04:00
|
|
|
sx={{
|
|
|
|
mt: 1,
|
|
|
|
mb: 1,
|
2024-09-06 01:22:10 -04:00
|
|
|
borderRadius: 24,
|
2024-07-06 03:49:51 -04:00
|
|
|
// border: '1px solid',
|
2024-09-06 01:22:10 -04:00
|
|
|
height: 24,
|
2024-07-06 03:49:51 -04:00
|
|
|
borderColor: 'text.disabled',
|
|
|
|
padding: 1,
|
|
|
|
}}
|
|
|
|
onChange={handleSearchChange}
|
|
|
|
endDecorator={
|
2024-07-06 13:27:41 -04:00
|
|
|
searchTerm && (
|
|
|
|
<CancelRounded
|
|
|
|
onClick={() => {
|
|
|
|
setSearchTerm('')
|
|
|
|
setFilteredChores(chores)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
2024-07-06 03:49:51 -04:00
|
|
|
}
|
|
|
|
/>
|
2024-11-28 21:21:23 -05:00
|
|
|
<IconButtonWithMenu
|
|
|
|
key={'icon-menu-labels-filter'}
|
|
|
|
icon={<PriorityHigh />}
|
|
|
|
options={Priorities}
|
|
|
|
selectedItem={selectedFilter}
|
|
|
|
onItemSelect={selected => {
|
|
|
|
handleLabelFiltering({ priority: selected.value })
|
|
|
|
}}
|
|
|
|
mouseClickHandler={handleMenuOutsideClick}
|
|
|
|
isActive={selectedFilter.startsWith('Priority: ')}
|
|
|
|
/>
|
|
|
|
<IconButtonWithMenu
|
|
|
|
key={'icon-menu-labels-filter'}
|
|
|
|
icon={<Style />}
|
|
|
|
options={userLabels}
|
|
|
|
selectedItem={selectedFilter}
|
|
|
|
onItemSelect={selected => {
|
|
|
|
handleLabelFiltering({ label: selected })
|
|
|
|
}}
|
|
|
|
isActive={selectedFilter.startsWith('Label: ')}
|
|
|
|
mouseClickHandler={handleMenuOutsideClick}
|
|
|
|
useChips
|
|
|
|
/>
|
|
|
|
|
2024-09-06 01:22:10 -04:00
|
|
|
<IconButton
|
|
|
|
onClick={handleFilterMenuOpen}
|
|
|
|
variant='outlined'
|
|
|
|
color={
|
2024-11-28 21:21:23 -05:00
|
|
|
selectedFilter && FILTERS[selectedFilter] && selectedFilter != 'All'
|
|
|
|
? 'primary'
|
|
|
|
: 'neutral'
|
2024-09-06 01:22:10 -04:00
|
|
|
}
|
|
|
|
size='sm'
|
|
|
|
sx={{
|
|
|
|
height: 24,
|
|
|
|
borderRadius: 24,
|
|
|
|
}}
|
|
|
|
>
|
2024-11-28 21:21:23 -05:00
|
|
|
<FilterAlt />
|
2024-09-06 01:22:10 -04:00
|
|
|
</IconButton>
|
|
|
|
<List
|
|
|
|
orientation='horizontal'
|
|
|
|
wrap
|
|
|
|
sx={{
|
|
|
|
mt: 0.2,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Menu
|
|
|
|
ref={menuRef}
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
open={Boolean(anchorEl)}
|
|
|
|
onClose={handleFilterMenuClose}
|
|
|
|
>
|
2024-11-28 21:21:23 -05:00
|
|
|
{Object.keys(FILTERS).map((filter, index) => (
|
2024-09-06 01:22:10 -04:00
|
|
|
<MenuItem
|
2024-11-28 21:21:23 -05:00
|
|
|
key={`filter-list-${filter}-${index}`}
|
2024-09-06 01:22:10 -04:00
|
|
|
onClick={() => {
|
|
|
|
const filterFunction = FILTERS[filter]
|
|
|
|
const filteredChores =
|
|
|
|
filterFunction.length === 2
|
|
|
|
? filterFunction(chores, userProfile.id)
|
|
|
|
: filterFunction(chores)
|
|
|
|
setFilteredChores(filteredChores)
|
|
|
|
setSelectedFilter(filter)
|
|
|
|
handleFilterMenuClose()
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{filter}
|
|
|
|
<Chip color={selectedFilter === filter ? 'primary' : 'neutral'}>
|
|
|
|
{FILTERS[filter].length === 2
|
|
|
|
? FILTERS[filter](chores, userProfile.id).length
|
|
|
|
: FILTERS[filter](chores).length}
|
|
|
|
</Chip>
|
|
|
|
</MenuItem>
|
|
|
|
))}
|
2024-11-28 21:21:23 -05:00
|
|
|
{selectedFilter.startsWith('Label: ') ||
|
|
|
|
(selectedFilter.startsWith('Priority: ') && (
|
|
|
|
<MenuItem
|
|
|
|
key={`filter-list-cancel-all-filters`}
|
|
|
|
onClick={() => {
|
|
|
|
setFilteredChores(chores)
|
|
|
|
setSelectedFilter('All')
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Cancel All Filters
|
|
|
|
</MenuItem>
|
|
|
|
))}
|
2024-09-06 01:22:10 -04:00
|
|
|
</Menu>
|
|
|
|
</List>
|
2024-07-06 03:49:51 -04:00
|
|
|
</Box>
|
2024-11-28 21:21:23 -05:00
|
|
|
{selectedFilter !== 'All' && (
|
|
|
|
<Chip
|
|
|
|
level='title-md'
|
|
|
|
gutterBottom
|
|
|
|
color='warning'
|
|
|
|
label={selectedFilter}
|
|
|
|
onDelete={() => {
|
|
|
|
setFilteredChores(chores)
|
|
|
|
setSelectedFilter('All')
|
|
|
|
}}
|
|
|
|
endDecorator={<CancelRounded />}
|
|
|
|
onClick={() => {
|
|
|
|
setFilteredChores(chores)
|
|
|
|
setSelectedFilter('All')
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Current Filter: {selectedFilter}
|
|
|
|
</Chip>
|
|
|
|
)}
|
2024-06-30 18:55:39 -04:00
|
|
|
{/* </Sheet> */}
|
|
|
|
{filteredChores.length === 0 && (
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
flexDirection: 'column',
|
|
|
|
height: '50vh',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<EditCalendar
|
|
|
|
sx={{
|
|
|
|
fontSize: '4rem',
|
|
|
|
// color: 'text.disabled',
|
|
|
|
mb: 1,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Typography level='title-md' gutterBottom>
|
|
|
|
Nothing scheduled
|
|
|
|
</Typography>
|
2024-11-28 21:21:23 -05:00
|
|
|
{chores.length > 0 && (
|
|
|
|
<>
|
|
|
|
<Button
|
|
|
|
onClick={() => setFilteredChores(chores)}
|
|
|
|
variant='outlined'
|
|
|
|
color='neutral'
|
|
|
|
>
|
|
|
|
Reset filters
|
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
)}
|
2024-06-30 18:55:39 -04:00
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{filteredChores.map(chore => (
|
|
|
|
<ChoreCard
|
|
|
|
key={chore.id}
|
|
|
|
chore={chore}
|
|
|
|
onChoreUpdate={handleChoreUpdated}
|
|
|
|
onChoreRemove={handleChoreDeleted}
|
|
|
|
performers={performers}
|
2024-11-23 20:23:59 -05:00
|
|
|
userLabels={userLabels}
|
2024-11-28 21:21:23 -05:00
|
|
|
onChipClick={handleLabelFiltering}
|
2024-06-30 18:55:39 -04:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
|
|
|
|
<Box
|
|
|
|
// variant='outlined'
|
|
|
|
sx={{
|
|
|
|
position: 'fixed',
|
|
|
|
bottom: 0,
|
|
|
|
left: 10,
|
|
|
|
p: 2, // padding
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
gap: 2,
|
|
|
|
'z-index': 1000,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<IconButton
|
|
|
|
color='primary'
|
|
|
|
variant='solid'
|
|
|
|
sx={{
|
|
|
|
borderRadius: '50%',
|
|
|
|
width: 50,
|
|
|
|
height: 50,
|
|
|
|
}}
|
|
|
|
// startDecorator={<Add />}
|
|
|
|
onClick={() => {
|
|
|
|
Navigate(`/chores/create`)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Add />
|
|
|
|
</IconButton>
|
|
|
|
</Box>
|
|
|
|
<Snackbar
|
|
|
|
open={isSnackbarOpen}
|
|
|
|
onClose={() => {
|
|
|
|
setIsSnackbarOpen(false)
|
|
|
|
}}
|
|
|
|
autoHideDuration={3000}
|
|
|
|
variant='soft'
|
|
|
|
color='success'
|
|
|
|
size='lg'
|
|
|
|
invertedColors
|
|
|
|
>
|
|
|
|
<Typography level='title-md'>{snackBarMessage}</Typography>
|
|
|
|
</Snackbar>
|
|
|
|
</Container>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const FILTERS = {
|
|
|
|
All: function (chores) {
|
|
|
|
return chores
|
|
|
|
},
|
|
|
|
Overdue: function (chores) {
|
|
|
|
return chores.filter(chore => {
|
|
|
|
if (chore.nextDueDate === null) return false
|
|
|
|
return new Date(chore.nextDueDate) < new Date()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
'Due today': function (chores) {
|
|
|
|
return chores.filter(chore => {
|
|
|
|
return (
|
|
|
|
new Date(chore.nextDueDate).toDateString() === new Date().toDateString()
|
|
|
|
)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
'Due in week': function (chores) {
|
|
|
|
return chores.filter(chore => {
|
|
|
|
return (
|
|
|
|
new Date(chore.nextDueDate) <
|
|
|
|
new Date(Date.now() + 7 * 24 * 60 * 60 * 1000) &&
|
|
|
|
new Date(chore.nextDueDate) > new Date()
|
|
|
|
)
|
|
|
|
})
|
|
|
|
},
|
2024-11-28 21:21:23 -05:00
|
|
|
'Due Later': function (chores) {
|
|
|
|
return chores.filter(chore => {
|
|
|
|
return (
|
|
|
|
new Date(chore.nextDueDate) > new Date(Date.now() + 24 * 60 * 60 * 1000)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
},
|
2024-06-30 18:55:39 -04:00
|
|
|
'Created By Me': function (chores, userID) {
|
|
|
|
return chores.filter(chore => {
|
|
|
|
return chore.createdBy === userID
|
|
|
|
})
|
|
|
|
},
|
|
|
|
'Assigned To Me': function (chores, userID) {
|
|
|
|
return chores.filter(chore => {
|
|
|
|
return chore.assignedTo === userID
|
|
|
|
})
|
|
|
|
},
|
|
|
|
'No Due Date': function (chores, userID) {
|
|
|
|
return chores.filter(chore => {
|
|
|
|
return chore.nextDueDate === null
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MyChores
|