mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-21 06:34:30 +01:00
Compare commits
3 Commits
v0.2.10
...
client-hel
| Author | SHA1 | Date | |
|---|---|---|---|
|
ddffacbd52
|
|||
|
|
95197e216c | ||
|
|
660005d857 |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,5 +1,19 @@
|
|||||||
# 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
|
## Version 0.2.10
|
||||||
|
|
||||||
### Improved
|
### Improved
|
||||||
|
|||||||
@@ -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,26 +1,35 @@
|
|||||||
import { Circle, Coins, ArrowRight, CircleCheck, ChevronDown, ChevronUp, Timer, Plus, Pin, Calendar } from 'lucide-react'
|
import { Circle, Coins, ArrowRight, CircleCheck, ChevronDown, ChevronUp, Plus, Pin, AlertTriangle } from 'lucide-react' // Removed unused icons
|
||||||
import CompletionCountBadge from './CompletionCountBadge'
|
import CompletionCountBadge from './CompletionCountBadge'
|
||||||
import {
|
import {
|
||||||
ContextMenu,
|
ContextMenu,
|
||||||
ContextMenuContent,
|
ContextMenuContent,
|
||||||
ContextMenuItem,
|
ContextMenuItem,
|
||||||
|
ContextMenuSeparator,
|
||||||
ContextMenuTrigger,
|
ContextMenuTrigger,
|
||||||
} from "@/components/ui/context-menu"
|
} from "@/components/ui/context-menu"
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useAtom } from 'jotai'
|
import { useAtom } from 'jotai'
|
||||||
import { pomodoroAtom, settingsAtom, completedHabitsMapAtom, browserSettingsAtom, BrowserSettings, hasTasksAtom, dailyHabitsAtom } from '@/lib/atoms'
|
import { pomodoroAtom, settingsAtom, completedHabitsMapAtom, browserSettingsAtom, BrowserSettings, hasTasksAtom } from '@/lib/atoms'
|
||||||
import { getTodayInTimezone, isSameDate, t2d, d2t, getNow } from '@/lib/utils'
|
import { getTodayInTimezone, isSameDate, t2d, d2t, getNow, isHabitDue, isTaskOverdue } from '@/lib/utils'
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import { Badge } from '@/components/ui/badge'
|
import { Badge } from '@/components/ui/badge'
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip"
|
||||||
import { Progress } from '@/components/ui/progress'
|
import { Progress } from '@/components/ui/progress'
|
||||||
import { Settings, WishlistItemType } from '@/lib/types'
|
import { Settings, WishlistItemType } from '@/lib/types'
|
||||||
import { Habit } from '@/lib/types'
|
import { Habit } from '@/lib/types'
|
||||||
import Linkify from './linkify'
|
import Linkify from './linkify'
|
||||||
import { useHabits } from '@/hooks/useHabits'
|
import { useHabits } from '@/hooks/useHabits'
|
||||||
import AddEditHabitModal from './AddEditHabitModal'
|
import AddEditHabitModal from './AddEditHabitModal'
|
||||||
|
import ConfirmDialog from './ConfirmDialog'
|
||||||
import { Button } from './ui/button'
|
import { Button } from './ui/button'
|
||||||
|
import { HabitContextMenuItems } from './HabitContextMenuItems'
|
||||||
|
|
||||||
interface UpcomingItemsProps {
|
interface UpcomingItemsProps {
|
||||||
habits: Habit[]
|
habits: Habit[]
|
||||||
@@ -34,13 +43,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 +52,46 @@ const ItemSection = ({
|
|||||||
emptyMessage,
|
emptyMessage,
|
||||||
isTask,
|
isTask,
|
||||||
viewLink,
|
viewLink,
|
||||||
expanded,
|
|
||||||
setExpanded,
|
|
||||||
addNewItem,
|
addNewItem,
|
||||||
badgeType,
|
|
||||||
todayCompletions,
|
|
||||||
settings,
|
|
||||||
setBrowserSettings,
|
|
||||||
}: ItemSectionProps) => {
|
}: ItemSectionProps) => {
|
||||||
const { completeHabit, undoComplete, saveHabit, habitFreqMap } = 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 +122,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 +134,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,8 +143,8 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -134,7 +167,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 +223,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>
|
||||||
@@ -271,10 +300,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 +319,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 +329,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 +362,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 +424,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 +435,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">
|
||||||
|
|||||||
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>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ import { settingsAtom, pomodoroAtom, browserSettingsAtom, usersAtom } from '@/li
|
|||||||
import { getTodayInTimezone, isSameDate, t2d, d2t, getNow, d2s, getCompletionsForToday, isTaskOverdue, convertMachineReadableFrequencyToHumanReadable } from '@/lib/utils'
|
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 { 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 { Coins, Edit, Check, Undo2, MoreVertical, Pin } from 'lucide-react' // Removed unused icons
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
@@ -18,6 +18,7 @@ import { INITIAL_RECURRENCE_RULE, RECURRENCE_RULE_MAP } from '@/lib/constants'
|
|||||||
import { DateTime } from 'luxon'
|
import { DateTime } from 'luxon'
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar'
|
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar'
|
||||||
import { useHelpers } from '@/lib/client-helpers'
|
import { useHelpers } from '@/lib/client-helpers'
|
||||||
|
import { HabitContextMenuItems } from './HabitContextMenuItems'
|
||||||
|
|
||||||
interface HabitItemProps {
|
interface HabitItemProps {
|
||||||
habit: Habit
|
habit: Habit
|
||||||
@@ -194,70 +195,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,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState, useMemo, useEffect } from 'react' // Added useMemo, useEffect
|
||||||
import { Plus, ListTodo } from 'lucide-react'
|
import { Plus, ArrowUpNarrowWide, ArrowDownWideNarrow, Search } from 'lucide-react' // Added sort icons, Search icon
|
||||||
import { useAtom } from 'jotai'
|
import { useAtom } from 'jotai'
|
||||||
import { habitsAtom, settingsAtom, browserSettingsAtom } from '@/lib/atoms'
|
import { habitsAtom, settingsAtom, browserSettingsAtom } from '@/lib/atoms'
|
||||||
import EmptyState from './EmptyState'
|
import EmptyState from './EmptyState'
|
||||||
@@ -13,20 +13,100 @@ import { Habit } from '@/lib/types'
|
|||||||
import { useHabits } from '@/hooks/useHabits'
|
import { useHabits } from '@/hooks/useHabits'
|
||||||
import { HabitIcon, TaskIcon } from '@/lib/constants'
|
import { HabitIcon, TaskIcon } from '@/lib/constants'
|
||||||
import { ViewToggle } from './ViewToggle'
|
import { ViewToggle } from './ViewToggle'
|
||||||
|
import { Input } from '@/components/ui/input' // Added
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' // Added
|
||||||
|
import { Label } from '@/components/ui/label' // Added
|
||||||
|
import { DateTime } from 'luxon' // Added
|
||||||
|
import { getHabitFreq } from '@/lib/utils' // Added
|
||||||
|
|
||||||
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}
|
||||||
|
|||||||
@@ -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,9 +1,8 @@
|
|||||||
// client helpers
|
// client helpers
|
||||||
'use-client'
|
'use-client'
|
||||||
|
|
||||||
import { useSession } from "next-auth/react"
|
|
||||||
import { User, UserId } from './types'
|
|
||||||
import { useAtom } from 'jotai'
|
import { useAtom } from 'jotai'
|
||||||
|
import { useSession } from "next-auth/react"
|
||||||
import { usersAtom } from './atoms'
|
import { usersAtom } from './atoms'
|
||||||
import { checkPermission } from './utils'
|
import { checkPermission } from './utils'
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@ export function useHelpers() {
|
|||||||
const currentUser = usersData.users.find((u) => u.id === currentUserId)
|
const currentUser = usersData.users.find((u) => u.id === currentUserId)
|
||||||
// detect iOS: https://stackoverflow.com/a/9039885
|
// detect iOS: https://stackoverflow.com/a/9039885
|
||||||
function iOS() {
|
function iOS() {
|
||||||
return [
|
return typeof navigator !== "undefined" && ([
|
||||||
'iPad Simulator',
|
'iPad Simulator',
|
||||||
'iPhone Simulator',
|
'iPhone Simulator',
|
||||||
'iPod Simulator',
|
'iPod Simulator',
|
||||||
@@ -23,7 +22,7 @@ export function useHelpers() {
|
|||||||
'iPod',
|
'iPod',
|
||||||
].includes(navigator.platform)
|
].includes(navigator.platform)
|
||||||
// iPad on iOS 13 detection
|
// iPad on iOS 13 detection
|
||||||
|| (navigator.userAgent.includes("Mac") && "ontouchend" in document)
|
|| (navigator.userAgent.includes("Mac") && "ontouchend" in document))
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "habittrove",
|
"name": "habittrove",
|
||||||
"version": "0.2.10",
|
"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