From 41ae9df2a09c6c13172513fdc8cadb45e96c93bf Mon Sep 17 00:00:00 2001 From: Doh Date: Thu, 16 Jan 2025 20:40:51 -0500 Subject: [PATCH] fix pomo (#42) --- CHANGELOG.md | 11 ++++ components/ChangelogModal.tsx | 2 +- components/HabitItem.tsx | 100 ++++++++++++++++++++++++--------- components/HabitList.tsx | 2 +- components/PomodoroTimer.tsx | 21 +++---- components/WishlistItem.tsx | 100 ++++++++++++++++++++++++--------- components/WishlistManager.tsx | 2 +- components/ui/button.tsx | 3 +- package-lock.json | 4 +- package.json | 2 +- 10 files changed, 176 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ced7bd2..7fa0f04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## Version 0.1.20 + +### Changed + +- improved UI for habits and wishlist on mobile + +### Fixed + +- fix pomodoro break timer from triggering completions +- don't show progress on pomodoro for single completion habit + ## Version 0.1.19 ### Added diff --git a/components/ChangelogModal.tsx b/components/ChangelogModal.tsx index 2ef3523..1988f3f 100644 --- a/components/ChangelogModal.tsx +++ b/components/ChangelogModal.tsx @@ -27,7 +27,7 @@ export default function ChangelogModal({ isOpen, onClose }: ChangelogModalProps) - Changelog +
{changelog} diff --git a/components/HabitItem.tsx b/components/HabitItem.tsx index 1ffa141..1edd8df 100644 --- a/components/HabitItem.tsx +++ b/components/HabitItem.tsx @@ -3,8 +3,16 @@ import { useAtom } from 'jotai' import { settingsAtom } from '@/lib/atoms' import { getTodayInTimezone, isSameDate, t2d, d2t, getNow, parseNaturalLanguageRRule, parseRRule } from '@/lib/utils' import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card' +import ReactMarkdown from 'react-markdown' import { Button } from '@/components/ui/button' -import { Coins, Edit, Trash2, Check, Undo2 } from 'lucide-react' +import { Coins, Edit, Trash2, Check, Undo2, MoreVertical } from 'lucide-react' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from '@/components/ui/dropdown-menu' import { useEffect, useState } from 'react' import { useHabits } from '@/hooks/useHabits' import { RRule } from 'rrule' @@ -49,30 +57,24 @@ export default function HabitItem({ habit, onEdit, onDelete }: HabitItemProps) { return ( - - {habit.name} - {habit.description} + + {habit.name} + {habit.description && ( + + {habit.description} + + )} - +

Frequency: {parseRRule(habit.frequency || INITIAL_RECURRENCE_RULE).toText()}

{habit.coinReward} coins per completion
- -
- - -
+
)}
+
+ + + + + + + + + Edit + + + + + Delete + + + +
) diff --git a/components/HabitList.tsx b/components/HabitList.tsx index abb583f..9bbfb4c 100644 --- a/components/HabitList.tsx +++ b/components/HabitList.tsx @@ -33,7 +33,7 @@ export default function HabitList() { Add Habit
-
+
{habits.length === 0 ? (
{ setState("stopped") - currentTimer.current = currentTimer.current.type === 'focus' ? PomoConfigs.break : PomoConfigs.focus + const currentTimerType = currentTimer.current.type + currentTimer.current = currentTimerType === 'focus' ? PomoConfigs.break : PomoConfigs.focus setTimeLeft(currentTimer.current.duration) setCurrentLabel( currentTimer.current.labels[Math.floor(Math.random() * currentTimer.current.labels.length)] @@ -167,13 +168,10 @@ export default function PomodoroTimer() { // Play sound playSound() - // update habits - if (selectedHabit) { - const ret = await completeHabit(selectedHabit) - if (ret) { - const updatedHabit = ret.updatedHabits.find(h => h.id === selectedHabit.id) - // The atom will automatically update with the new completions - } + // update habits only after focus sessions + if (selectedHabit && currentTimerType === 'focus') { + await completeHabit(selectedHabit) + // The atom will automatically update with the new completions } } @@ -258,14 +256,13 @@ export default function PomodoroTimer() {
)} {currentTimer.current.type.charAt(0).toUpperCase() + currentTimer.current.type.slice(1)}: {currentLabel} - {selectedHabit && ( + {selectedHabit && selectedHabit.targetCompletions && selectedHabit.targetCompletions > 1 && (
{(() => { - const total = selectedHabit.targetCompletions || 1 // Show up to 7 items, but no more than the target completions - const maxItems = Math.min(7, total) + const maxItems = Math.min(7, selectedHabit.targetCompletions) // Calculate start position to center current completion - const start = Math.max(0, Math.min(todayCompletions - Math.floor(maxItems / 2), total - maxItems)) + const start = Math.max(0, Math.min(todayCompletions - Math.floor(maxItems / 2), selectedHabit.targetCompletions - maxItems)) return Array.from({ length: maxItems }).map((_, i) => { const cycle = start + i diff --git a/components/WishlistItem.tsx b/components/WishlistItem.tsx index e68e2c4..46bf06c 100644 --- a/components/WishlistItem.tsx +++ b/components/WishlistItem.tsx @@ -1,7 +1,15 @@ import { WishlistItemType } from '@/lib/types' import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card' +import ReactMarkdown from 'react-markdown' import { Button } from '@/components/ui/button' -import { Coins, Edit, Trash2, Gift } from 'lucide-react' +import { Coins, Edit, Trash2, Gift, MoreVertical } from 'lucide-react' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from '@/components/ui/dropdown-menu' interface WishlistItemProps { item: WishlistItemType @@ -25,43 +33,81 @@ export default function WishlistItem({ return ( - - {item.name} - {item.description} + + {item.name} + {item.description && ( + + {item.description} + + )} - +
{item.coinCost} coins
- -
- -
- +
+ + + + + + + + + Edit + + + + + Delete + + + +
) diff --git a/components/WishlistManager.tsx b/components/WishlistManager.tsx index 9f8d56f..924be67 100644 --- a/components/WishlistManager.tsx +++ b/components/WishlistManager.tsx @@ -68,7 +68,7 @@ export default function WishlistManager() { Add Reward
-
+
{wishlistItems.length === 0 ? (
, - VariantProps { + VariantProps { asChild?: boolean } diff --git a/package-lock.json b/package-lock.json index 330ccf9..e68e694 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "habittrove", - "version": "0.1.18", + "version": "0.1.19", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "habittrove", - "version": "0.1.18", + "version": "0.1.19", "dependencies": { "@emoji-mart/data": "^1.2.1", "@emoji-mart/react": "^1.1.1", diff --git a/package.json b/package.json index 446391d..c17ccc4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "habittrove", - "version": "0.1.19", + "version": "0.1.20", "private": true, "scripts": { "dev": "next dev --turbopack",