added support for tasks

This commit is contained in:
dohsimpson
2025-01-22 17:59:59 -05:00
parent 3b33719e1a
commit d3502e284d
19 changed files with 223 additions and 105 deletions

View File

@@ -28,7 +28,12 @@ export function useCoins() {
return null
}
const data = await addCoins(amount, description, 'MANUAL_ADJUSTMENT', undefined, note)
const data = await addCoins({
amount,
description,
type: 'MANUAL_ADJUSTMENT',
note
})
setCoins(data)
toast({ title: "Success", description: `Added ${amount} coins` })
return data
@@ -44,7 +49,12 @@ export function useCoins() {
return null
}
const data = await removeCoins(numAmount, description, 'MANUAL_ADJUSTMENT', undefined, note)
const data = await removeCoins({
amount: numAmount,
description,
type: 'MANUAL_ADJUSTMENT',
note
})
setCoins(data)
toast({ title: "Success", description: `Removed ${numAmount} coins` })
return data

View File

@@ -51,12 +51,12 @@ export function useHabits() {
// Check if we've now reached the target
const isTargetReached = completionsToday + 1 === target
if (isTargetReached) {
const updatedCoins = await addCoins(
habit.coinReward,
`Completed habit: ${habit.name}`,
'HABIT_COMPLETION',
habit.id
)
const updatedCoins = await addCoins({
amount: habit.coinReward,
description: `Completed habit: ${habit.name}`,
type: habit.isTask ? 'TASK_COMPLETION' : 'HABIT_COMPLETION',
relatedItemId: habit.id,
})
setCoins(updatedCoins)
}
@@ -105,12 +105,12 @@ export function useHabits() {
// If we were at the target, remove the coins
const target = habit.targetCompletions || 1
if (todayCompletions.length === target) {
const updatedCoins = await removeCoins(
habit.coinReward,
`Undid habit completion: ${habit.name}`,
'HABIT_UNDO',
habit.id
)
const updatedCoins = await removeCoins({
amount: habit.coinReward,
description: `Undid habit completion: ${habit.name}`,
type: habit.isTask ? 'TASK_UNDO' : 'HABIT_UNDO',
relatedItemId: habit.id,
})
setCoins(updatedCoins)
}
@@ -205,12 +205,12 @@ export function useHabits() {
// Check if we've now reached the target
const isTargetReached = completionsOnDate + 1 === target
if (isTargetReached) {
const updatedCoins = await addCoins(
habit.coinReward,
`Completed habit: ${habit.name} on ${d2s({ dateTime: date, timezone, format: 'yyyy-MM-dd' })}`,
'HABIT_COMPLETION',
habit.id
)
const updatedCoins = await addCoins({
amount: habit.coinReward,
description: `Completed habit: ${habit.name} on ${d2s({ dateTime: date, timezone, format: 'yyyy-MM-dd' })}`,
type: habit.isTask ? 'TASK_COMPLETION' : 'HABIT_COMPLETION',
relatedItemId: habit.id,
})
setCoins(updatedCoins)
}

View File

@@ -33,12 +33,12 @@ export function useWishlist() {
const redeemWishlistItem = async (item: WishlistItemType) => {
if (balance >= item.coinCost) {
const data = await removeCoins(
item.coinCost,
`Redeemed reward: ${item.name}`,
'WISH_REDEMPTION',
item.id
)
const data = await removeCoins({
amount: item.coinCost,
description: `Redeemed reward: ${item.name}`,
type: 'WISH_REDEMPTION',
relatedItemId: item.id
})
setCoins(data)
// Randomly choose a celebration effect