[+] New feature: Added dynamic time-aware daily AI reflection prompts.#51
Conversation
📝 WalkthroughWalkthroughThis PR adds an end-to-end dynamic daily reflection prompt system: new types, domain validation/fallback logic, a Supabase edge function calling an AI provider, a client service with request deduplication, a persisted Zustand store, ChangesDynamic Daily Reflection Prompts
Layout tweaks
Estimated code review effort: 4 (Complex) | ~75 minutes Sequence Diagram(s)sequenceDiagram
participant HomeScreen
participant useDailyReflectionPrompt
participant PromptStore as useDailyReflectionPromptStore
participant PromptService as dailyReflectionPromptService
participant EdgeFunction as generate-daily-reflection-prompts
participant AIProvider
HomeScreen->>useDailyReflectionPrompt: currentTime (from useReflectionClock)
useDailyReflectionPrompt->>PromptStore: read cached bundle / hydration status
alt bundle missing and online
useDailyReflectionPrompt->>PromptService: generateDailyReflectionPromptBundle
PromptService->>EdgeFunction: POST dateKey, timezone
EdgeFunction->>AIProvider: chat completion request
AIProvider-->>EdgeFunction: prompt JSON
EdgeFunction-->>PromptService: validated prompts
PromptService-->>useDailyReflectionPrompt: bundle or error
useDailyReflectionPrompt->>PromptStore: setBundle (generated or fallback)
else offline
useDailyReflectionPrompt->>PromptStore: setBundle (fallback)
end
useDailyReflectionPrompt-->>HomeScreen: isLoading, period, prompt
HomeScreen->>HomeScreen: openDailyReflection navigates to /journal/new
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@components/home/home-screen.tsx`:
- Around line 198-211: The empty-state CTA is currently disabled in
openDailyReflection when reflectionPrompt is null, which blocks users while the
prompt is still loading. Update openDailyReflection in home-screen.tsx to always
navigate to a usable journal entry path, either by falling back to the plain
/journal/new flow without prompt params or by preserving the previous non-prompt
editor route, while keeping the reflection prompt behavior only when
reflectionPrompt is available.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 571aa6c4-9238-4d9f-9228-ec29f577adc0
⛔ Files ignored due to path filters (1)
assets/images/insights-tab-mockup.pngis excluded by!**/*.png
📒 Files selected for processing (17)
components/ai/ai-response-renderer.tsxcomponents/home/home-screen.tsxcomponents/insights/insights-screen.tsxdata/daily-reflection-prompts.tsdocs/dynamic-home-reflection-prompts-test.mdhooks/useDailyReflectionPrompt.tshooks/useReflectionClock.tslib/account/clearLocalUserData.tslib/ai/dailyReflectionPromptService.tslib/reflection-prompts/dailyReflectionPrompts.tspackage.jsonstore/useDailyReflectionPromptStore.tssupabase/config.tomlsupabase/functions/generate-daily-reflection-prompts/deno.jsonsupabase/functions/generate-daily-reflection-prompts/index.tstests/daily-reflection-prompts.test.tstypes/dailyReflectionPrompt.ts
Summary by CodeRabbit
New Features
Bug Fixes