Refactor duration handling and enhance chore management features
- Replace hardcoded time units with TIME_UNITS constant in NotificationTemplate. - Introduce DurationInput component for reusable duration selection in ChoreEdit and AddTaskModal. - Update chore queries to refetch on window focus. - Adjust completion window logic in ChoreView and HistoryCard for better deadline handling. - Implement smart insights filter restoration in MyChores. - Add MyChoreHeader component for improved filter display. - Enhance activity notes display with truncation and modal view in ActivitiesCard.
This commit is contained in:
@@ -324,7 +324,7 @@ export const notInCompletionWindow = chore => {
|
||||
chore.completionWindow &&
|
||||
chore.completionWindow > -1 &&
|
||||
chore.nextDueDate &&
|
||||
moment().add(chore.completionWindow, 'hours') < moment(chore.nextDueDate)
|
||||
moment() < moment(chore.nextDueDate).add(-chore.completionWindow, 'seconds')
|
||||
)
|
||||
}
|
||||
export const ChoreFilters = userId => ({
|
||||
|
||||
18
src/utils/DurationUtils.js
Normal file
18
src/utils/DurationUtils.js
Normal file
@@ -0,0 +1,18 @@
|
||||
export const TIME_UNITS = [
|
||||
{ label: 'Mins', value: 'm', seconds: 60 },
|
||||
{ label: 'Hours', value: 'h', seconds: 3600 },
|
||||
{ label: 'Days', value: 'd', seconds: 86400 },
|
||||
]
|
||||
|
||||
export function secondsToValueAndUnit(totalSeconds) {
|
||||
if (totalSeconds % 86400 === 0)
|
||||
return { value: totalSeconds / 86400, unit: 'd' }
|
||||
if (totalSeconds % 3600 === 0)
|
||||
return { value: totalSeconds / 3600, unit: 'h' }
|
||||
return { value: Math.round(totalSeconds / 60), unit: 'm' }
|
||||
}
|
||||
|
||||
export function valueAndUnitToSeconds(value, unit) {
|
||||
const unitInfo = TIME_UNITS.find(u => u.value === unit)
|
||||
return value * (unitInfo?.seconds ?? 1)
|
||||
}
|
||||
Reference in New Issue
Block a user