Skip to content

Conversation

timDeHof
Copy link
Owner

@timDeHof timDeHof commented Jul 31, 2025

closes #25
closes #26

  • New dashboard index page with location cards
  • Added locations store with real-time updates
  • Created API endpoint for fetching locations
  • Updated sidebar component to use href prop
  • Refactored location queries and types

Summary by CodeRabbit

  • New Features

    • Added a dashboard page displaying user locations in a responsive grid, with loading states and prompts for adding new locations.
    • Introduced dynamic sidebar items that update based on user locations, with loading indicators.
    • Implemented secure API endpoints for fetching and creating user locations, accessible only to authenticated users.
    • Added new stores for managing locations and sidebar state.
  • Improvements

    • Sidebar navigation updated to use a more descriptive prop for links.
    • Sidebar dynamically reflects user-specific data and loading status.
  • Bug Fixes

    • Improved authentication handling for API endpoints, ensuring only authenticated users can access or modify location data.

- New dashboard index page with location cards
- Added locations store with real-time updates
- Created API endpoint for fetching locations
- Updated sidebar component to use href prop
- Refactored location queries and types
@timDeHof timDeHof linked an issue Jul 31, 2025 that may be closed by this pull request
4 tasks
Copy link

vercel bot commented Jul 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nuxt-travel-log ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2025 2:44am

Copy link

coderabbitai bot commented Jul 31, 2025

Walkthrough

This change introduces dynamic location listing and loading states in the dashboard and sidebar. It adds new Pinia stores for locations and sidebar items, a secure API for fetching user locations, and a utility for authenticated event handling. The sidebar-button component's navigation prop is renamed from to to href throughout the codebase.

Changes

Cohort / File(s) Change Summary
Sidebar Button Prop Refactor
components/sidebar-button.vue, pages/dashboard.vue
Renamed navigation prop in sidebar-button from to to href and updated all usages accordingly.
Dashboard Locations Listing
pages/dashboard/index.vue
Added a new dashboard page component that lists user locations, handles loading and empty states, and provides an "add location" prompt.
Sidebar Dynamic Locations & Loading
stores/sidebar.ts, stores/locations.ts, pages/dashboard.vue
Introduced new Pinia stores for sidebar and locations, enabling dynamic sidebar location listing, icons, and loading indicators. Sidebar updates automatically with location changes.
API: Fetch Locations
server/api/locations.get.ts, lib/db/queries/location.ts
Added a secure API endpoint and supporting DB query to fetch all locations for the authenticated user.
API: Authenticated Handler Utility
utils/define-authenticated-event-handler.ts, server/api/locations.post.ts
Added a reusable utility to enforce authentication in event handlers and refactored the locations POST API to use it instead of inline checks.
Type Update
lib/types.ts
Updated the type of the user in the H3 event context to use UserWithId from the auth module, removing a local alias.
CI Workflow Update
.github/workflows/lint.yml
Integrated linting into the build job by removing the separate lint job and adjusting job naming and steps.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DashboardPage
    participant LocationsStore
    participant SidebarStore
    participant API
    participant DB

    User->>DashboardPage: Visit /dashboard
    DashboardPage->>LocationsStore: refresh()
    LocationsStore->>API: GET /api/locations
    API->>DB: findLocations(userId)
    DB-->>API: Locations[]
    API-->>LocationsStore: Locations[]
    LocationsStore->>SidebarStore: update sidebarItems with Locations
    DashboardPage->>User: Show loading, then locations or empty state
    SidebarStore->>User: Show sidebar items with locations and loading indicator
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Assessment against linked issues

Objective Addressed Explanation
Loading indicator displayed while fetching data (#25, #26)
Empty state is shown when no locations exist (#25, #26)
Click here to add a location (#25)
Each item shows location name and description (#25)
Location list is displayed in sidebar (#26)
Each location shows name and icon (#26)
List updates automatically when locations change (#26)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Poem

In the sidebar, new places appear,
With icons and names, all crystal clear.
The dashboard now shows your journeys anew,
Loading and empty states—handled for you!
As rabbits we code, with hops full of cheer,
Your travel log grows—adventure is near!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ntl-25

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
utils/define-authenticated-event-handler.ts (1)

25-32: Remove commented code.

The commented code appears to be leftover from development and should be removed to keep the codebase clean.

-// export default defineEventHandler(async (event) => {
-//   if (!event.context.user) {
-//     return sendError(event, createError({
-//       statusCode: 401,
-//       statusMessage: "Unauthorized",
-//     }));
-//   }
-// });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56d0f29 and b10f7a2.

📒 Files selected for processing (10)
  • components/sidebar-button.vue (2 hunks)
  • lib/db/queries/location.ts (1 hunks)
  • lib/types.ts (1 hunks)
  • pages/dashboard.vue (2 hunks)
  • pages/dashboard/index.vue (1 hunks)
  • server/api/locations.get.ts (1 hunks)
  • server/api/locations.post.ts (1 hunks)
  • stores/locations.ts (1 hunks)
  • stores/sidebar.ts (1 hunks)
  • utils/define-authenticated-event-handler.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (6)
lib/db/queries/location.ts (1)
lib/db/schema/location.ts (1)
  • location (8-18)
server/api/locations.get.ts (2)
utils/define-authenticated-event-handler.ts (1)
  • defineAuthenticatedEventHandler (11-23)
lib/db/queries/location.ts (1)
  • findLocations (11-15)
utils/define-authenticated-event-handler.ts (1)
lib/auth.ts (1)
  • UserWithId (11-13)
stores/locations.ts (1)
stores/sidebar.ts (1)
  • useSidebarStore (8-15)
server/api/locations.post.ts (1)
utils/define-authenticated-event-handler.ts (1)
  • defineAuthenticatedEventHandler (11-23)
lib/types.ts (1)
lib/auth.ts (1)
  • UserWithId (11-13)
🔇 Additional comments (17)
lib/db/queries/location.ts (1)

11-15: LGTM! Well-implemented database query function.

The findLocations function correctly filters locations by userId using Drizzle ORM's eq condition, ensuring data isolation between users. The implementation follows the existing patterns in the file and is secure against SQL injection.

stores/sidebar.ts (2)

1-6: Well-defined type interface.

The SidebarItem type is properly structured with all necessary properties for sidebar navigation items. The use of href instead of to aligns with the navigation prop standardization mentioned in the PR objectives.


8-15: Clean Pinia store implementation.

The store follows Pinia composition API best practices with reactive references for sidebarItems and loading state. The implementation is minimal yet sufficient for managing sidebar state.

components/sidebar-button.vue (2)

2-7: Consistent prop rename from 'to' to 'href'.

The prop definition has been correctly updated to use href instead of to, maintaining the same functionality while standardizing navigation prop naming across the application.


18-21: All prop references correctly updated.

The template properly uses props.href in both the :to binding and the conditional class logic for active route highlighting. The functionality remains intact after the prop rename.

server/api/locations.get.ts (1)

1-6: Secure and well-structured API endpoint.

The endpoint correctly uses defineAuthenticatedEventHandler to enforce authentication and securely accesses the user's locations using their ID from the event context. The implementation follows good security practices by ensuring users can only access their own location data.

lib/types.ts (2)

1-1: Improved type consistency with centralized import.

Using UserWithId from the ./auth module instead of a local type alias improves consistency and reduces duplication across the application.


6-6: Consistent typing for authenticated user context.

The H3EventContext interface now uses the centralized UserWithId type, ensuring consistent typing across all authentication-related functionality including the new API endpoints.

stores/locations.ts (1)

2-5: LGTM!

The lazy fetch configuration is appropriate for a store, allowing manual control over when data is loaded. The sidebar store integration aligns well with the PR objectives for dynamic sidebar updates.

utils/define-authenticated-event-handler.ts (2)

1-9: LGTM!

The type definitions are well-structured and properly extend the H3Event type to guarantee the presence of an authenticated user in the context.


11-23: LGTM!

The authentication logic is robust with proper error handling and type safety. The 401 response is appropriate for unauthorized access attempts.

pages/dashboard/index.vue (2)

1-8: LGTM!

The script setup properly integrates with the locations store and follows Vue 3 Composition API best practices. The onMounted refresh ensures fresh data is loaded when the component initializes.


10-44: LGTM!

The template perfectly implements all requirements from issues #25 and #26:

  • Loading indicator during data fetch
  • Location cards displaying name and description
  • Empty state with clear call-to-action
  • Responsive grid layout for location cards

The conditional rendering logic is clean and user-friendly.

pages/dashboard.vue (3)

3-11: LGTM!

The store integrations are properly implemented, and the conditional refresh logic ensures location data is only fetched when needed on the dashboard root path.


45-45: LGTM!

The prop changes from to to href are consistent with the sidebar-button component API updates mentioned in the AI summary.

Also applies to: 51-51, 72-72


55-68: LGTM!

The dynamic sidebar item rendering properly implements the requirements with appropriate loading states and seamless integration with existing sidebar buttons. The skeleton loading indicator provides good UX during data fetch.

server/api/locations.post.ts (1)

7-9: LGTM!

The refactor to use defineAuthenticatedEventHandler is a clean improvement that centralizes authentication logic while maintaining all existing functionality. This enhances code consistency and maintainability across API endpoints.

Comment on lines +7 to +17
watchEffect(() => {
if (data.value) {
sidebarStore.sidebarItems = data.value?.map(location => ({
id: `location-${location.id}`,
label: location.name,
icon: "tabler:map-pin-filled",
href: `/dashboard/${location.id}`,
}));
}
sidebarStore.loading = status.value === "pending";
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Handle the case where location data becomes null or undefined.

The current logic only updates sidebar items when data.value is truthy, but doesn't clear them when data becomes null or undefined after being initially populated.

 watchEffect(() => {
-  if (data.value) {
+  if (data.value && data.value.length > 0) {
     sidebarStore.sidebarItems = data.value?.map(location => ({
       id: `location-${location.id}`,
       label: location.name,
       icon: "tabler:map-pin-filled",
       href: `/dashboard/${location.id}`,
     }));
+  } else if (data.value && data.value.length === 0) {
+    sidebarStore.sidebarItems = [];
   }
   sidebarStore.loading = status.value === "pending";
 });

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In stores/locations.ts around lines 7 to 17, the code updates
sidebarStore.sidebarItems only when data.value is truthy but does not clear
sidebarItems if data.value becomes null or undefined later. Modify the
watchEffect to explicitly set sidebarStore.sidebarItems to an empty array or
clear it when data.value is falsy, ensuring the sidebar items reflect the
current state of location data accurately.

- Update environment name in GitHub workflow to use proper capitalization
- Rename useLocationStore to useLocationsStore for consistency
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
.github/workflows/lint.yml (2)

1-2: Rename workflow for accuracy

The workflow is still called “Lint”, yet linting is now just a step of the consolidated build job. This is confusing when reading the Actions list or configuring required status checks.

Rename the file header (name:) to something that reflects its new scope, e.g. CI, Build & Lint, or similar.


10-12: Environment & runtime sanity-check

  1. The blank line at Line 10 is superfluous; trimming avoids accidental indentation mistakes.
  2. environment: Build requires a repository environment named exactly “Build”. If that environment isn’t configured, the job will stall in “Waiting for environment…”. Verify its existence or remove the key.
  3. You upgraded to Node 22.x, which is not yet the LTS release. Double-check that the project really targets this version (CI ≠ prod). If not, stay on 20.x LTS.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b10f7a2 and 323cc1b.

📒 Files selected for processing (2)
  • .github/workflows/lint.yml (1 hunks)
  • stores/locations.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • stores/locations.ts

@timDeHof timDeHof merged commit e2c92b9 into main Jul 31, 2025
7 checks passed
@timDeHof timDeHof deleted the ntl-25 branch July 31, 2025 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

As a traveler, I want to see my locations listed in the sidebar As a traveler, I want to view a list of all my saved locations
1 participant