Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,91 +125,112 @@ export const WeeklyRoutineGrid = () => {
const isToday = dayIndex === today;

return (
<div
key={day}
className={cn(
"flex min-h-45 flex-col rounded-lg border p-3",
isToday && "border-pink-600 dark:border-pink-400",
<div key={day} className="flex flex-col">
{/* Today label above card */}
{isToday ? (
<div className="mb-2 text-center">
<span className="inline-block rounded-full bg-pink-100 px-2.5 py-0.5 text-xs font-semibold text-pink-600 dark:bg-pink-950/50 dark:text-pink-400">
Today ·{" "}
{new Date().toLocaleDateString("en-US", {
month: "short",
day: "numeric",
})}
</span>
</div>
) : (
<div className="mb-2 h-5" />
)}
>
{/* Day header */}

<div
className={cn(
"mb-3 text-center text-sm font-medium",
isToday
? "text-pink-600 dark:text-pink-400"
: "text-muted-foreground",
"flex min-h-45 flex-1 flex-col rounded-lg border p-3",
isToday && "border-pink-600 dark:border-pink-400",
)}
>
{day}
</div>
{/* Day header */}
<div
className={cn(
"mb-3 text-center text-sm font-medium",
isToday
? "text-pink-600 dark:text-pink-400"
: "text-muted-foreground",
)}
>
{day}
</div>

{/* Routine cards for this day */}
<div className="flex flex-col gap-2">
{routinesByDay[dayIndex]?.map((routine) => {
const colors = getColors(routine.color);
{/* Routine cards for this day */}
<div className="flex flex-col gap-2">
{routinesByDay[dayIndex]?.map((routine) => {
const colors = getColors(routine.color);

return (
<HoverCard key={`${routine._id}-${dayIndex}`} openDelay={200}>
<HoverCardTrigger asChild>
<div
className={`cursor-pointer rounded-md border px-2.5 py-2 ${colors.bg} ${colors.border}`}
>
<p
className={`truncate text-sm font-medium ${colors.text}`}
>
{routine.title}
</p>
<p className={`text-xs ${colors.time}`}>
{formatTime(
routine.schedule.hour,
routine.schedule.minute,
)}
</p>
</div>
</HoverCardTrigger>
<HoverCardContent
className="w-72"
side="right"
align="start"
return (
<HoverCard
key={`${routine._id}-${dayIndex}`}
openDelay={200}
>
<div className="space-y-2">
<h4 className="text-sm font-semibold">
{routine.title}
</h4>
{routine.description && (
<p className="text-muted-foreground text-sm">
{routine.description}
<HoverCardTrigger asChild>
<div
className={`cursor-pointer rounded-md border px-2.5 py-2 ${colors.bg} ${colors.border}`}
>
<p
className={`truncate text-sm font-medium ${colors.text}`}
>
{routine.title}
</p>
)}
<div className="text-muted-foreground flex flex-col gap-1 text-xs">
<div className="flex justify-between">
<span>Schedule</span>
<span className="text-foreground">
{formatScheduleDays(routine.schedule.daysOfWeek)}
</span>
</div>
<div className="flex justify-between">
<span>Time</span>
<span className="text-foreground">
{formatTime(
routine.schedule.hour,
routine.schedule.minute,
)}
</span>
</div>
<div className="flex justify-between">
<span>Priority</span>
<span className="text-foreground">
{formatPriority(routine.priority)}
</span>
<p className={`text-xs ${colors.time}`}>
{formatTime(
routine.schedule.hour,
routine.schedule.minute,
)}
</p>
</div>
</HoverCardTrigger>
<HoverCardContent
className="w-72"
side="right"
align="start"
>
<div className="space-y-2">
<h4 className="text-sm font-semibold">
{routine.title}
</h4>
{routine.description && (
<p className="text-muted-foreground text-sm">
{routine.description}
</p>
)}
<div className="text-muted-foreground flex flex-col gap-1 text-xs">
<div className="flex justify-between">
<span>Schedule</span>
<span className="text-foreground">
{formatScheduleDays(
routine.schedule.daysOfWeek,
)}
</span>
</div>
<div className="flex justify-between">
<span>Time</span>
<span className="text-foreground">
{formatTime(
routine.schedule.hour,
routine.schedule.minute,
)}
</span>
</div>
<div className="flex justify-between">
<span>Priority</span>
<span className="text-foreground">
{formatPriority(routine.priority)}
</span>
</div>
</div>
</div>
</div>
</HoverCardContent>
</HoverCard>
);
})}
</HoverCardContent>
</HoverCard>
);
})}
</div>
</div>
</div>
);
Expand Down
18 changes: 18 additions & 0 deletions packages/backend/convex/routines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ export const trigger = mutation({

const now = Date.now();

// Deduplicate: skip if an active task with the same title already exists
const existingTasks = await ctx.db
.query("tasks")
.withIndex("by_createdAt")
.collect();
const activeStatuses = ["inbox", "assigned", "in_progress", "review"];
const duplicate = existingTasks.find(
(t) => t.title === routine.title && activeStatuses.includes(t.status),
);
if (duplicate) {
// Already an active task for this routine — skip creation
await ctx.db.patch(args.routineId, {
lastTriggeredAt: now,
updatedAt: now,
});
return duplicate._id;
}

// Create task from routine template
const taskId = await ctx.db.insert("tasks", {
title: routine.title,
Expand Down