feat: journal dashboard widgets, agent polish, and edit-mode live previews
Journal dashboard widgets and quick-add; rich-text quick-add dialogs. Dashboard draft sync for live edit previews; assistant bubble + API tools. Journal UX: stress slider, mood grid, query cap fix.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useTransition } from "react";
|
||||
import { setAssistantEnabled } from "@/app/settings/assistant-actions";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
|
||||
export function AssistantOptIn({ enabled }: { enabled: boolean }) {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const router = useRouter();
|
||||
|
||||
function toggle(next: boolean) {
|
||||
startTransition(async () => {
|
||||
await setAssistantEnabled(next);
|
||||
router.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<label className="flex items-center justify-between gap-4">
|
||||
<div className="min-w-0">
|
||||
<div className="text-sm font-medium">AI assistant</div>
|
||||
<p className="muted text-[12px] mt-0.5">
|
||||
Off by default. Turn on to show a chat bubble in the bottom-right corner.
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
checked={enabled}
|
||||
disabled={isPending}
|
||||
onCheckedChange={toggle}
|
||||
aria-label="AI assistant"
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
@@ -11,7 +11,12 @@ import { GripVertical, Settings2, Trash2, RotateCcw, Plus, LayoutGrid } from "lu
|
||||
import type { DashboardLayout, WidgetPlacement, PresetId } from "@/lib/dashboard";
|
||||
import { computePresetLayoutFromMetas, widgetContentKey } from "@/lib/dashboard";
|
||||
import type { SerializedWidgetMeta } from "@/modules/_core/registry";
|
||||
import { saveDashboardLayout, resetDashboardLayout } from "@/app/d/actions";
|
||||
import {
|
||||
saveDashboardLayout,
|
||||
resetDashboardLayout,
|
||||
syncEditorDraftLayout,
|
||||
discardEditorDraftLayout,
|
||||
} from "@/app/d/actions";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { WidgetPicker } from "./widget-picker";
|
||||
|
||||
@@ -58,8 +63,18 @@ export function DashboardEditor({
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [dashboard.slug]);
|
||||
|
||||
function publishDraft(next: WidgetPlacement[]) {
|
||||
startTransition(async () => {
|
||||
await syncEditorDraftLayout(dashboard.id, { version: 1, widgets: next });
|
||||
router.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
router.push(`/d/${dashboard.slug}`);
|
||||
startTransition(async () => {
|
||||
await discardEditorDraftLayout(dashboard.id);
|
||||
router.push(`/d/${dashboard.slug}`);
|
||||
});
|
||||
}
|
||||
|
||||
function handleSave() {
|
||||
@@ -89,26 +104,32 @@ export function DashboardEditor({
|
||||
}
|
||||
|
||||
function removeWidget(index: number) {
|
||||
setPlacements((current) => current.filter((_, i) => i !== index));
|
||||
const next = placements.filter((_, i) => i !== index);
|
||||
setPlacements(next);
|
||||
setIsDirty(true);
|
||||
publishDraft(next);
|
||||
}
|
||||
|
||||
function addWidget(widgetId: string, config: unknown) {
|
||||
const meta = widgetMetas.find((m) => m.id === widgetId);
|
||||
if (!meta) return;
|
||||
const maxY = placements.reduce((m, p) => Math.max(m, p.y + p.h), 0);
|
||||
setPlacements((current) => [
|
||||
...current,
|
||||
const next = [
|
||||
...placements,
|
||||
{ widgetId, config, x: 0, y: maxY, w: meta.defaultSize.w, h: meta.defaultSize.h },
|
||||
]);
|
||||
];
|
||||
setPlacements(next);
|
||||
setIsDirty(true);
|
||||
setPickerOpen(false);
|
||||
publishDraft(next);
|
||||
}
|
||||
|
||||
function updateConfig(index: number, config: unknown) {
|
||||
setPlacements((current) => current.map((p, i) => (i === index ? { ...p, config } : p)));
|
||||
const next = placements.map((p, i) => (i === index ? { ...p, config } : p));
|
||||
setPlacements(next);
|
||||
setIsDirty(true);
|
||||
setConfiguringIndex(null);
|
||||
publishDraft(next);
|
||||
}
|
||||
|
||||
function applyPreset(preset: PresetId) {
|
||||
@@ -116,6 +137,7 @@ export function DashboardEditor({
|
||||
setPlacements(next.widgets);
|
||||
setIsDirty(true);
|
||||
setPresetMenuOpen(false);
|
||||
publishDraft(next.widgets);
|
||||
}
|
||||
|
||||
const gridItems: Layout = placements.map((p, i) => ({
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
"use client";
|
||||
|
||||
const greetingForHour = (h: number) =>
|
||||
h < 5 ? "Up early" : h < 12 ? "Good morning" : h < 18 ? "Good afternoon" : "Good evening";
|
||||
|
||||
@@ -18,7 +16,9 @@ export function DashboardGreeting({ firstName }: { firstName: string }) {
|
||||
{greeting}
|
||||
{firstName && `, ${firstName}`}.
|
||||
</h1>
|
||||
<p className="muted mt-1 text-[13px]">{today}</p>
|
||||
<p className="muted mt-1 text-[13px]" suppressHydrationWarning>
|
||||
{today}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { CalendarCreateDialog } from "@/components/quick-add/dialogs/calendar-cr
|
||||
import { CalendarEventCreateDialog } from "@/components/quick-add/dialogs/calendar-event-create-dialog";
|
||||
import { ContainerCreateDialog } from "@/components/quick-add/dialogs/container-create-dialog";
|
||||
import { GardenCareLogDialog } from "@/components/quick-add/dialogs/garden-care-log-dialog";
|
||||
import { JournalEntryCreateDialog } from "@/components/quick-add/dialogs/journal-entry-create-dialog";
|
||||
import { ListCreateDialog } from "@/components/quick-add/dialogs/list-create-dialog";
|
||||
import { ListItemCreateDialog } from "@/components/quick-add/dialogs/list-item-create-dialog";
|
||||
import { NoteCreateDialog } from "@/components/quick-add/dialogs/note-create-dialog";
|
||||
@@ -29,6 +30,10 @@ export function QuickAddCreateHost() {
|
||||
onOpenChange={onOpenChange}
|
||||
/>
|
||||
<NoteCreateDialog open={activeCreateKey === "notes.note"} onOpenChange={onOpenChange} />
|
||||
<JournalEntryCreateDialog
|
||||
open={activeCreateKey === "journal.entry"}
|
||||
onOpenChange={onOpenChange}
|
||||
/>
|
||||
<ListItemCreateDialog
|
||||
open={activeCreateKey === "lists.add-shopping"}
|
||||
onOpenChange={onOpenChange}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import { useEffect, useMemo, useState, useTransition } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -20,8 +21,21 @@ import {
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { createEvent } from "@/modules/calendar/server/actions";
|
||||
import { richTextToPlainText } from "@/components/rich-text";
|
||||
import { listCalendars, type CalendarDto } from "@/modules/calendar/server/queries";
|
||||
|
||||
const RichTextEditor = dynamic(
|
||||
() => import("@/components/rich-text/rich-text-editor").then((mod) => mod.RichTextEditor),
|
||||
{
|
||||
ssr: false,
|
||||
loading: () => (
|
||||
<div className="min-h-24 rounded-lg border border-input px-3 py-2 text-sm text-muted-foreground animate-pulse">
|
||||
Loading editor…
|
||||
</div>
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
type Props = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
@@ -30,7 +44,7 @@ type Props = {
|
||||
export function CalendarEventCreateDialog({ open, onOpenChange }: Props) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogContent className="sm:max-w-2xl">
|
||||
{open ? <CalendarEventCreateForm onDone={() => onOpenChange(false)} /> : null}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
@@ -71,7 +85,7 @@ function CalendarEventCreateForm({ onDone }: { onDone: () => void }) {
|
||||
endAt: new Date(endAt),
|
||||
allDay: false,
|
||||
location: location || null,
|
||||
notes: notes || null,
|
||||
notes: richTextToPlainText(notes) ? notes : null,
|
||||
remindMinutesBefore: remind ? 30 : null,
|
||||
});
|
||||
onDone();
|
||||
@@ -146,13 +160,15 @@ function CalendarEventCreateForm({ onDone }: { onDone: () => void }) {
|
||||
onChange={(e) => setLocation(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<div className="space-y-1.5 min-w-0">
|
||||
<Label htmlFor="qa-event-notes">Notes</Label>
|
||||
<textarea
|
||||
<RichTextEditor
|
||||
id="qa-event-notes"
|
||||
className="min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-sm outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50"
|
||||
aria-label="Notes"
|
||||
value={notes}
|
||||
onChange={(e) => setNotes(e.target.value)}
|
||||
onChange={setNotes}
|
||||
disabled={isPending}
|
||||
placeholder="Add details…"
|
||||
/>
|
||||
</div>
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
"use client";
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState, useTransition } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { MoodPicker } from "@/modules/journal/components/mood-picker";
|
||||
import { StressSlider } from "@/modules/journal/components/stress-slider";
|
||||
import { createJournalEntry } from "@/modules/journal/server/actions";
|
||||
|
||||
const RichTextEditor = dynamic(
|
||||
() => import("@/components/rich-text/rich-text-editor").then((mod) => mod.RichTextEditor),
|
||||
{
|
||||
ssr: false,
|
||||
loading: () => (
|
||||
<div className="min-h-40 rounded-[var(--r-md)] border-[0.5px] px-3 py-2 text-sm muted animate-pulse">
|
||||
Loading editor…
|
||||
</div>
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
type Props = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
};
|
||||
|
||||
export function JournalEntryCreateDialog({ open, onOpenChange }: Props) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-2xl">
|
||||
{open ? <JournalEntryCreateForm onDone={() => onOpenChange(false)} /> : null}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function JournalEntryCreateForm({ onDone }: { onDone: () => void }) {
|
||||
const router = useRouter();
|
||||
const [recordedAt, setRecordedAt] = useState(toLocalDateTimeValue(null));
|
||||
const [title, setTitle] = useState("");
|
||||
const [body, setBody] = useState("");
|
||||
const [moods, setMoods] = useState<string[]>([]);
|
||||
const [stress, setStress] = useState(5);
|
||||
const [trackStress, setTrackStress] = useState(true);
|
||||
const [pillsTaken, setPillsTaken] = useState(false);
|
||||
const [trackPills, setTrackPills] = useState(true);
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
startTransition(async () => {
|
||||
await createJournalEntry({
|
||||
recordedAt: new Date(recordedAt),
|
||||
title: title.trim() || null,
|
||||
body,
|
||||
moods,
|
||||
stress: trackStress ? stress : null,
|
||||
pillsTaken: trackPills ? pillsTaken : null,
|
||||
});
|
||||
router.refresh();
|
||||
onDone();
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<DialogHeader>
|
||||
<DialogTitle>New journal entry</DialogTitle>
|
||||
</DialogHeader>
|
||||
<form id="quick-add-journal-form" onSubmit={handleSubmit} className="grid gap-3">
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="qa-journal-recorded">When</Label>
|
||||
<Input
|
||||
id="qa-journal-recorded"
|
||||
type="datetime-local"
|
||||
value={recordedAt}
|
||||
onChange={(e) => setRecordedAt(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="qa-journal-title">Title</Label>
|
||||
<Input
|
||||
id="qa-journal-title"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder="Optional"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label>Moods</Label>
|
||||
<MoodPicker value={moods} onChange={setMoods} disabled={isPending} />
|
||||
</div>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<Label htmlFor="qa-journal-stress">Stress (1–10)</Label>
|
||||
<div className="flex items-center gap-2 text-[12px] text-muted-foreground">
|
||||
<span>Track</span>
|
||||
<Switch checked={trackStress} onCheckedChange={setTrackStress} />
|
||||
</div>
|
||||
</div>
|
||||
<StressSlider
|
||||
id="qa-journal-stress"
|
||||
value={stress}
|
||||
onChange={setStress}
|
||||
disabled={!trackStress || isPending}
|
||||
/>
|
||||
{!trackStress ? (
|
||||
<div className="text-[12px] text-muted-foreground">Not tracked</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<Label htmlFor="qa-journal-pills">Pills today</Label>
|
||||
<div className="flex items-center gap-2 text-[12px] text-muted-foreground">
|
||||
<span>Track</span>
|
||||
<Switch checked={trackPills} onCheckedChange={setTrackPills} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 pt-2">
|
||||
<Switch
|
||||
id="qa-journal-pills"
|
||||
checked={pillsTaken}
|
||||
disabled={!trackPills || isPending}
|
||||
onCheckedChange={setPillsTaken}
|
||||
/>
|
||||
<span className="text-[13px]">{pillsTaken ? "Taken" : "Not taken"}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-1.5 min-w-0">
|
||||
<Label htmlFor="qa-journal-body">Reflection</Label>
|
||||
<RichTextEditor
|
||||
id="qa-journal-body"
|
||||
aria-label="Reflection"
|
||||
value={body}
|
||||
onChange={setBody}
|
||||
disabled={isPending}
|
||||
placeholder="What happened today?"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
<DialogFooter>
|
||||
<Button type="submit" form="quick-add-journal-form" disabled={isPending}>
|
||||
Save entry
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function toLocalDateTimeValue(value: string | null) {
|
||||
const date = value ? new Date(value) : new Date();
|
||||
const local = new Date(date.getTime() - date.getTimezoneOffset() * 60_000);
|
||||
return local.toISOString().slice(0, 16);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import { useState, useTransition } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -13,6 +14,18 @@ import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { createNote } from "@/modules/notes/server/actions";
|
||||
|
||||
const RichTextEditor = dynamic(
|
||||
() => import("@/components/rich-text/rich-text-editor").then((mod) => mod.RichTextEditor),
|
||||
{
|
||||
ssr: false,
|
||||
loading: () => (
|
||||
<div className="min-h-32 rounded-lg border border-input px-3 py-2 text-sm text-muted-foreground animate-pulse">
|
||||
Loading editor…
|
||||
</div>
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
type Props = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
@@ -21,7 +34,7 @@ type Props = {
|
||||
export function NoteCreateDialog({ open, onOpenChange }: Props) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogContent className="sm:max-w-2xl">
|
||||
{open ? <NoteCreateForm onDone={() => onOpenChange(false)} /> : null}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
@@ -62,14 +75,15 @@ function NoteCreateForm({ onDone }: { onDone: () => void }) {
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<div className="space-y-1.5 min-w-0">
|
||||
<Label htmlFor="qa-note-body">Body</Label>
|
||||
<textarea
|
||||
<RichTextEditor
|
||||
id="qa-note-body"
|
||||
aria-label="Body"
|
||||
className="min-h-32 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-sm outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50"
|
||||
value={body}
|
||||
onChange={(e) => setBody(e.target.value)}
|
||||
onChange={setBody}
|
||||
disabled={isPending}
|
||||
placeholder="Start writing…"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
|
||||
@@ -103,10 +103,12 @@ export function WidgetPicker({
|
||||
key={meta.id}
|
||||
type="button"
|
||||
onClick={() => selectWidget(meta.id)}
|
||||
className="w-full text-left rounded-md px-3 py-2 hover:bg-accent transition-colors"
|
||||
className="group w-full text-left rounded-md px-3 py-2 transition-colors hover:bg-[var(--shade)] focus-visible:bg-[var(--shade)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--hair-2)]"
|
||||
>
|
||||
<p className="text-sm font-medium">{meta.title}</p>
|
||||
<p className="text-xs text-muted-foreground">{meta.description}</p>
|
||||
<p className="text-sm font-medium text-[var(--ink)]">{meta.title}</p>
|
||||
<p className="text-xs text-[var(--ink-mute)] group-hover:text-[var(--ink-2)] group-focus-visible:text-[var(--ink-2)]">
|
||||
{meta.description}
|
||||
</p>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user