mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-03-10 04:19:49 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
6934432fb5
|
|||
|
|
95197e216c | ||
|
|
660005d857 | ||
|
|
2408ed84bd |
20
CHANGELOG.md
20
CHANGELOG.md
@@ -1,5 +1,25 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Version 0.2.11
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* support searching and sorting in habit list
|
||||||
|
|
||||||
|
### Improved
|
||||||
|
|
||||||
|
* Show overdue tasks in daily overview
|
||||||
|
* Context menu option for tasks changed from "Move to Today" to "Move to Tomorrow"
|
||||||
|
* More context menu items in daily overview
|
||||||
|
* code refactor for context menu and daily overview item section
|
||||||
|
|
||||||
|
|
||||||
|
## Version 0.2.10
|
||||||
|
|
||||||
|
### Improved
|
||||||
|
|
||||||
|
* performance optimization: faster load time for large data set
|
||||||
|
|
||||||
## Version 0.2.9
|
## Version 0.2.9
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ HabitTrove is a gamified habit tracking application that helps you build and mai
|
|||||||
|
|
||||||
## Try the Demo
|
## Try the Demo
|
||||||
|
|
||||||
Want to try HabitTrove before installing? Visit the public [demo instance](https://habittrove.app.enting.org) to experience all features without any setup required. (do not store personal info. Data on the demo instance is reset daily)
|
Want to try HabitTrove before installing? Visit the public [demo instance](https://demo.habittrove.com) to experience all features without any setup required. (do not store personal info. Data on the demo instance is reset daily)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,32 @@
|
|||||||
'use server'
|
'use server'
|
||||||
|
|
||||||
import fs from 'fs/promises'
|
import { getCurrentUser, saltAndHashPassword, verifyPassword } from "@/lib/server-helpers";
|
||||||
import path from 'path'
|
|
||||||
import {
|
import {
|
||||||
HabitsData,
|
|
||||||
CoinsData,
|
CoinsData,
|
||||||
CoinTransaction,
|
CoinTransaction,
|
||||||
TransactionType,
|
|
||||||
WishlistItemType,
|
|
||||||
WishlistData,
|
|
||||||
Settings,
|
|
||||||
DataType,
|
|
||||||
DATA_DEFAULTS,
|
DATA_DEFAULTS,
|
||||||
getDefaultSettings,
|
DataType,
|
||||||
UserData,
|
|
||||||
getDefaultUsersData,
|
|
||||||
User,
|
|
||||||
getDefaultWishlistData,
|
|
||||||
getDefaultHabitsData,
|
|
||||||
getDefaultCoinsData,
|
getDefaultCoinsData,
|
||||||
|
getDefaultHabitsData,
|
||||||
|
getDefaultSettings,
|
||||||
|
getDefaultUsersData,
|
||||||
|
getDefaultWishlistData,
|
||||||
|
HabitsData,
|
||||||
Permission,
|
Permission,
|
||||||
ServerSettings
|
ServerSettings,
|
||||||
} from '@/lib/types'
|
Settings,
|
||||||
import { d2t, deepMerge, getNow, checkPermission, uuid } from '@/lib/utils';
|
TransactionType,
|
||||||
import { verifyPassword } from "@/lib/server-helpers";
|
User,
|
||||||
import { saltAndHashPassword } from "@/lib/server-helpers";
|
UserData,
|
||||||
|
WishlistData,
|
||||||
|
WishlistItemType
|
||||||
|
} from '@/lib/types';
|
||||||
|
import { d2t, getNow, uuid } from '@/lib/utils';
|
||||||
import { signInSchema } from '@/lib/zod';
|
import { signInSchema } from '@/lib/zod';
|
||||||
import { auth } from '@/auth';
|
import fs from 'fs/promises';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { getCurrentUser, getCurrentUserId } from '@/lib/server-helpers'
|
import path from 'path';
|
||||||
|
|
||||||
import { PermissionError } from '@/lib/exceptions'
|
|
||||||
|
|
||||||
type ResourceType = 'habit' | 'wishlist' | 'coins'
|
type ResourceType = 'habit' | 'wishlist' | 'coins'
|
||||||
type ActionType = 'write' | 'interact'
|
type ActionType = 'write' | 'interact'
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import Layout from '@/components/Layout'
|
|
||||||
import HabitCalendar from '@/components/HabitCalendar'
|
import HabitCalendar from '@/components/HabitCalendar'
|
||||||
import { ViewToggle } from '@/components/ViewToggle'
|
|
||||||
import CompletionCountBadge from '@/components/CompletionCountBadge'
|
|
||||||
|
|
||||||
export default function CalendarPage() {
|
export default function CalendarPage() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import Layout from '@/components/Layout'
|
|
||||||
import CoinsManager from '@/components/CoinsManager'
|
import CoinsManager from '@/components/CoinsManager'
|
||||||
|
|
||||||
export default function CoinsPage() {
|
export default function CoinsPage() {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useHabits } from "@/hooks/useHabits";
|
|
||||||
import { habitsAtom, settingsAtom } from "@/lib/atoms";
|
import { habitsAtom, settingsAtom } from "@/lib/atoms";
|
||||||
import { Habit } from "@/lib/types";
|
import { Habit } from "@/lib/types";
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import Layout from '@/components/Layout'
|
|
||||||
import HabitList from '@/components/HabitList'
|
import HabitList from '@/components/HabitList'
|
||||||
import { ViewToggle } from '@/components/ViewToggle'
|
|
||||||
|
|
||||||
export default function HabitsPage() {
|
export default function HabitsPage() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import './globals.css'
|
|
||||||
import { Inter } from 'next/font/google'
|
|
||||||
import { DM_Sans } from 'next/font/google'
|
|
||||||
import { JotaiProvider } from '@/components/jotai-providers'
|
|
||||||
import { Suspense } from 'react'
|
|
||||||
import { JotaiHydrate } from '@/components/jotai-hydrate'
|
import { JotaiHydrate } from '@/components/jotai-hydrate'
|
||||||
import { loadSettings, loadHabitsData, loadCoinsData, loadWishlistData, loadUsersData, loadServerSettings } from './actions/data'
|
import { JotaiProvider } from '@/components/jotai-providers'
|
||||||
import Layout from '@/components/Layout'
|
import Layout from '@/components/Layout'
|
||||||
import { Toaster } from '@/components/ui/toaster'
|
|
||||||
import { ThemeProvider } from "@/components/theme-provider"
|
import { ThemeProvider } from "@/components/theme-provider"
|
||||||
|
import { Toaster } from '@/components/ui/toaster'
|
||||||
import { SessionProvider } from 'next-auth/react'
|
import { SessionProvider } from 'next-auth/react'
|
||||||
|
import { DM_Sans } from 'next/font/google'
|
||||||
|
import { Suspense } from 'react'
|
||||||
|
import { loadCoinsData, loadHabitsData, loadServerSettings, loadSettings, loadUsersData, loadWishlistData } from './actions/data'
|
||||||
|
import './globals.css'
|
||||||
|
|
||||||
|
|
||||||
// Inter (clean, modern, excellent readability)
|
// Inter (clean, modern, excellent readability)
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
import { DynamicTimeNoSSR } from '@/components/DynamicTimeNoSSR';
|
||||||
import { Switch } from '@/components/ui/switch';
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
|
import { Switch } from '@/components/ui/switch';
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
TooltipContent,
|
TooltipContent,
|
||||||
TooltipProvider,
|
TooltipProvider,
|
||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from "@/components/ui/tooltip";
|
} from "@/components/ui/tooltip";
|
||||||
import { DynamicTimeNoSSR } from '@/components/DynamicTimeNoSSR';
|
|
||||||
import { useAtom } from 'jotai';
|
|
||||||
import { settingsAtom } from '@/lib/atoms';
|
import { settingsAtom } from '@/lib/atoms';
|
||||||
import { Settings, WeekDay } from '@/lib/types'
|
import { Settings, WeekDay } from '@/lib/types';
|
||||||
import { saveSettings, uploadAvatar } from '../actions/data'
|
import { useAtom } from 'jotai';
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
|
import { Info } from 'lucide-react'; // Import Info icon
|
||||||
import { Button } from '@/components/ui/button';
|
import { saveSettings } from '../actions/data';
|
||||||
import { User, Info } from 'lucide-react'; // Import Info icon
|
|
||||||
|
|
||||||
export default function SettingsPage() {
|
export default function SettingsPage() {
|
||||||
const [settings, setSettings] = useAtom(settingsAtom);
|
const [settings, setSettings] = useAtom(settingsAtom);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import Layout from '@/components/Layout'
|
|
||||||
import WishlistManager from '@/components/WishlistManager'
|
import WishlistManager from '@/components/WishlistManager'
|
||||||
|
|
||||||
export default function WishlistPage() {
|
export default function WishlistPage() {
|
||||||
|
|||||||
@@ -1,33 +1,24 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
|
||||||
import { RRule, RRuleSet, rrulestr } from 'rrule'
|
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { settingsAtom, browserSettingsAtom, usersAtom } from '@/lib/atoms'
|
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'
|
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'
|
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||||
import { Switch } from '@/components/ui/switch'
|
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import { Textarea } from '@/components/ui/textarea'
|
|
||||||
import { Info, SmilePlus, Zap } from 'lucide-react'
|
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
||||||
|
import { Textarea } from '@/components/ui/textarea'
|
||||||
|
import { settingsAtom, usersAtom } from '@/lib/atoms'
|
||||||
|
import { useHelpers } from '@/lib/client-helpers'
|
||||||
|
import { INITIAL_DUE, INITIAL_RECURRENCE_RULE, QUICK_DATES } from '@/lib/constants'
|
||||||
|
import { Habit } from '@/lib/types'
|
||||||
|
import { convertHumanReadableFrequencyToMachineReadable, convertMachineReadableFrequencyToHumanReadable, d2t, serializeRRule } from '@/lib/utils'
|
||||||
import data from '@emoji-mart/data'
|
import data from '@emoji-mart/data'
|
||||||
import Picker from '@emoji-mart/react'
|
import Picker from '@emoji-mart/react'
|
||||||
import { Habit, SafeUser } from '@/lib/types'
|
import { useAtom } from 'jotai'
|
||||||
import { convertHumanReadableFrequencyToMachineReadable, convertMachineReadableFrequencyToHumanReadable, d2s, d2t, serializeRRule } from '@/lib/utils'
|
import { SmilePlus, Zap } from 'lucide-react'
|
||||||
import { INITIAL_DUE, INITIAL_RECURRENCE_RULE, QUICK_DATES, RECURRENCE_RULE_MAP } from '@/lib/constants'
|
|
||||||
import * as chrono from 'chrono-node';
|
|
||||||
import { DateTime } from 'luxon'
|
import { DateTime } from 'luxon'
|
||||||
import {
|
import { useState } from 'react'
|
||||||
Select,
|
import { RRule } from 'rrule'
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from "@/components/ui/select"
|
|
||||||
import { useHelpers } from '@/lib/client-helpers'
|
|
||||||
|
|
||||||
interface AddEditHabitModalProps {
|
interface AddEditHabitModalProps {
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
import { useState, useEffect } from 'react'
|
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { usersAtom } from '@/lib/atoms'
|
|
||||||
import { useHelpers } from '@/lib/client-helpers'
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar'
|
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'
|
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import { Textarea } from '@/components/ui/textarea'
|
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
||||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
import { Textarea } from '@/components/ui/textarea'
|
||||||
import { SmilePlus, Info } from 'lucide-react'
|
import { usersAtom } from '@/lib/atoms'
|
||||||
|
import { useHelpers } from '@/lib/client-helpers'
|
||||||
|
import { WishlistItemType } from '@/lib/types'
|
||||||
import data from '@emoji-mart/data'
|
import data from '@emoji-mart/data'
|
||||||
import Picker from '@emoji-mart/react'
|
import Picker from '@emoji-mart/react'
|
||||||
import { WishlistItemType } from '@/lib/types'
|
import { useAtom } from 'jotai'
|
||||||
|
import { SmilePlus } from 'lucide-react'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar'
|
||||||
|
|
||||||
interface AddEditWishlistItemModalProps {
|
interface AddEditWishlistItemModalProps {
|
||||||
isOpen: boolean
|
isOpen: boolean
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export default function ClientWrapper({ children }: { children: ReactNode }) {
|
|||||||
if (!currentUserId && !userSelect) {
|
if (!currentUserId && !userSelect) {
|
||||||
setUserSelect(true)
|
setUserSelect(true)
|
||||||
}
|
}
|
||||||
}, [currentUserId, status, userSelect])
|
}, [currentUserId, status, userSelect, setUserSelect])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState, useEffect, useRef } from 'react' // Import useEffect, useRef
|
|
||||||
import { useSearchParams } from 'next/navigation' // Import useSearchParams
|
|
||||||
import { t2d, d2s, getNow, isSameDate } from '@/lib/utils'
|
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import { FormattedNumber } from '@/components/FormattedNumber'
|
import { FormattedNumber } from '@/components/FormattedNumber'
|
||||||
import { History, Pencil } from 'lucide-react'
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
|
||||||
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'
|
import { Button } from '@/components/ui/button'
|
||||||
import EmptyState from './EmptyState'
|
|
||||||
import { Input } from '@/components/ui/input'
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import { settingsAtom, usersAtom } from '@/lib/atoms'
|
import { Input } from '@/components/ui/input'
|
||||||
import Link from 'next/link'
|
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { useCoins } from '@/hooks/useCoins'
|
import { useCoins } from '@/hooks/useCoins'
|
||||||
import { TransactionNoteEditor } from './TransactionNoteEditor'
|
import { settingsAtom, usersAtom } from '@/lib/atoms'
|
||||||
import { useHelpers } from '@/lib/client-helpers'
|
import { useHelpers } from '@/lib/client-helpers'
|
||||||
|
import { d2s, t2d } from '@/lib/utils'
|
||||||
|
import { useAtom } from 'jotai'
|
||||||
|
import { History } from 'lucide-react'
|
||||||
|
import Link from 'next/link'
|
||||||
|
import { useSearchParams } from 'next/navigation'; // Import useSearchParams
|
||||||
|
import { useEffect, useRef, useState } from 'react'; // Import useEffect, useRef
|
||||||
|
import EmptyState from './EmptyState'
|
||||||
|
import { TransactionNoteEditor } from './TransactionNoteEditor'
|
||||||
|
|
||||||
export default function CoinsManager() {
|
export default function CoinsManager() {
|
||||||
const { currentUser } = useHelpers()
|
const { currentUser } = useHelpers()
|
||||||
@@ -53,7 +53,7 @@ export default function CoinsManager() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only run when userIdFromQuery or currentUser changes, avoid re-running on selectedUser change within this effect
|
// Only run when userIdFromQuery or currentUser changes, avoid re-running on selectedUser change within this effect
|
||||||
}, [userIdFromQuery, currentUser, usersData.users]);
|
}, [userIdFromQuery, currentUser, usersData.users, selectedUser]);
|
||||||
|
|
||||||
// Effect to scroll to highlighted transaction
|
// Effect to scroll to highlighted transaction
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { useAtom } from 'jotai'
|
import { completedHabitsMapAtom, habitsByDateFamily, settingsAtom } from '@/lib/atoms'
|
||||||
import { completedHabitsMapAtom, habitsAtom, habitsByDateFamily } from '@/lib/atoms'
|
|
||||||
import { getTodayInTimezone } from '@/lib/utils'
|
import { getTodayInTimezone } from '@/lib/utils'
|
||||||
import { useHabits } from '@/hooks/useHabits'
|
import { useAtom } from 'jotai'
|
||||||
import { settingsAtom } from '@/lib/atoms'
|
|
||||||
|
|
||||||
interface CompletionCountBadgeProps {
|
interface CompletionCountBadgeProps {
|
||||||
type: 'habits' | 'tasks'
|
type: 'habits' | 'tasks'
|
||||||
|
|||||||
@@ -1,25 +1,30 @@
|
|||||||
import { Circle, Coins, ArrowRight, CircleCheck, ChevronDown, ChevronUp, Timer, Plus, Pin, Calendar } from 'lucide-react'
|
import { Badge } from '@/components/ui/badge'
|
||||||
import CompletionCountBadge from './CompletionCountBadge'
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import {
|
import {
|
||||||
ContextMenu,
|
ContextMenu,
|
||||||
ContextMenuContent,
|
ContextMenuContent,
|
||||||
ContextMenuItem,
|
ContextMenuTrigger
|
||||||
ContextMenuTrigger,
|
|
||||||
} from "@/components/ui/context-menu"
|
} from "@/components/ui/context-menu"
|
||||||
import { cn, getHabitFreq } from '@/lib/utils'
|
import { Progress } from '@/components/ui/progress'
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip"
|
||||||
|
import { useHabits } from '@/hooks/useHabits'
|
||||||
|
import { browserSettingsAtom, completedHabitsMapAtom, hasTasksAtom, pomodoroAtom, settingsAtom } from '@/lib/atoms'
|
||||||
|
import { Habit, WishlistItemType } from '@/lib/types'
|
||||||
|
import { cn, d2t, getNow, getTodayInTimezone, isHabitDue, isSameDate, isTaskOverdue, t2d } from '@/lib/utils'
|
||||||
|
import { useAtom } from 'jotai'
|
||||||
|
import { AlertTriangle, ArrowRight, ChevronDown, ChevronUp, Circle, CircleCheck, Coins, Pin, Plus } from 'lucide-react'; // Removed unused icons
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { pomodoroAtom, settingsAtom, completedHabitsMapAtom, browserSettingsAtom, BrowserSettings, hasTasksAtom, dailyHabitsAtom } from '@/lib/atoms'
|
|
||||||
import { getTodayInTimezone, isSameDate, t2d, d2t, getNow } from '@/lib/utils'
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
|
||||||
import { Badge } from '@/components/ui/badge'
|
|
||||||
import { Progress } from '@/components/ui/progress'
|
|
||||||
import { Settings, WishlistItemType } from '@/lib/types'
|
|
||||||
import { Habit } from '@/lib/types'
|
|
||||||
import Linkify from './linkify'
|
|
||||||
import { useHabits } from '@/hooks/useHabits'
|
|
||||||
import AddEditHabitModal from './AddEditHabitModal'
|
import AddEditHabitModal from './AddEditHabitModal'
|
||||||
|
import CompletionCountBadge from './CompletionCountBadge'
|
||||||
|
import ConfirmDialog from './ConfirmDialog'
|
||||||
|
import { HabitContextMenuItems } from './HabitContextMenuItems'
|
||||||
|
import Linkify from './linkify'
|
||||||
import { Button } from './ui/button'
|
import { Button } from './ui/button'
|
||||||
|
|
||||||
interface UpcomingItemsProps {
|
interface UpcomingItemsProps {
|
||||||
@@ -34,13 +39,7 @@ interface ItemSectionProps {
|
|||||||
emptyMessage: string;
|
emptyMessage: string;
|
||||||
isTask: boolean;
|
isTask: boolean;
|
||||||
viewLink: string;
|
viewLink: string;
|
||||||
expanded: boolean;
|
|
||||||
setExpanded: (value: boolean) => void;
|
|
||||||
addNewItem: () => void;
|
addNewItem: () => void;
|
||||||
badgeType: "tasks" | "habits";
|
|
||||||
todayCompletions: Habit[];
|
|
||||||
settings: Settings;
|
|
||||||
setBrowserSettings: (value: React.SetStateAction<BrowserSettings>) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ItemSection = ({
|
const ItemSection = ({
|
||||||
@@ -49,16 +48,46 @@ const ItemSection = ({
|
|||||||
emptyMessage,
|
emptyMessage,
|
||||||
isTask,
|
isTask,
|
||||||
viewLink,
|
viewLink,
|
||||||
expanded,
|
|
||||||
setExpanded,
|
|
||||||
addNewItem,
|
addNewItem,
|
||||||
badgeType,
|
|
||||||
todayCompletions,
|
|
||||||
settings,
|
|
||||||
setBrowserSettings,
|
|
||||||
}: ItemSectionProps) => {
|
}: ItemSectionProps) => {
|
||||||
const { completeHabit, undoComplete, saveHabit } = useHabits();
|
const { completeHabit, undoComplete, saveHabit, deleteHabit, archiveHabit, habitFreqMap } = useHabits();
|
||||||
const [_, setPomo] = useAtom(pomodoroAtom);
|
const [_, setPomo] = useAtom(pomodoroAtom);
|
||||||
|
const [browserSettings, setBrowserSettings] = useAtom(browserSettingsAtom);
|
||||||
|
const [settings] = useAtom(settingsAtom);
|
||||||
|
const [completedHabitsMap] = useAtom(completedHabitsMapAtom);
|
||||||
|
|
||||||
|
const today = getTodayInTimezone(settings.system.timezone);
|
||||||
|
const currentTodayCompletions = completedHabitsMap.get(today) || [];
|
||||||
|
const currentBadgeType = isTask ? 'tasks' : 'habits';
|
||||||
|
|
||||||
|
const currentExpanded = isTask ? browserSettings.expandedTasks : browserSettings.expandedHabits;
|
||||||
|
const setCurrentExpanded = (value: boolean) => {
|
||||||
|
setBrowserSettings(prev => ({
|
||||||
|
...prev,
|
||||||
|
[isTask ? 'expandedTasks' : 'expandedHabits']: value
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const [isConfirmDeleteDialogOpen, setIsConfirmDeleteDialogOpen] = useState(false);
|
||||||
|
const [habitToDelete, setHabitToDelete] = useState<Habit | null>(null);
|
||||||
|
const [habitToEdit, setHabitToEdit] = useState<Habit | null>(null);
|
||||||
|
|
||||||
|
const handleDeleteClick = (habit: Habit) => {
|
||||||
|
setHabitToDelete(habit);
|
||||||
|
setIsConfirmDeleteDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmDelete = async () => {
|
||||||
|
if (habitToDelete) {
|
||||||
|
await deleteHabit(habitToDelete.id);
|
||||||
|
setHabitToDelete(null);
|
||||||
|
setIsConfirmDeleteDialogOpen(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditClick = (habit: Habit) => {
|
||||||
|
setHabitToEdit(habit);
|
||||||
|
};
|
||||||
|
|
||||||
if (items.length === 0) {
|
if (items.length === 0) {
|
||||||
return (
|
return (
|
||||||
@@ -89,7 +118,7 @@ const ItemSection = ({
|
|||||||
<h3 className="font-semibold">{title}</h3>
|
<h3 className="font-semibold">{title}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<CompletionCountBadge type={badgeType} />
|
<CompletionCountBadge type={currentBadgeType} />
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -101,7 +130,7 @@ const ItemSection = ({
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul className={`grid gap-2 transition-all duration-300 ease-in-out ${expanded ? 'max-h-none' : 'max-h-[200px]'} overflow-hidden`}>
|
<ul className={`grid gap-2 transition-all duration-300 ease-in-out ${currentExpanded ? 'max-h-none' : 'max-h-[200px]'} overflow-hidden`}>
|
||||||
{items
|
{items
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
// First by pinned status
|
// First by pinned status
|
||||||
@@ -110,15 +139,15 @@ const ItemSection = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Then by completion status
|
// Then by completion status
|
||||||
const aCompleted = todayCompletions.includes(a);
|
const aCompleted = currentTodayCompletions.includes(a);
|
||||||
const bCompleted = todayCompletions.includes(b);
|
const bCompleted = currentTodayCompletions.includes(b);
|
||||||
if (aCompleted !== bCompleted) {
|
if (aCompleted !== bCompleted) {
|
||||||
return aCompleted ? 1 : -1;
|
return aCompleted ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then by frequency (daily first)
|
// Then by frequency (daily first)
|
||||||
const aFreq = getHabitFreq(a);
|
const aFreq = habitFreqMap.get(a.id) || 'daily';
|
||||||
const bFreq = getHabitFreq(b);
|
const bFreq = habitFreqMap.get(b.id) || 'daily';
|
||||||
const freqOrder = ['daily', 'weekly', 'monthly', 'yearly'];
|
const freqOrder = ['daily', 'weekly', 'monthly', 'yearly'];
|
||||||
if (freqOrder.indexOf(aFreq) !== freqOrder.indexOf(bFreq)) {
|
if (freqOrder.indexOf(aFreq) !== freqOrder.indexOf(bFreq)) {
|
||||||
return freqOrder.indexOf(aFreq) - freqOrder.indexOf(bFreq);
|
return freqOrder.indexOf(aFreq) - freqOrder.indexOf(bFreq);
|
||||||
@@ -134,7 +163,7 @@ const ItemSection = ({
|
|||||||
const bTarget = b.targetCompletions || 1;
|
const bTarget = b.targetCompletions || 1;
|
||||||
return bTarget - aTarget;
|
return bTarget - aTarget;
|
||||||
})
|
})
|
||||||
.slice(0, expanded ? undefined : 5)
|
.slice(0, currentExpanded ? undefined : 5)
|
||||||
.map((habit) => {
|
.map((habit) => {
|
||||||
const completionsToday = habit.completions.filter(completion =>
|
const completionsToday = habit.completions.filter(completion =>
|
||||||
isSameDate(t2d({ timestamp: completion, timezone: settings.system.timezone }), t2d({ timestamp: d2t({ dateTime: getNow({ timezone: settings.system.timezone }) }), timezone: settings.system.timezone }))
|
isSameDate(t2d({ timestamp: completion, timezone: settings.system.timezone }), t2d({ timestamp: d2t({ dateTime: getNow({ timezone: settings.system.timezone }) }), timezone: settings.system.timezone }))
|
||||||
@@ -190,50 +219,46 @@ const ItemSection = ({
|
|||||||
)}
|
)}
|
||||||
<Link
|
<Link
|
||||||
href={`/habits?highlight=${habit.id}`}
|
href={`/habits?highlight=${habit.id}`}
|
||||||
className={cn(
|
className="flex items-center gap-1 hover:text-primary transition-colors"
|
||||||
isCompleted ? 'line-through' : '',
|
onClick={() => {
|
||||||
'break-all hover:text-primary transition-colors'
|
const newViewType = isTask ? 'tasks' : 'habits';
|
||||||
)}
|
if (browserSettings.viewType !== newViewType) {
|
||||||
|
setBrowserSettings(prev => ({ ...prev, viewType: newViewType }));
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{habit.name}
|
{isTask && isTaskOverdue(habit, settings.system.timezone) && !isCompleted && (
|
||||||
|
<TooltipProvider>
|
||||||
|
<Tooltip delayDuration={0}>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
{/* The AlertTriangle itself doesn't need hover styles if the parent Link handles it */}
|
||||||
|
<AlertTriangle className="h-4 w-4 flex-shrink-0 text-red-600 dark:text-red-500" />
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
<p>Overdue</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
)}
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
isCompleted ? 'line-through' : '',
|
||||||
|
'break-all' // Text specific styles
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{habit.name}
|
||||||
|
</span>
|
||||||
</Link>
|
</Link>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</ContextMenuTrigger>
|
</ContextMenuTrigger>
|
||||||
<ContextMenuContent className="w-64">
|
<ContextMenuContent className="w-64">
|
||||||
<ContextMenuItem onClick={() => {
|
<HabitContextMenuItems
|
||||||
setPomo((prev) => ({
|
habit={habit}
|
||||||
...prev,
|
onEditRequest={() => handleEditClick(habit)}
|
||||||
show: true,
|
onDeleteRequest={() => handleDeleteClick(habit)}
|
||||||
selectedHabitId: habit.id
|
context="daily-overview"
|
||||||
}))
|
/>
|
||||||
}}>
|
|
||||||
<Timer className="mr-2 h-4 w-4" />
|
|
||||||
<span>Start Pomodoro</span>
|
|
||||||
</ContextMenuItem>
|
|
||||||
{habit.isTask && (
|
|
||||||
<ContextMenuItem onClick={() => {
|
|
||||||
saveHabit({...habit, frequency: d2t({ dateTime: getNow({ timezone: settings.system.timezone })})})
|
|
||||||
}}>
|
|
||||||
<Calendar className="mr-2 h-4 w-4" />
|
|
||||||
<span>Move to Today</span>
|
|
||||||
</ContextMenuItem>
|
|
||||||
)}
|
|
||||||
<ContextMenuItem onClick={() => {
|
|
||||||
saveHabit({ ...habit, pinned: !habit.pinned })
|
|
||||||
}}>
|
|
||||||
{habit.pinned ? (
|
|
||||||
<>
|
|
||||||
<Pin className="mr-2 h-4 w-4" />
|
|
||||||
<span>Unpin</span>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Pin className="mr-2 h-4 w-4" />
|
|
||||||
<span>Pin</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</ContextMenuItem>
|
|
||||||
</ContextMenuContent>
|
</ContextMenuContent>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</span>
|
</span>
|
||||||
@@ -243,9 +268,9 @@ const ItemSection = ({
|
|||||||
{completionsToday}/{target}
|
{completionsToday}/{target}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{getHabitFreq(habit) !== 'daily' && (
|
{habitFreqMap.get(habit.id) !== 'daily' && (
|
||||||
<Badge variant="outline" className="text-xs">
|
<Badge variant="outline" className="text-xs">
|
||||||
{getHabitFreq(habit)}
|
{habitFreqMap.get(habit.id)}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
<span className="flex items-center">
|
<span className="flex items-center">
|
||||||
@@ -271,10 +296,10 @@ const ItemSection = ({
|
|||||||
</ul>
|
</ul>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<button
|
<button
|
||||||
onClick={() => setExpanded(!expanded)}
|
onClick={() => setCurrentExpanded(!currentExpanded)}
|
||||||
className="text-sm text-muted-foreground hover:text-primary flex items-center gap-1"
|
className="text-sm text-muted-foreground hover:text-primary flex items-center gap-1"
|
||||||
>
|
>
|
||||||
{expanded ? (
|
{currentExpanded ? (
|
||||||
<>
|
<>
|
||||||
Show less
|
Show less
|
||||||
<ChevronUp className="h-3 w-3" />
|
<ChevronUp className="h-3 w-3" />
|
||||||
@@ -290,10 +315,9 @@ const ItemSection = ({
|
|||||||
href={viewLink}
|
href={viewLink}
|
||||||
className="text-sm text-muted-foreground hover:text-primary flex items-center gap-1"
|
className="text-sm text-muted-foreground hover:text-primary flex items-center gap-1"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (isTask) {
|
const newViewType = isTask ? 'tasks' : 'habits';
|
||||||
setBrowserSettings(prev => ({ ...prev, viewType: 'tasks' }));
|
if (browserSettings.viewType !== newViewType) {
|
||||||
} else {
|
setBrowserSettings(prev => ({ ...prev, viewType: newViewType }));
|
||||||
setBrowserSettings(prev => ({ ...prev, viewType: 'habits' }));
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -301,6 +325,27 @@ const ItemSection = ({
|
|||||||
<ArrowRight className="h-3 w-3" />
|
<ArrowRight className="h-3 w-3" />
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
{habitToDelete && (
|
||||||
|
<ConfirmDialog
|
||||||
|
isOpen={isConfirmDeleteDialogOpen}
|
||||||
|
onClose={() => setIsConfirmDeleteDialogOpen(false)}
|
||||||
|
onConfirm={confirmDelete}
|
||||||
|
title={`Delete ${isTask ? 'Task' : 'Habit'}`}
|
||||||
|
message={`Are you sure you want to delete "${habitToDelete.name}"? This action cannot be undone.`}
|
||||||
|
confirmText="Delete"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{habitToEdit && (
|
||||||
|
<AddEditHabitModal
|
||||||
|
onClose={() => setHabitToEdit(null)}
|
||||||
|
onSave={async (updatedHabit) => {
|
||||||
|
await saveHabit({ ...habitToEdit, ...updatedHabit });
|
||||||
|
setHabitToEdit(null);
|
||||||
|
}}
|
||||||
|
habit={habitToEdit}
|
||||||
|
isTask={habitToEdit.isTask || false}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -313,14 +358,25 @@ export default function DailyOverview({
|
|||||||
const { completeHabit, undoComplete } = useHabits()
|
const { completeHabit, undoComplete } = useHabits()
|
||||||
const [settings] = useAtom(settingsAtom)
|
const [settings] = useAtom(settingsAtom)
|
||||||
const [completedHabitsMap] = useAtom(completedHabitsMapAtom)
|
const [completedHabitsMap] = useAtom(completedHabitsMapAtom)
|
||||||
const [dailyItems] = useAtom(dailyHabitsAtom)
|
|
||||||
const [browserSettings, setBrowserSettings] = useAtom(browserSettingsAtom)
|
const [browserSettings, setBrowserSettings] = useAtom(browserSettingsAtom)
|
||||||
const dailyTasks = dailyItems.filter(habit => habit.isTask)
|
|
||||||
const dailyHabits = dailyItems.filter(habit => !habit.isTask)
|
|
||||||
const today = getTodayInTimezone(settings.system.timezone)
|
const today = getTodayInTimezone(settings.system.timezone)
|
||||||
const todayCompletions = completedHabitsMap.get(today) || []
|
const todayCompletions = completedHabitsMap.get(today) || []
|
||||||
const { saveHabit } = useHabits()
|
const { saveHabit } = useHabits()
|
||||||
|
|
||||||
|
const timezone = settings.system.timezone
|
||||||
|
const todayDateObj = getNow({ timezone })
|
||||||
|
|
||||||
|
const dailyTasks = habits.filter(habit =>
|
||||||
|
habit.isTask &&
|
||||||
|
!habit.archived &&
|
||||||
|
(isHabitDue({ habit, timezone, date: todayDateObj }) || isTaskOverdue(habit, timezone))
|
||||||
|
)
|
||||||
|
const dailyHabits = habits.filter(habit =>
|
||||||
|
!habit.isTask &&
|
||||||
|
!habit.archived &&
|
||||||
|
isHabitDue({ habit, timezone, date: todayDateObj })
|
||||||
|
)
|
||||||
|
|
||||||
// Get all wishlist items sorted by redeemable status (non-redeemable first) then by coin cost
|
// Get all wishlist items sorted by redeemable status (non-redeemable first) then by coin cost
|
||||||
// Filter out archived wishlist items
|
// Filter out archived wishlist items
|
||||||
const sortedWishlistItems = wishlistItems
|
const sortedWishlistItems = wishlistItems
|
||||||
@@ -364,13 +420,7 @@ export default function DailyOverview({
|
|||||||
emptyMessage="No tasks due today. Add some tasks to get started!"
|
emptyMessage="No tasks due today. Add some tasks to get started!"
|
||||||
isTask={true}
|
isTask={true}
|
||||||
viewLink="/habits?view=tasks"
|
viewLink="/habits?view=tasks"
|
||||||
expanded={browserSettings.expandedTasks}
|
|
||||||
setExpanded={(value) => setBrowserSettings(prev => ({ ...prev, expandedTasks: value }))}
|
|
||||||
addNewItem={() => setModalConfig({ isOpen: true, isTask: true })}
|
addNewItem={() => setModalConfig({ isOpen: true, isTask: true })}
|
||||||
badgeType="tasks"
|
|
||||||
todayCompletions={todayCompletions}
|
|
||||||
settings={settings}
|
|
||||||
setBrowserSettings={setBrowserSettings}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -381,13 +431,7 @@ export default function DailyOverview({
|
|||||||
emptyMessage="No habits due today. Add some habits to get started!"
|
emptyMessage="No habits due today. Add some habits to get started!"
|
||||||
isTask={false}
|
isTask={false}
|
||||||
viewLink="/habits"
|
viewLink="/habits"
|
||||||
expanded={browserSettings.expandedHabits}
|
|
||||||
setExpanded={(value) => setBrowserSettings(prev => ({ ...prev, expandedHabits: value }))}
|
|
||||||
addNewItem={() => setModalConfig({ isOpen: true, isTask: false })}
|
addNewItem={() => setModalConfig({ isOpen: true, isTask: false })}
|
||||||
badgeType="habits"
|
|
||||||
todayCompletions={todayCompletions}
|
|
||||||
settings={settings}
|
|
||||||
setBrowserSettings={setBrowserSettings}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
|
import { useCoins } from '@/hooks/useCoins'
|
||||||
|
import { habitsAtom, wishlistAtom } from '@/lib/atoms'
|
||||||
import { useAtom } from 'jotai'
|
import { useAtom } from 'jotai'
|
||||||
import { wishlistAtom, habitsAtom, settingsAtom } from '@/lib/atoms'
|
import CoinBalance from './CoinBalance'
|
||||||
import DailyOverview from './DailyOverview'
|
import DailyOverview from './DailyOverview'
|
||||||
import HabitStreak from './HabitStreak'
|
import HabitStreak from './HabitStreak'
|
||||||
import CoinBalance from './CoinBalance'
|
|
||||||
import { useHabits } from '@/hooks/useHabits'
|
|
||||||
import { useCoins } from '@/hooks/useCoins'
|
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function Dashboard() {
|
||||||
const [habitsData] = useAtom(habitsAtom)
|
const [habitsData] = useAtom(habitsAtom)
|
||||||
const habits = habitsData.habits
|
const habits = habitsData.habits
|
||||||
const [settings] = useAtom(settingsAtom)
|
|
||||||
const { balance } = useCoins()
|
const { balance } = useCoins()
|
||||||
const [wishlist] = useAtom(wishlistAtom)
|
const [wishlist] = useAtom(wishlistAtom)
|
||||||
const wishlistItems = wishlist.items
|
const wishlistItems = wishlist.items
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState, useMemo, useCallback } from 'react'
|
import CompletionCountBadge from '@/components/CompletionCountBadge'
|
||||||
import { Calendar } from '@/components/ui/calendar'
|
import { Calendar } from '@/components/ui/calendar'
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import CompletionCountBadge from '@/components/CompletionCountBadge'
|
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import { Check, Circle, CircleCheck } from 'lucide-react'
|
|
||||||
import { d2s, getNow, t2d, getCompletedHabitsForDate, isHabitDue, getISODate, getCompletionsForToday, getCompletionsForDate } from '@/lib/utils'
|
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { useHabits } from '@/hooks/useHabits'
|
import { useHabits } from '@/hooks/useHabits'
|
||||||
import { habitsAtom, settingsAtom, completedHabitsMapAtom, hasTasksAtom } from '@/lib/atoms'
|
import { completedHabitsMapAtom, habitsAtom, hasTasksAtom, settingsAtom } from '@/lib/atoms'
|
||||||
import { DateTime } from 'luxon'
|
|
||||||
import Linkify from './linkify'
|
|
||||||
import { Habit } from '@/lib/types'
|
import { Habit } from '@/lib/types'
|
||||||
|
import { d2s, getCompletionsForDate, getISODate, getNow, isHabitDue } from '@/lib/utils'
|
||||||
|
import { useAtom } from 'jotai'
|
||||||
|
import { Circle, CircleCheck } from 'lucide-react'
|
||||||
|
import { DateTime } from 'luxon'
|
||||||
|
import { useCallback, useMemo, useState } from 'react'
|
||||||
|
import Linkify from './linkify'
|
||||||
|
|
||||||
export default function HabitCalendar() {
|
export default function HabitCalendar() {
|
||||||
const { completePastHabit } = useHabits()
|
const { completePastHabit } = useHabits()
|
||||||
|
|||||||
157
components/HabitContextMenuItems.tsx
Normal file
157
components/HabitContextMenuItems.tsx
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
import { Habit } from '@/lib/types';
|
||||||
|
import { useHabits } from '@/hooks/useHabits';
|
||||||
|
import { useAtom } from 'jotai';
|
||||||
|
import { pomodoroAtom, settingsAtom } from '@/lib/atoms';
|
||||||
|
import { d2t, getNow, isHabitDueToday } from '@/lib/utils';
|
||||||
|
import { DropdownMenuItem, DropdownMenuSeparator } from '@/components/ui/dropdown-menu';
|
||||||
|
import { ContextMenuItem, ContextMenuSeparator } from '@/components/ui/context-menu';
|
||||||
|
import { Timer, Calendar, Pin, Edit, Archive, ArchiveRestore, Trash2 } from 'lucide-react';
|
||||||
|
import { useHelpers } from '@/lib/client-helpers'; // For permission checks if needed, though useHabits handles most
|
||||||
|
|
||||||
|
interface HabitContextMenuItemsProps {
|
||||||
|
habit: Habit;
|
||||||
|
onEditRequest: () => void;
|
||||||
|
onDeleteRequest: () => void;
|
||||||
|
context?: 'daily-overview' | 'habit-item';
|
||||||
|
onClose?: () => void; // Optional: To close the dropdown if an action is taken
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HabitContextMenuItems({
|
||||||
|
habit,
|
||||||
|
onEditRequest,
|
||||||
|
onDeleteRequest,
|
||||||
|
context = 'habit-item',
|
||||||
|
onClose,
|
||||||
|
}: HabitContextMenuItemsProps) {
|
||||||
|
const { saveHabit, archiveHabit, unarchiveHabit } = useHabits();
|
||||||
|
const [settings] = useAtom(settingsAtom);
|
||||||
|
const [, setPomo] = useAtom(pomodoroAtom);
|
||||||
|
const { hasPermission } = useHelpers(); // Assuming useHabits handles permissions for its actions
|
||||||
|
|
||||||
|
const canWrite = hasPermission('habit', 'write'); // For UI disabling if not handled by useHabits' actions
|
||||||
|
const canInteract = hasPermission('habit', 'interact');
|
||||||
|
|
||||||
|
const MenuItemComponent = context === 'daily-overview' ? ContextMenuItem : DropdownMenuItem;
|
||||||
|
const MenuSeparatorComponent = context === 'daily-overview' ? ContextMenuSeparator : DropdownMenuSeparator;
|
||||||
|
|
||||||
|
const taskIsDueToday = habit.isTask ? isHabitDueToday({ habit, timezone: settings.system.timezone }) : false;
|
||||||
|
|
||||||
|
const handleAction = (action: () => void) => {
|
||||||
|
action();
|
||||||
|
onClose?.();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{!habit.archived && (
|
||||||
|
<MenuItemComponent
|
||||||
|
disabled={!canInteract}
|
||||||
|
onClick={() => handleAction(() => {
|
||||||
|
setPomo((prev) => ({
|
||||||
|
...prev,
|
||||||
|
show: true,
|
||||||
|
selectedHabitId: habit.id,
|
||||||
|
}));
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Timer className="mr-2 h-4 w-4" />
|
||||||
|
<span>Start Pomodoro</span>
|
||||||
|
</MenuItemComponent>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* "Move to Today" option: Show if task is not due today */}
|
||||||
|
{habit.isTask && !habit.archived && !taskIsDueToday && (
|
||||||
|
<MenuItemComponent
|
||||||
|
disabled={!canWrite}
|
||||||
|
onClick={() => handleAction(() => {
|
||||||
|
const today = getNow({ timezone: settings.system.timezone });
|
||||||
|
saveHabit({ ...habit, frequency: d2t({ dateTime: today }) });
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Calendar className="mr-2 h-4 w-4" />
|
||||||
|
<span>Move to Today</span>
|
||||||
|
</MenuItemComponent>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* "Move to Tomorrow" option: Show if task is due today OR not due today */}
|
||||||
|
{habit.isTask && !habit.archived && (
|
||||||
|
<MenuItemComponent
|
||||||
|
disabled={!canWrite}
|
||||||
|
onClick={() => handleAction(() => {
|
||||||
|
const tomorrow = getNow({ timezone: settings.system.timezone }).plus({ days: 1 });
|
||||||
|
saveHabit({ ...habit, frequency: d2t({ dateTime: tomorrow }) });
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Calendar className="mr-2 h-4 w-4" />
|
||||||
|
<span>Move to Tomorrow</span>
|
||||||
|
</MenuItemComponent>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!habit.archived && (
|
||||||
|
<MenuItemComponent
|
||||||
|
disabled={!canWrite}
|
||||||
|
onClick={() => handleAction(() => saveHabit({ ...habit, pinned: !habit.pinned }))}
|
||||||
|
>
|
||||||
|
<Pin className="mr-2 h-4 w-4" />
|
||||||
|
<span>{habit.pinned ? 'Unpin' : 'Pin'}</span>
|
||||||
|
</MenuItemComponent>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{context === 'habit-item' && !habit.archived && ( // Edit button visible in dropdown only for habit-item context on small screens
|
||||||
|
<MenuItemComponent
|
||||||
|
onClick={() => handleAction(onEditRequest)}
|
||||||
|
className="sm:hidden" // Kept the sm:hidden for HabitItem specific responsive behavior
|
||||||
|
disabled={!canWrite}
|
||||||
|
>
|
||||||
|
<Edit className="mr-2 h-4 w-4" />
|
||||||
|
<span>Edit</span>
|
||||||
|
</MenuItemComponent>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{context === 'daily-overview' && !habit.archived && ( // Edit button always visible in dropdown for daily-overview context
|
||||||
|
<MenuItemComponent
|
||||||
|
onClick={() => handleAction(onEditRequest)}
|
||||||
|
disabled={!canWrite}
|
||||||
|
>
|
||||||
|
<Edit className="mr-2 h-4 w-4" />
|
||||||
|
<span>Edit</span>
|
||||||
|
</MenuItemComponent>
|
||||||
|
)}
|
||||||
|
|
||||||
|
|
||||||
|
{!habit.archived && (
|
||||||
|
<MenuItemComponent
|
||||||
|
disabled={!canWrite}
|
||||||
|
onClick={() => handleAction(() => archiveHabit(habit.id))}
|
||||||
|
>
|
||||||
|
<Archive className="mr-2 h-4 w-4" />
|
||||||
|
<span>Archive</span>
|
||||||
|
</MenuItemComponent>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{habit.archived && (
|
||||||
|
<MenuItemComponent
|
||||||
|
disabled={!canWrite}
|
||||||
|
onClick={() => handleAction(() => unarchiveHabit(habit.id))}
|
||||||
|
>
|
||||||
|
<ArchiveRestore className="mr-2 h-4 w-4" />
|
||||||
|
<span>Unarchive</span>
|
||||||
|
</MenuItemComponent>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{context === 'habit-item' && !habit.archived && <MenuSeparatorComponent className="sm:hidden" />}
|
||||||
|
|
||||||
|
{(context === 'daily-overview' || habit.archived) && <MenuSeparatorComponent />}
|
||||||
|
|
||||||
|
|
||||||
|
<MenuItemComponent
|
||||||
|
onClick={() => handleAction(onDeleteRequest)}
|
||||||
|
className="text-red-600 focus:text-red-600 dark:text-red-400 dark:focus:text-red-400"
|
||||||
|
disabled={!canWrite} // Assuming delete is a write operation
|
||||||
|
>
|
||||||
|
<Trash2 className="mr-2 h-4 w-4" />
|
||||||
|
<span>Delete</span>
|
||||||
|
</MenuItemComponent>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,23 +1,20 @@
|
|||||||
import { Habit, SafeUser, User, Permission } from '@/lib/types'
|
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { settingsAtom, pomodoroAtom, browserSettingsAtom, usersAtom } from '@/lib/atoms'
|
|
||||||
import { getTodayInTimezone, isSameDate, t2d, d2t, getNow, d2s, getCompletionsForToday, isTaskOverdue, convertMachineReadableFrequencyToHumanReadable } from '@/lib/utils'
|
|
||||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Coins, Edit, Trash2, Check, Undo2, MoreVertical, Timer, Archive, ArchiveRestore, Calendar, Pin } from 'lucide-react'
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuItem,
|
DropdownMenuTrigger
|
||||||
DropdownMenuSeparator,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
} from '@/components/ui/dropdown-menu'
|
} from '@/components/ui/dropdown-menu'
|
||||||
import { useEffect, useState } from 'react'
|
|
||||||
import { useHabits } from '@/hooks/useHabits'
|
import { useHabits } from '@/hooks/useHabits'
|
||||||
import { INITIAL_RECURRENCE_RULE, RECURRENCE_RULE_MAP } from '@/lib/constants'
|
import { browserSettingsAtom, settingsAtom, usersAtom } from '@/lib/atoms'
|
||||||
import { DateTime } from 'luxon'
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar'
|
|
||||||
import { useHelpers } from '@/lib/client-helpers'
|
import { useHelpers } from '@/lib/client-helpers'
|
||||||
|
import { Habit, User } from '@/lib/types'
|
||||||
|
import { convertMachineReadableFrequencyToHumanReadable, getCompletionsForToday, isTaskOverdue } from '@/lib/utils'
|
||||||
|
import { useAtom } from 'jotai'
|
||||||
|
import { Check, Coins, Edit, MoreVertical, Pin, Undo2 } from 'lucide-react'; // Removed unused icons
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { HabitContextMenuItems } from './HabitContextMenuItems'
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar'
|
||||||
|
|
||||||
interface HabitItemProps {
|
interface HabitItemProps {
|
||||||
habit: Habit
|
habit: Habit
|
||||||
@@ -48,7 +45,6 @@ const renderUserAvatars = (habit: Habit, currentUser: User | null, usersData: {
|
|||||||
export default function HabitItem({ habit, onEdit, onDelete }: HabitItemProps) {
|
export default function HabitItem({ habit, onEdit, onDelete }: HabitItemProps) {
|
||||||
const { completeHabit, undoComplete, archiveHabit, unarchiveHabit, saveHabit } = useHabits()
|
const { completeHabit, undoComplete, archiveHabit, unarchiveHabit, saveHabit } = useHabits()
|
||||||
const [settings] = useAtom(settingsAtom)
|
const [settings] = useAtom(settingsAtom)
|
||||||
const [_, setPomo] = useAtom(pomodoroAtom)
|
|
||||||
const completionsToday = getCompletionsForToday({ habit, timezone: settings.system.timezone })
|
const completionsToday = getCompletionsForToday({ habit, timezone: settings.system.timezone })
|
||||||
const target = habit.targetCompletions || 1
|
const target = habit.targetCompletions || 1
|
||||||
const isCompletedToday = completionsToday >= target
|
const isCompletedToday = completionsToday >= target
|
||||||
@@ -194,70 +190,12 @@ export default function HabitItem({ habit, onEdit, onDelete }: HabitItemProps) {
|
|||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
{!habit.archived && (
|
<HabitContextMenuItems
|
||||||
<DropdownMenuItem onClick={() => {
|
habit={habit}
|
||||||
if (!canInteract) return
|
onEditRequest={onEdit}
|
||||||
setPomo((prev) => ({
|
onDeleteRequest={onDelete}
|
||||||
...prev,
|
context="habit-item"
|
||||||
show: true,
|
/>
|
||||||
selectedHabitId: habit.id
|
|
||||||
}))
|
|
||||||
}}>
|
|
||||||
<Timer className="mr-2 h-4 w-4" />
|
|
||||||
<span>Start Pomodoro</span>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
)}
|
|
||||||
{!habit.archived && (
|
|
||||||
<>
|
|
||||||
{habit.isTask && (
|
|
||||||
<DropdownMenuItem disabled={!canWrite} onClick={() => {
|
|
||||||
saveHabit({...habit, frequency: d2t({ dateTime: getNow({ timezone: settings.system.timezone })})})
|
|
||||||
}}>
|
|
||||||
<Calendar className="mr-2 h-4 w-4" />
|
|
||||||
<span>Move to Today</span>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
)}
|
|
||||||
<DropdownMenuItem disabled={!canWrite} onClick={() => saveHabit({...habit, pinned: !habit.pinned})}>
|
|
||||||
{habit.pinned ? (
|
|
||||||
<>
|
|
||||||
<Archive className="mr-2 h-4 w-4" />
|
|
||||||
<span>Unpin</span>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Archive className="mr-2 h-4 w-4" />
|
|
||||||
<span>Pin</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem disabled={!canWrite} onClick={() => archiveHabit(habit.id)}>
|
|
||||||
<Archive className="mr-2 h-4 w-4" />
|
|
||||||
<span>Archive</span>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{habit.archived && (
|
|
||||||
<DropdownMenuItem disabled={!canWrite} onClick={() => unarchiveHabit(habit.id)}>
|
|
||||||
<ArchiveRestore className="mr-2 h-4 w-4" />
|
|
||||||
<span>Unarchive</span>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
)}
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={onEdit}
|
|
||||||
className="sm:hidden"
|
|
||||||
disabled={habit.archived}
|
|
||||||
>
|
|
||||||
<Edit className="mr-2 h-4 w-4" />
|
|
||||||
Edit
|
|
||||||
</DropdownMenuItem>
|
|
||||||
<DropdownMenuSeparator className="sm:hidden" />
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="text-red-600 focus:text-red-600 dark:text-red-400 dark:focus:text-red-400 cursor-pointer"
|
|
||||||
onClick={onDelete}
|
|
||||||
>
|
|
||||||
<Trash2 className="mr-2 h-4 w-4" />
|
|
||||||
Delete
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,32 +1,112 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
|
||||||
import { Plus, ListTodo } from 'lucide-react'
|
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { habitsAtom, settingsAtom, browserSettingsAtom } from '@/lib/atoms'
|
|
||||||
import EmptyState from './EmptyState'
|
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import HabitItem from './HabitItem'
|
import { Input } from '@/components/ui/input'; // Added
|
||||||
|
import { Label } from '@/components/ui/label'; // Added
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; // Added
|
||||||
|
import { useHabits } from '@/hooks/useHabits'
|
||||||
|
import { browserSettingsAtom, habitsAtom } from '@/lib/atoms'
|
||||||
|
import { HabitIcon, TaskIcon } from '@/lib/constants'
|
||||||
|
import { Habit } from '@/lib/types'
|
||||||
|
import { getHabitFreq } from '@/lib/utils'; // Added
|
||||||
|
import { useAtom } from 'jotai'
|
||||||
|
import { ArrowDownWideNarrow, ArrowUpNarrowWide, Plus, Search } from 'lucide-react'; // Added sort icons, Search icon
|
||||||
|
import { DateTime } from 'luxon'; // Added
|
||||||
|
import { useEffect, useMemo, useState } from 'react'; // Added useMemo, useEffect
|
||||||
import AddEditHabitModal from './AddEditHabitModal'
|
import AddEditHabitModal from './AddEditHabitModal'
|
||||||
import ConfirmDialog from './ConfirmDialog'
|
import ConfirmDialog from './ConfirmDialog'
|
||||||
import { Habit } from '@/lib/types'
|
import EmptyState from './EmptyState'
|
||||||
import { useHabits } from '@/hooks/useHabits'
|
import HabitItem from './HabitItem'
|
||||||
import { HabitIcon, TaskIcon } from '@/lib/constants'
|
|
||||||
import { ViewToggle } from './ViewToggle'
|
import { ViewToggle } from './ViewToggle'
|
||||||
|
|
||||||
export default function HabitList() {
|
export default function HabitList() {
|
||||||
const { saveHabit, deleteHabit } = useHabits()
|
const { saveHabit, deleteHabit } = useHabits()
|
||||||
const [habitsData, setHabitsData] = useAtom(habitsAtom)
|
const [habitsData] = useAtom(habitsAtom) // setHabitsData removed as it's not used
|
||||||
const [browserSettings] = useAtom(browserSettingsAtom)
|
const [browserSettings] = useAtom(browserSettingsAtom)
|
||||||
const isTasksView = browserSettings.viewType === 'tasks'
|
const isTasksView = browserSettings.viewType === 'tasks'
|
||||||
const habits = habitsData.habits.filter(habit =>
|
// const [settings] = useAtom(settingsAtom); // settingsAtom is not directly used in HabitList itself.
|
||||||
isTasksView ? habit.isTask : !habit.isTask
|
|
||||||
)
|
type SortableField = 'name' | 'coinReward' | 'dueDate' | 'frequency';
|
||||||
const activeHabits = habits
|
type SortOrder = 'asc' | 'desc';
|
||||||
.filter(h => !h.archived)
|
|
||||||
.sort((a, b) => (b.pinned ? 1 : 0) - (a.pinned ? 1 : 0))
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
const archivedHabits = habits.filter(h => h.archived)
|
const [sortBy, setSortBy] = useState<SortableField>('name');
|
||||||
const [settings] = useAtom(settingsAtom)
|
const [sortOrder, setSortOrder] = useState<SortOrder>('asc');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isTasksView && sortBy === 'frequency') {
|
||||||
|
setSortBy('name');
|
||||||
|
} else if (!isTasksView && sortBy === 'dueDate') {
|
||||||
|
setSortBy('name');
|
||||||
|
}
|
||||||
|
}, [isTasksView, sortBy]);
|
||||||
|
|
||||||
|
const compareHabits = useMemo(() => {
|
||||||
|
return (a: Habit, b: Habit, currentSortBy: SortableField, currentSortOrder: SortOrder, tasksView: boolean): number => {
|
||||||
|
let comparison = 0;
|
||||||
|
switch (currentSortBy) {
|
||||||
|
case 'name':
|
||||||
|
comparison = a.name.localeCompare(b.name);
|
||||||
|
break;
|
||||||
|
case 'coinReward':
|
||||||
|
comparison = a.coinReward - b.coinReward;
|
||||||
|
break;
|
||||||
|
case 'dueDate':
|
||||||
|
if (tasksView && a.isTask && b.isTask) {
|
||||||
|
const dateA = DateTime.fromISO(a.frequency);
|
||||||
|
const dateB = DateTime.fromISO(b.frequency);
|
||||||
|
if (dateA.isValid && dateB.isValid) comparison = dateA.toMillis() - dateB.toMillis();
|
||||||
|
else if (dateA.isValid) comparison = -1; // Valid dates first
|
||||||
|
else if (dateB.isValid) comparison = 1;
|
||||||
|
// If both invalid, comparison remains 0
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'frequency':
|
||||||
|
if (!tasksView && !a.isTask && !b.isTask) {
|
||||||
|
const freqOrder = ['daily', 'weekly', 'monthly', 'yearly'];
|
||||||
|
const freqAVal = getHabitFreq(a);
|
||||||
|
const freqBVal = getHabitFreq(b);
|
||||||
|
comparison = freqOrder.indexOf(freqAVal) - freqOrder.indexOf(freqBVal);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return currentSortOrder === 'asc' ? comparison : -comparison;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const allHabitsInView = useMemo(() => {
|
||||||
|
return habitsData.habits.filter(habit =>
|
||||||
|
isTasksView ? habit.isTask : !habit.isTask
|
||||||
|
);
|
||||||
|
}, [habitsData.habits, isTasksView]);
|
||||||
|
|
||||||
|
const searchedHabits = useMemo(() => {
|
||||||
|
if (!searchTerm.trim()) {
|
||||||
|
return allHabitsInView;
|
||||||
|
}
|
||||||
|
const lowercasedSearchTerm = searchTerm.toLowerCase();
|
||||||
|
return allHabitsInView.filter(habit =>
|
||||||
|
habit.name.toLowerCase().includes(lowercasedSearchTerm) ||
|
||||||
|
(habit.description && habit.description.toLowerCase().includes(lowercasedSearchTerm))
|
||||||
|
);
|
||||||
|
}, [allHabitsInView, searchTerm]);
|
||||||
|
|
||||||
|
const activeHabits = useMemo(() => {
|
||||||
|
return searchedHabits
|
||||||
|
.filter(h => !h.archived)
|
||||||
|
.sort((a, b) => {
|
||||||
|
if (a.pinned && !b.pinned) return -1;
|
||||||
|
if (!a.pinned && b.pinned) return 1;
|
||||||
|
// For items in the same pinned group (both pinned or both not pinned), apply general sort
|
||||||
|
return compareHabits(a, b, sortBy, sortOrder, isTasksView);
|
||||||
|
});
|
||||||
|
}, [searchedHabits, sortBy, sortOrder, isTasksView, compareHabits]);
|
||||||
|
|
||||||
|
const archivedHabits = useMemo(() => {
|
||||||
|
return searchedHabits
|
||||||
|
.filter(h => h.archived)
|
||||||
|
.sort((a, b) => compareHabits(a, b, sortBy, sortOrder, isTasksView));
|
||||||
|
}, [searchedHabits, sortBy, sortOrder, isTasksView, compareHabits]);
|
||||||
const [modalConfig, setModalConfig] = useState<{
|
const [modalConfig, setModalConfig] = useState<{
|
||||||
isOpen: boolean,
|
isOpen: boolean,
|
||||||
isTask: boolean
|
isTask: boolean
|
||||||
@@ -59,8 +139,47 @@ export default function HabitList() {
|
|||||||
<div className='py-4'>
|
<div className='py-4'>
|
||||||
<ViewToggle />
|
<ViewToggle />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Search and Sort Controls */}
|
||||||
|
<div className="flex flex-col sm:flex-row items-center gap-4 my-4">
|
||||||
|
<div className="relative flex-grow w-full sm:w-auto">
|
||||||
|
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||||
|
<Search className="h-5 w-5 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<Input
|
||||||
|
type="search"
|
||||||
|
placeholder={`Search ${isTasksView ? 'tasks' : 'habits'}...`}
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={(e) => setSearchTerm(e.target.value)}
|
||||||
|
className="pl-10 w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 self-start sm:self-center w-full sm:w-auto">
|
||||||
|
<Label htmlFor="sort-by" className="text-sm font-medium whitespace-nowrap sr-only sm:not-sr-only">Sort by:</Label>
|
||||||
|
<Select value={sortBy} onValueChange={(value) => setSortBy(value as SortableField)}>
|
||||||
|
<SelectTrigger id="sort-by" className="w-full sm:w-[180px]">
|
||||||
|
<SelectValue placeholder="Sort by" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="name">Name</SelectItem>
|
||||||
|
<SelectItem value="coinReward">Coin Reward</SelectItem>
|
||||||
|
{isTasksView && <SelectItem value="dueDate">Due Date</SelectItem>}
|
||||||
|
{!isTasksView && <SelectItem value="frequency">Frequency</SelectItem>}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<Button variant="outline" size="icon" onClick={() => setSortOrder(prev => prev === 'asc' ? 'desc' : 'asc')}>
|
||||||
|
{sortOrder === 'asc' ? <ArrowUpNarrowWide className="h-4 w-4" /> : <ArrowDownWideNarrow className="h-4 w-4" />}
|
||||||
|
<span className="sr-only">Toggle sort order</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 items-stretch">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 items-stretch">
|
||||||
{activeHabits.length === 0 ? (
|
{activeHabits.length === 0 && searchTerm.trim() ? (
|
||||||
|
<div className="col-span-2 text-center text-muted-foreground py-8">
|
||||||
|
No {isTasksView ? 'tasks' : 'habits'} found matching your search.
|
||||||
|
</div>
|
||||||
|
) : activeHabits.length === 0 ? (
|
||||||
<div className="col-span-2">
|
<div className="col-span-2">
|
||||||
<EmptyState
|
<EmptyState
|
||||||
icon={isTasksView ? TaskIcon : HabitIcon}
|
icon={isTasksView ? TaskIcon : HabitIcon}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { Habit } from '@/lib/types'
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
import { d2s, getNow, t2d, getCompletedHabitsForDate } from '@/lib/utils'
|
import { completedHabitsMapAtom, hasTasksAtom, settingsAtom } from '@/lib/atoms'; // Added completedHabitsMapAtom
|
||||||
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts'
|
import { Habit } from '@/lib/types'
|
||||||
|
import { d2s, getNow } from '@/lib/utils'; // Removed getCompletedHabitsForDate
|
||||||
import { useAtom } from 'jotai'
|
import { useAtom } from 'jotai'
|
||||||
import { settingsAtom, hasTasksAtom } from '@/lib/atoms'
|
import { CartesianGrid, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'
|
||||||
|
|
||||||
interface HabitStreakProps {
|
interface HabitStreakProps {
|
||||||
habits: Habit[]
|
habits: Habit[]
|
||||||
@@ -14,6 +14,8 @@ interface HabitStreakProps {
|
|||||||
export default function HabitStreak({ habits }: HabitStreakProps) {
|
export default function HabitStreak({ habits }: HabitStreakProps) {
|
||||||
const [settings] = useAtom(settingsAtom)
|
const [settings] = useAtom(settingsAtom)
|
||||||
const [hasTasks] = useAtom(hasTasksAtom)
|
const [hasTasks] = useAtom(hasTasksAtom)
|
||||||
|
const [completedHabitsMap] = useAtom(completedHabitsMapAtom) // Use the atom
|
||||||
|
|
||||||
// Get the last 7 days of data
|
// Get the last 7 days of data
|
||||||
const dates = Array.from({ length: 7 }, (_, i) => {
|
const dates = Array.from({ length: 7 }, (_, i) => {
|
||||||
const d = getNow({ timezone: settings.system.timezone });
|
const d = getNow({ timezone: settings.system.timezone });
|
||||||
@@ -21,20 +23,17 @@ export default function HabitStreak({ habits }: HabitStreakProps) {
|
|||||||
}).reverse()
|
}).reverse()
|
||||||
|
|
||||||
const completions = dates.map(date => {
|
const completions = dates.map(date => {
|
||||||
const completedHabits = getCompletedHabitsForDate({
|
// Get completed habits for the date from the map
|
||||||
habits: habits.filter(h => !h.isTask),
|
const completedOnDate = completedHabitsMap.get(date) || [];
|
||||||
date: t2d({ timestamp: date, timezone: settings.system.timezone }),
|
|
||||||
timezone: settings.system.timezone
|
// Filter the completed list to count habits and tasks
|
||||||
});
|
const completedHabitsCount = completedOnDate.filter(h => !h.isTask).length;
|
||||||
const completedTasks = getCompletedHabitsForDate({
|
const completedTasksCount = completedOnDate.filter(h => h.isTask).length;
|
||||||
habits: habits.filter(h => h.isTask),
|
|
||||||
date: t2d({ timestamp: date, timezone: settings.system.timezone }),
|
|
||||||
timezone: settings.system.timezone
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
date,
|
date,
|
||||||
habits: completedHabits.length,
|
habits: completedHabitsCount,
|
||||||
tasks: completedTasks.length
|
tasks: completedTasksCount
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,15 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { coinsAtom, settingsAtom, browserSettingsAtom } from '@/lib/atoms'
|
|
||||||
import { useCoins } from '@/hooks/useCoins'
|
|
||||||
import { FormattedNumber } from '@/components/FormattedNumber'
|
import { FormattedNumber } from '@/components/FormattedNumber'
|
||||||
import { Menu, Settings, User, Info, Coins } from 'lucide-react'
|
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import { Logo } from '@/components/Logo'
|
import { Logo } from '@/components/Logo'
|
||||||
import NotificationBell from './NotificationBell'
|
import { useCoins } from '@/hooks/useCoins'
|
||||||
import {
|
import { settingsAtom } from '@/lib/atoms'
|
||||||
DropdownMenu,
|
import { useAtom } from 'jotai'
|
||||||
DropdownMenuContent,
|
import { Coins } from 'lucide-react'
|
||||||
DropdownMenuItem,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
} from '@/components/ui/dropdown-menu'
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
|
|
||||||
import AboutModal from './AboutModal'
|
|
||||||
import Link from 'next/link'
|
|
||||||
import dynamic from 'next/dynamic'
|
import dynamic from 'next/dynamic'
|
||||||
|
import Link from 'next/link'
|
||||||
|
import NotificationBell from './NotificationBell'
|
||||||
import { Profile } from './Profile'
|
import { Profile } from './Profile'
|
||||||
import { useHelpers } from '@/lib/client-helpers'
|
|
||||||
|
|
||||||
interface HeaderProps {
|
interface HeaderProps {
|
||||||
className?: string
|
className?: string
|
||||||
@@ -30,7 +19,6 @@ const TodayEarnedCoins = dynamic(() => import('./TodayEarnedCoins'), { ssr: fals
|
|||||||
|
|
||||||
export default function Header({ className }: HeaderProps) {
|
export default function Header({ className }: HeaderProps) {
|
||||||
const [settings] = useAtom(settingsAtom)
|
const [settings] = useAtom(settingsAtom)
|
||||||
const [browserSettings] = useAtom(browserSettingsAtom)
|
|
||||||
const { balance } = useCoins()
|
const { balance } = useCoins()
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { Sparkles } from "lucide-react"
|
|
||||||
|
|
||||||
export function Logo() {
|
export function Logo() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import Link from 'next/link'
|
|
||||||
import { Home, Calendar, List, Gift, Coins, Settings, Info, CheckSquare } from 'lucide-react'
|
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { browserSettingsAtom } from '@/lib/atoms'
|
import { browserSettingsAtom } from '@/lib/atoms'
|
||||||
|
import { useHelpers } from '@/lib/client-helpers'
|
||||||
|
import { HabitIcon, TaskIcon } from '@/lib/constants'
|
||||||
|
import { useAtom } from 'jotai'
|
||||||
|
import { Calendar, Coins, Gift, Home } from 'lucide-react'
|
||||||
|
import Link from 'next/link'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import AboutModal from './AboutModal'
|
import AboutModal from './AboutModal'
|
||||||
import { HabitIcon, TaskIcon } from '@/lib/constants'
|
|
||||||
import { useHelpers } from '@/lib/client-helpers'
|
|
||||||
|
|
||||||
type ViewPort = 'main' | 'mobile'
|
type ViewPort = 'main' | 'mobile'
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
import React from 'react';
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||||
|
import { DropdownMenuItem } from '@/components/ui/dropdown-menu';
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
|
||||||
import { CoinsData, HabitsData, WishlistData, UserData, User, CoinTransaction } from '@/lib/types';
|
|
||||||
import { t2d } from '@/lib/utils';
|
|
||||||
import Link from 'next/link';
|
|
||||||
import { DropdownMenuItem } from '@/components/ui/dropdown-menu';
|
|
||||||
import { Info } from 'lucide-react';
|
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
TooltipContent,
|
TooltipContent,
|
||||||
TooltipProvider,
|
TooltipProvider,
|
||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from '@/components/ui/tooltip';
|
} from '@/components/ui/tooltip';
|
||||||
|
import { CoinTransaction, HabitsData, User, UserData, WishlistData } from '@/lib/types';
|
||||||
|
import { t2d } from '@/lib/utils';
|
||||||
|
import { Info } from 'lucide-react';
|
||||||
|
import Link from 'next/link';
|
||||||
|
|
||||||
interface NotificationDropdownProps {
|
interface NotificationDropdownProps {
|
||||||
currentUser: User | null;
|
currentUser: User | null;
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar';
|
|
||||||
import { Input } from './ui/input';
|
|
||||||
import { Button } from './ui/button';
|
|
||||||
import { Label } from './ui/label';
|
|
||||||
import { User as UserIcon } from 'lucide-react';
|
|
||||||
import { Permission, User } from '@/lib/types';
|
|
||||||
import { toast } from '@/hooks/use-toast';
|
import { toast } from '@/hooks/use-toast';
|
||||||
|
import { User } from '@/lib/types';
|
||||||
|
import { User as UserIcon } from 'lucide-react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { Input } from './ui/input';
|
||||||
|
import { Label } from './ui/label';
|
||||||
|
|
||||||
interface PasswordEntryFormProps {
|
interface PasswordEntryFormProps {
|
||||||
user: User;
|
user: User;
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState, useEffect, useRef, useCallback } from 'react'
|
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Progress } from '@/components/ui/progress'
|
import { Progress } from '@/components/ui/progress'
|
||||||
import { Play, Pause, RotateCw, Minus, X, Clock, SkipForward } from 'lucide-react'
|
|
||||||
import { cn, getCompletionsForToday } from '@/lib/utils'
|
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { settingsAtom, pomodoroAtom, habitsAtom, pomodoroTodayCompletionsAtom } from '@/lib/atoms'
|
|
||||||
import { getCompletionsForDate, getTodayInTimezone } from '@/lib/utils'
|
|
||||||
import { useHabits } from '@/hooks/useHabits'
|
import { useHabits } from '@/hooks/useHabits'
|
||||||
|
import { habitsAtom, pomodoroAtom, pomodoroTodayCompletionsAtom, settingsAtom } from '@/lib/atoms'
|
||||||
|
import { cn } from '@/lib/utils'
|
||||||
|
import { useAtom } from 'jotai'
|
||||||
|
import { Clock, Minus, Pause, Play, RotateCw, SkipForward, X } from 'lucide-react'
|
||||||
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
|
||||||
interface PomoConfig {
|
interface PomoConfig {
|
||||||
labels: string[]
|
labels: string[]
|
||||||
@@ -135,7 +134,19 @@ export default function PomodoroTimer() {
|
|||||||
const remaining = Math.floor((targetEndTime - Date.now()) / 1000)
|
const remaining = Math.floor((targetEndTime - Date.now()) / 1000)
|
||||||
|
|
||||||
if (remaining <= 0) {
|
if (remaining <= 0) {
|
||||||
handleTimerEnd()
|
setState("stopped")
|
||||||
|
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)]
|
||||||
|
)
|
||||||
|
|
||||||
|
// update habits only after focus sessions
|
||||||
|
if (selectedHabit && currentTimerType === 'focus') {
|
||||||
|
completeHabit(selectedHabit)
|
||||||
|
// The atom will automatically update with the new completions
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setTimeLeft(remaining)
|
setTimeLeft(remaining)
|
||||||
}
|
}
|
||||||
@@ -146,23 +157,7 @@ export default function PomodoroTimer() {
|
|||||||
return () => {
|
return () => {
|
||||||
if (interval) clearInterval(interval)
|
if (interval) clearInterval(interval)
|
||||||
}
|
}
|
||||||
}, [state])
|
}, [state, timeLeft, completeHabit, selectedHabit])
|
||||||
|
|
||||||
const handleTimerEnd = async () => {
|
|
||||||
setState("stopped")
|
|
||||||
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)]
|
|
||||||
)
|
|
||||||
|
|
||||||
// update habits only after focus sessions
|
|
||||||
if (selectedHabit && currentTimerType === 'focus') {
|
|
||||||
await completeHabit(selectedHabit)
|
|
||||||
// The atom will automatically update with the new completions
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const toggleTimer = () => {
|
const toggleTimer = () => {
|
||||||
setState(prev => prev === 'started' ? 'paused' : 'started')
|
setState(prev => prev === 'started' ? 'paused' : 'started')
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
|
import { signOut } from "@/app/actions/user"
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||||
import { Settings, Info, User, Moon, Sun, Palette, ArrowRightLeft, LogOut, Crown } from "lucide-react"
|
import { toast } from "@/hooks/use-toast"
|
||||||
|
import { settingsAtom, userSelectAtom } from "@/lib/atoms"
|
||||||
|
import { useHelpers } from "@/lib/client-helpers"
|
||||||
|
import { useAtom } from "jotai"
|
||||||
|
import { ArrowRightLeft, Crown, Info, LogOut, Moon, Palette, Settings, Sun, User } from "lucide-react"
|
||||||
|
import { useTheme } from "next-themes"
|
||||||
|
import Link from "next/link"
|
||||||
|
import { useState } from "react"
|
||||||
|
import AboutModal from "./AboutModal"
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from './ui/dialog'
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from './ui/dialog'
|
||||||
import UserForm from './UserForm'
|
import UserForm from './UserForm'
|
||||||
import Link from "next/link"
|
|
||||||
import { useAtom } from "jotai"
|
|
||||||
import { settingsAtom, userSelectAtom } from "@/lib/atoms"
|
|
||||||
import AboutModal from "./AboutModal"
|
|
||||||
import { useEffect, useState } from "react"
|
|
||||||
import { useTheme } from "next-themes"
|
|
||||||
import { signOut } from "@/app/actions/user"
|
|
||||||
import { toast } from "@/hooks/use-toast"
|
|
||||||
import { useHelpers } from "@/lib/client-helpers"
|
|
||||||
|
|
||||||
export function Profile() {
|
export function Profile() {
|
||||||
const [settings] = useAtom(settingsAtom)
|
const [settings] = useAtom(settingsAtom)
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { createUser, updateUser, updateUserPassword, uploadAvatar } from '@/app/actions/data';
|
||||||
|
import { toast } from '@/hooks/use-toast';
|
||||||
|
import { serverSettingsAtom, usersAtom } from '@/lib/atoms';
|
||||||
|
import { useHelpers } from '@/lib/client-helpers';
|
||||||
|
import { Permission } from '@/lib/types';
|
||||||
import { passwordSchema, usernameSchema } from '@/lib/zod';
|
import { passwordSchema, usernameSchema } from '@/lib/zod';
|
||||||
import { Input } from './ui/input';
|
import { useAtom, useAtomValue } from 'jotai';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import { User as UserIcon } from 'lucide-react';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { PermissionSelector } from './PermissionSelector';
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar';
|
||||||
import { Button } from './ui/button';
|
import { Button } from './ui/button';
|
||||||
|
import { Input } from './ui/input';
|
||||||
import { Label } from './ui/label';
|
import { Label } from './ui/label';
|
||||||
import { Switch } from './ui/switch';
|
import { Switch } from './ui/switch';
|
||||||
import { Permission } from '@/lib/types';
|
|
||||||
import { toast } from '@/hooks/use-toast';
|
|
||||||
import { useAtom, useAtomValue } from 'jotai';
|
|
||||||
import { serverSettingsAtom, usersAtom } from '@/lib/atoms';
|
|
||||||
import { createUser, updateUser, updateUserPassword, uploadAvatar } from '@/app/actions/data';
|
|
||||||
import { SafeUser, User } from '@/lib/types';
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar';
|
|
||||||
import { User as UserIcon } from 'lucide-react';
|
|
||||||
import _ from 'lodash';
|
|
||||||
import { PermissionSelector } from './PermissionSelector';
|
|
||||||
import { useHelpers } from '@/lib/client-helpers';
|
|
||||||
|
|
||||||
interface UserFormProps {
|
interface UserFormProps {
|
||||||
userId?: string; // if provided, we're editing; if not, we're creating
|
userId?: string; // if provided, we're editing; if not, we're creating
|
||||||
|
|||||||
@@ -1,22 +1,19 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { signIn } from '@/app/actions/user';
|
||||||
|
import { toast } from '@/hooks/use-toast';
|
||||||
|
import { usersAtom } from '@/lib/atoms';
|
||||||
|
import { useHelpers } from '@/lib/client-helpers';
|
||||||
|
import { SafeUser, User } from '@/lib/types';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import { Description } from '@radix-ui/react-dialog';
|
||||||
|
import { useAtom } from 'jotai';
|
||||||
|
import { Crown, Plus, User as UserIcon, UserRoundPen } from 'lucide-react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import PasswordEntryForm from './PasswordEntryForm';
|
import PasswordEntryForm from './PasswordEntryForm';
|
||||||
import UserForm from './UserForm';
|
import UserForm from './UserForm';
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from './ui/dialog';
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar';
|
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar';
|
||||||
import { Crown, Pencil, Plus, User as UserIcon, UserRoundPen } from 'lucide-react';
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from './ui/dialog';
|
||||||
import { Input } from './ui/input';
|
|
||||||
import { Button } from './ui/button';
|
|
||||||
import { useAtom } from 'jotai';
|
|
||||||
import { usersAtom } from '@/lib/atoms';
|
|
||||||
import { signIn } from '@/app/actions/user';
|
|
||||||
import { createUser } from '@/app/actions/data';
|
|
||||||
import { toast } from '@/hooks/use-toast';
|
|
||||||
import { Description } from '@radix-ui/react-dialog';
|
|
||||||
import { SafeUser, User } from '@/lib/types';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import { useHelpers } from '@/lib/client-helpers';
|
|
||||||
|
|
||||||
function UserCard({
|
function UserCard({
|
||||||
user,
|
user,
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { cn } from '@/lib/utils'
|
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { CheckSquare, ListChecks } from 'lucide-react'
|
|
||||||
import { browserSettingsAtom, habitsAtom, settingsAtom } from '@/lib/atoms'
|
import { browserSettingsAtom, habitsAtom, settingsAtom } from '@/lib/atoms'
|
||||||
import type { ViewType } from '@/lib/types'
|
|
||||||
import { HabitIcon, TaskIcon } from '@/lib/constants'
|
import { HabitIcon, TaskIcon } from '@/lib/constants'
|
||||||
import { isHabitDueToday } from '@/lib/utils'
|
import type { ViewType } from '@/lib/types'
|
||||||
|
import { cn, isHabitDueToday } from '@/lib/utils'
|
||||||
|
import { useAtom } from 'jotai'
|
||||||
import { NotificationBadge } from './ui/notification-badge'
|
import { NotificationBadge } from './ui/notification-badge'
|
||||||
|
|
||||||
interface ViewToggleProps {
|
interface ViewToggleProps {
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
import { WishlistItemType, User, Permission } from '@/lib/types'
|
|
||||||
import { useAtom } from 'jotai'
|
|
||||||
import { usersAtom } from '@/lib/atoms'
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar'
|
|
||||||
import { useHelpers } from '@/lib/client-helpers'
|
|
||||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
|
||||||
import ReactMarkdown from 'react-markdown'
|
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Coins, Edit, Trash2, Gift, MoreVertical, Archive, ArchiveRestore } from 'lucide-react'
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
@@ -14,6 +7,12 @@ import {
|
|||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from '@/components/ui/dropdown-menu'
|
} from '@/components/ui/dropdown-menu'
|
||||||
|
import { usersAtom } from '@/lib/atoms'
|
||||||
|
import { useHelpers } from '@/lib/client-helpers'
|
||||||
|
import { User, WishlistItemType } from '@/lib/types'
|
||||||
|
import { useAtom } from 'jotai'
|
||||||
|
import { Archive, ArchiveRestore, Coins, Edit, Gift, MoreVertical, Trash2 } from 'lucide-react'
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar'
|
||||||
|
|
||||||
interface WishlistItemProps {
|
interface WishlistItemProps {
|
||||||
item: WishlistItemType
|
item: WishlistItemType
|
||||||
|
|||||||
@@ -88,9 +88,9 @@ export default function WishlistManager() {
|
|||||||
<Plus className="mr-2 h-4 w-4" /> Add Reward
|
<Plus className="mr-2 h-4 w-4" /> Add Reward
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 items-stretch">
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4 items-stretch">
|
||||||
{activeItems.length === 0 ? (
|
{activeItems.length === 0 ? (
|
||||||
<div className="col-span-2">
|
<div className="col-span-1 lg:col-span-2">
|
||||||
<EmptyState
|
<EmptyState
|
||||||
icon={Gift}
|
icon={Gift}
|
||||||
title="Your wishlist is empty"
|
title="Your wishlist is empty"
|
||||||
@@ -127,7 +127,7 @@ export default function WishlistManager() {
|
|||||||
|
|
||||||
{archivedItems.length > 0 && (
|
{archivedItems.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<div className="col-span-2 relative flex items-center my-6">
|
<div className="col-span-1 lg:col-span-2 relative flex items-center my-6">
|
||||||
<div className="flex-grow border-t border-gray-300 dark:border-gray-600" />
|
<div className="flex-grow border-t border-gray-300 dark:border-gray-600" />
|
||||||
<span className="mx-4 text-sm text-gray-500 dark:text-gray-400">Archived</span>
|
<span className="mx-4 text-sm text-gray-500 dark:text-gray-400">Archived</span>
|
||||||
<div className="flex-grow border-t border-gray-300 dark:border-gray-600" />
|
<div className="flex-grow border-t border-gray-300 dark:border-gray-600" />
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
import { Moon, Sun } from "lucide-react"
|
||||||
import { Moon, MoonIcon, Sun } from "lucide-react"
|
|
||||||
import { useTheme } from "next-themes"
|
import { useTheme } from "next-themes"
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ import { useAtom } from 'jotai'
|
|||||||
import { calculateCoinsEarnedToday, calculateCoinsSpentToday, calculateTotalEarned, calculateTotalSpent, calculateTransactionsToday, checkPermission } from '@/lib/utils'
|
import { calculateCoinsEarnedToday, calculateCoinsSpentToday, calculateTotalEarned, calculateTotalSpent, calculateTransactionsToday, checkPermission } from '@/lib/utils'
|
||||||
import {
|
import {
|
||||||
coinsAtom,
|
coinsAtom,
|
||||||
// coinsEarnedTodayAtom,
|
coinsEarnedTodayAtom,
|
||||||
// totalEarnedAtom,
|
totalEarnedAtom,
|
||||||
// totalSpentAtom,
|
totalSpentAtom,
|
||||||
// coinsSpentTodayAtom,
|
coinsSpentTodayAtom,
|
||||||
// transactionsTodayAtom,
|
transactionsTodayAtom,
|
||||||
// coinsBalanceAtom,
|
coinsBalanceAtom,
|
||||||
settingsAtom,
|
settingsAtom,
|
||||||
usersAtom
|
usersAtom,
|
||||||
} from '@/lib/atoms'
|
} from '@/lib/atoms'
|
||||||
import { addCoins, removeCoins, saveCoinsData } from '@/app/actions/data'
|
import { addCoins, removeCoins, saveCoinsData } from '@/app/actions/data'
|
||||||
import { CoinsData, User } from '@/lib/types'
|
import { CoinsData, User } from '@/lib/types'
|
||||||
@@ -29,7 +29,7 @@ function handlePermissionCheck(
|
|||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user.isAdmin && !checkPermission(user.permissions, resource, action)) {
|
if (!user.isAdmin && !checkPermission(user.permissions, resource, action)) {
|
||||||
toast({
|
toast({
|
||||||
title: "Permission Denied",
|
title: "Permission Denied",
|
||||||
@@ -38,7 +38,7 @@ function handlePermissionCheck(
|
|||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,12 +57,12 @@ export function useCoins(options?: { selectedUser?: string }) {
|
|||||||
// Filter transactions for the selectd user
|
// Filter transactions for the selectd user
|
||||||
const transactions = coins.transactions.filter(t => t.userId === user?.id)
|
const transactions = coins.transactions.filter(t => t.userId === user?.id)
|
||||||
|
|
||||||
const balance = transactions.reduce((sum, t) => sum + t.amount, 0)
|
const [balance] = useAtom(coinsBalanceAtom)
|
||||||
const coinsEarnedToday = calculateCoinsEarnedToday(transactions, settings.system.timezone)
|
const [coinsEarnedToday] = useAtom(coinsEarnedTodayAtom)
|
||||||
const totalEarned = calculateTotalEarned(transactions)
|
const [totalEarned] = useAtom(totalEarnedAtom)
|
||||||
const totalSpent = calculateTotalSpent(transactions)
|
const [totalSpent] = useAtom(totalSpentAtom)
|
||||||
const coinsSpentToday = calculateCoinsSpentToday(transactions, settings.system.timezone)
|
const [coinsSpentToday] = useAtom(coinsSpentTodayAtom)
|
||||||
const transactionsToday = calculateTransactionsToday(transactions, settings.system.timezone)
|
const [transactionsToday] = useAtom(transactionsTodayAtom)
|
||||||
|
|
||||||
const add = async (amount: number, description: string, note?: string) => {
|
const add = async (amount: number, description: string, note?: string) => {
|
||||||
if (!handlePermissionCheck(currentUser, 'coins', 'write')) return null
|
if (!handlePermissionCheck(currentUser, 'coins', 'write')) return null
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useAtom } from 'jotai'
|
import { useAtom, atom } from 'jotai'
|
||||||
import { habitsAtom, coinsAtom, settingsAtom, usersAtom } from '@/lib/atoms'
|
import { habitsAtom, coinsAtom, settingsAtom, usersAtom, habitFreqMapAtom } from '@/lib/atoms'
|
||||||
import { addCoins, removeCoins, saveHabitsData } from '@/app/actions/data'
|
import { addCoins, removeCoins, saveHabitsData } from '@/app/actions/data'
|
||||||
import { Habit, Permission, SafeUser, User } from '@/lib/types'
|
import { Habit, Permission, SafeUser, User } from '@/lib/types'
|
||||||
import { toast } from '@/hooks/use-toast'
|
import { toast } from '@/hooks/use-toast'
|
||||||
@@ -34,7 +34,7 @@ function handlePermissionCheck(
|
|||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user.isAdmin && !checkPermission(user.permissions, resource, action)) {
|
if (!user.isAdmin && !checkPermission(user.permissions, resource, action)) {
|
||||||
toast({
|
toast({
|
||||||
title: "Permission Denied",
|
title: "Permission Denied",
|
||||||
@@ -43,7 +43,7 @@ function handlePermissionCheck(
|
|||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +54,7 @@ export function useHabits() {
|
|||||||
const [habitsData, setHabitsData] = useAtom(habitsAtom)
|
const [habitsData, setHabitsData] = useAtom(habitsAtom)
|
||||||
const [coins, setCoins] = useAtom(coinsAtom)
|
const [coins, setCoins] = useAtom(coinsAtom)
|
||||||
const [settings] = useAtom(settingsAtom)
|
const [settings] = useAtom(settingsAtom)
|
||||||
|
const [habitFreqMap] = useAtom(habitFreqMapAtom)
|
||||||
|
|
||||||
const completeHabit = async (habit: Habit) => {
|
const completeHabit = async (habit: Habit) => {
|
||||||
if (!handlePermissionCheck(currentUser, 'habit', 'interact')) return
|
if (!handlePermissionCheck(currentUser, 'habit', 'interact')) return
|
||||||
@@ -313,6 +314,7 @@ export function useHabits() {
|
|||||||
deleteHabit,
|
deleteHabit,
|
||||||
completePastHabit,
|
completePastHabit,
|
||||||
archiveHabit,
|
archiveHabit,
|
||||||
unarchiveHabit
|
unarchiveHabit,
|
||||||
|
habitFreqMap,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
114
lib/atoms.ts
114
lib/atoms.ts
@@ -1,33 +1,30 @@
|
|||||||
import { atom } from "jotai";
|
|
||||||
import {
|
import {
|
||||||
getDefaultSettings,
|
|
||||||
getDefaultHabitsData,
|
|
||||||
getDefaultCoinsData,
|
|
||||||
getDefaultWishlistData,
|
|
||||||
Habit,
|
|
||||||
ViewType,
|
|
||||||
getDefaultUsersData,
|
|
||||||
CompletionCache,
|
|
||||||
getDefaultServerSettings,
|
|
||||||
User,
|
|
||||||
} from "./types";
|
|
||||||
import {
|
|
||||||
getTodayInTimezone,
|
|
||||||
isSameDate,
|
|
||||||
t2d,
|
|
||||||
calculateCoinsEarnedToday,
|
calculateCoinsEarnedToday,
|
||||||
|
calculateCoinsSpentToday,
|
||||||
calculateTotalEarned,
|
calculateTotalEarned,
|
||||||
calculateTotalSpent,
|
calculateTotalSpent,
|
||||||
calculateCoinsSpentToday,
|
|
||||||
calculateTransactionsToday,
|
calculateTransactionsToday,
|
||||||
getCompletionsForToday,
|
getCompletionsForToday,
|
||||||
getISODate,
|
getHabitFreq,
|
||||||
isHabitDueToday,
|
getTodayInTimezone,
|
||||||
getNow,
|
isHabitDue,
|
||||||
isHabitDue
|
t2d
|
||||||
} from "@/lib/utils";
|
} from "@/lib/utils";
|
||||||
|
import { atom } from "jotai";
|
||||||
import { atomFamily, atomWithStorage } from "jotai/utils";
|
import { atomFamily, atomWithStorage } from "jotai/utils";
|
||||||
import { DateTime } from "luxon";
|
import { DateTime } from "luxon";
|
||||||
|
import {
|
||||||
|
CompletionCache,
|
||||||
|
Freq,
|
||||||
|
getDefaultCoinsData,
|
||||||
|
getDefaultHabitsData,
|
||||||
|
getDefaultServerSettings,
|
||||||
|
getDefaultSettings,
|
||||||
|
getDefaultUsersData,
|
||||||
|
getDefaultWishlistData,
|
||||||
|
Habit,
|
||||||
|
ViewType
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
export interface BrowserSettings {
|
export interface BrowserSettings {
|
||||||
viewType: ViewType
|
viewType: ViewType
|
||||||
@@ -50,44 +47,44 @@ export const coinsAtom = atom(getDefaultCoinsData());
|
|||||||
export const wishlistAtom = atom(getDefaultWishlistData());
|
export const wishlistAtom = atom(getDefaultWishlistData());
|
||||||
export const serverSettingsAtom = atom(getDefaultServerSettings());
|
export const serverSettingsAtom = atom(getDefaultServerSettings());
|
||||||
|
|
||||||
// // Derived atom for coins earned today
|
// Derived atom for coins earned today
|
||||||
// export const coinsEarnedTodayAtom = atom((get) => {
|
export const coinsEarnedTodayAtom = atom((get) => {
|
||||||
// const coins = get(coinsAtom);
|
const coins = get(coinsAtom);
|
||||||
// const settings = get(settingsAtom);
|
const settings = get(settingsAtom);
|
||||||
// return calculateCoinsEarnedToday(coins.transactions, settings.system.timezone);
|
return calculateCoinsEarnedToday(coins.transactions, settings.system.timezone);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Derived atom for total earned
|
// Derived atom for total earned
|
||||||
// export const totalEarnedAtom = atom((get) => {
|
export const totalEarnedAtom = atom((get) => {
|
||||||
// const coins = get(coinsAtom);
|
const coins = get(coinsAtom);
|
||||||
// return calculateTotalEarned(coins.transactions);
|
return calculateTotalEarned(coins.transactions);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Derived atom for total spent
|
// Derived atom for total spent
|
||||||
// export const totalSpentAtom = atom((get) => {
|
export const totalSpentAtom = atom((get) => {
|
||||||
// const coins = get(coinsAtom);
|
const coins = get(coinsAtom);
|
||||||
// return calculateTotalSpent(coins.transactions);
|
return calculateTotalSpent(coins.transactions);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Derived atom for coins spent today
|
// Derived atom for coins spent today
|
||||||
// export const coinsSpentTodayAtom = atom((get) => {
|
export const coinsSpentTodayAtom = atom((get) => {
|
||||||
// const coins = get(coinsAtom);
|
const coins = get(coinsAtom);
|
||||||
// const settings = get(settingsAtom);
|
const settings = get(settingsAtom);
|
||||||
// return calculateCoinsSpentToday(coins.transactions, settings.system.timezone);
|
return calculateCoinsSpentToday(coins.transactions, settings.system.timezone);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Derived atom for transactions today
|
// Derived atom for transactions today
|
||||||
// export const transactionsTodayAtom = atom((get) => {
|
export const transactionsTodayAtom = atom((get) => {
|
||||||
// const coins = get(coinsAtom);
|
const coins = get(coinsAtom);
|
||||||
// const settings = get(settingsAtom);
|
const settings = get(settingsAtom);
|
||||||
// return calculateTransactionsToday(coins.transactions, settings.system.timezone);
|
return calculateTransactionsToday(coins.transactions, settings.system.timezone);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // Derived atom for current balance from all transactions
|
// Derived atom for current balance from all transactions
|
||||||
// export const coinsBalanceAtom = atom((get) => {
|
export const coinsBalanceAtom = atom((get) => {
|
||||||
// const coins = get(coinsAtom);
|
const coins = get(coinsAtom);
|
||||||
// return coins.transactions.reduce((sum, transaction) => sum + transaction.amount, 0);
|
return coins.transactions.reduce((sum, transaction) => sum + transaction.amount, 0);
|
||||||
// });
|
});
|
||||||
|
|
||||||
/* transient atoms */
|
/* transient atoms */
|
||||||
interface PomodoroAtom {
|
interface PomodoroAtom {
|
||||||
@@ -150,6 +147,15 @@ export const completedHabitsMapAtom = atom((get) => {
|
|||||||
return map;
|
return map;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Derived atom for habit frequency map
|
||||||
|
export const habitFreqMapAtom = atom((get) => {
|
||||||
|
const habits = get(habitsAtom).habits;
|
||||||
|
const map = new Map<string, Freq>();
|
||||||
|
habits.forEach(habit => {
|
||||||
|
map.set(habit.id, getHabitFreq(habit));
|
||||||
|
});
|
||||||
|
return map;
|
||||||
|
});
|
||||||
|
|
||||||
export const pomodoroTodayCompletionsAtom = atom((get) => {
|
export const pomodoroTodayCompletionsAtom = atom((get) => {
|
||||||
const pomo = get(pomodoroAtom)
|
const pomo = get(pomodoroAtom)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "habittrove",
|
"name": "habittrove",
|
||||||
"version": "0.2.9",
|
"version": "0.2.11",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev --turbopack",
|
"dev": "next dev --turbopack",
|
||||||
|
|||||||
Reference in New Issue
Block a user