Bump version to 0.1.95 and add dnd-kit dependencies; implement CompleteSubTask function and enhance chore sorting logic

This commit is contained in:
Mo Tarbin 2025-02-25 23:39:59 -05:00
parent e359b1c0a4
commit bbea27d380
9 changed files with 511 additions and 135 deletions

View file

@ -1,25 +1,11 @@
import moment from 'moment'
import { TASK_COLOR } from './Colors.jsx'
const priorityOrder = [1, 2, 3, 4, 0]
export const ChoresGrouper = (groupBy, chores) => {
// sort by priority then due date:
chores.sort((a, b) => {
// no priority is lowest priority:
if (a.priority === 0) {
return 1
}
if (a.priority !== b.priority) {
return a.priority - b.priority
}
if (a.nextDueDate === null) {
return 1
}
if (b.nextDueDate === null) {
return -1
}
return new Date(a.nextDueDate) - new Date(b.nextDueDate)
})
chores.sort(ChoreSorter)
var groups = []
switch (groupBy) {
case 'due_date':
@ -159,7 +145,25 @@ export const ChoresGrouper = (groupBy, chores) => {
}
return groups
}
export const ChoreSorter = (a, b) => {
const priorityA = priorityOrder.indexOf(a.priority)
const priorityB = priorityOrder.indexOf(b.priority)
if (priorityA !== priorityB) {
return priorityA - priorityB
}
// Status sorting (0 > 1 > ... ascending order)
if (a.status !== b.status) {
return a.status - b.status
}
// Due date sorting (earlier dates first, null/undefined last)
if (!a.nextDueDate && !b.nextDueDate) return 0
if (!a.nextDueDate) return 1
if (!b.nextDueDate) return -1
return new Date(a.nextDueDate) - new Date(b.nextDueDate)
}
export const notInCompletionWindow = chore => {
return (
chore.completionWindow &&

View file

@ -126,6 +126,15 @@ const MarkChoreComplete = (id, note, completedDate, performer) => {
})
}
const CompleteSubTask = (id, choreId, completedAt) => {
var markChoreURL = `/chores/${choreId}/subtask`
return Fetch(markChoreURL, {
method: 'PUT',
headers: HEADERS(),
body: JSON.stringify({ completedAt, id, choreId }),
})
}
const SkipChore = id => {
return Fetch(`/chores/${id}/skip`, {
method: 'POST',
@ -476,6 +485,7 @@ export {
ArchiveChore,
CancelSubscription,
ChangePassword,
CompleteSubTask,
CreateChore,
CreateLabel,
CreateLongLiveToken,

View file

@ -7,16 +7,10 @@ import {
const Priorities = [
{
name: 'P4',
value: 4,
icon: <HorizontalRule />,
color: '',
},
{
name: 'P3 ',
value: 3,
icon: <KeyboardControlKey />,
color: '',
name: 'P1',
value: 1,
icon: <PriorityHigh />,
color: 'danger',
},
{
name: 'P2',
@ -25,10 +19,16 @@ const Priorities = [
color: 'warning',
},
{
name: 'P1',
value: 1,
icon: <PriorityHigh />,
color: 'danger',
name: 'P3 ',
value: 3,
icon: <KeyboardControlKey />,
color: '',
},
{
name: 'P4',
value: 4,
icon: <HorizontalRule />,
color: '',
},
]