Skip to content

feat(profile): add preset avatar picker #246#290

Open
Diyapareta wants to merge 4 commits into
vishnukothakapu:mainfrom
Diyapareta:fix-avatar-validation
Open

feat(profile): add preset avatar picker #246#290
Diyapareta wants to merge 4 commits into
vishnukothakapu:mainfrom
Diyapareta:fix-avatar-validation

Conversation

@Diyapareta

@Diyapareta Diyapareta commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Related Issue

Closes #246

Description

This PR introduces a preset avatar picker for user profiles. Users can now choose from a collection of built-in avatars instead of only uploading a custom image.

Changes Made

  • Added a preset avatar picker modal

  • Added categorized built-in avatars:

    • Animal
    • Abstract
    • Minimal
    • Geometric
  • Added visual feedback for the currently selected avatar

  • Added backend validation to ensure only valid preset avatars can be selected

  • Added support for updating profile avatars using preset selections

  • Preserved existing avatar upload and crop functionality

  • Updated session avatar immediately after selection

Testing

  • Selected preset avatars and verified they persist after page refresh
  • Verified switching between preset avatars and uploaded avatars
  • Verified avatar removal functionality
  • Verified uploaded image and crop flow continues to work correctly
  • Tested responsive layout and avatar selection UI

Screenshots

Screenshot 2026-06-01 123330

Checklist

  • Code follows project guidelines
  • Existing functionality remains intact
  • Feature tested locally
  • No unnecessary console logs or debug code

Summary by CodeRabbit

  • New Features
    • Avatar picker modal for selecting and updating profile avatars from a curated collection of preset options
    • Preset avatars organized by category for easy browsing and selection
    • Avatar removal available from the profile header
    • Profile avatar changes sync instantly to your session
    • Avatar updates require sign-in and validate selections against approved presets
    • Upload flow includes disabled state and toast feedback during changes

@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown

@Diyapareta is attempting to deploy a commit to the vishnukothakapu's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c7afcf10-ee39-4b31-852f-42595d26585a

📥 Commits

Reviewing files that changed from the base of the PR and between b7fc2aa and 93f282c.

📒 Files selected for processing (1)
  • app/profile/ProfileHeaderCard.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/profile/ProfileHeaderCard.tsx

📝 Walkthrough

Walkthrough

Adds a preset SVG avatar library, a backend PATCH endpoint that validates and persists chosen preset avatars to the user's image field, and a frontend AvatarPickerModal integrated into ProfileHeaderCard to select, save, or remove preset avatars with session sync.

Changes

Preset Avatar Picker

Layer / File(s) Summary
Preset avatar data contract and helpers
lib/presetAvatars.ts
PresetAvatar type defines id, name, category, and src. avatarSvg() encodes SVG markup as inline data:image/svg+xml URIs. Exports presetAvatars array of categorized presets.
Backend avatar update endpoint
app/api/profile/avatar/route.ts
Adds PATCH handler: authenticates, parses JSON { avatar }, verifies the avatar string matches an exported preset src, updates user.image in the database, and returns success or 400/401 JSON errors. Also imports presetAvatars.
Avatar picker modal and profile header integration
app/profile/ProfileHeaderCard.tsx
Adds AvatarPickerModal dialog grouping presets by category, local selection state, Cancel/Save controls. ProfileHeaderCard gains pickerOpen state, openUploadPicker, handlers to PATCH selected preset or DELETE avatar (CSRF-protected), updates NextAuth session via update({ image }), and swaps inline edit controls for modal-open/remove buttons.
sequenceDiagram
  participant User
  participant ProfileHeaderCard
  participant AvatarPickerModal
  participant AvatarAPI as PATCH /api/profile/avatar
  participant Database
  participant NextAuthSession
  User->>ProfileHeaderCard: Click edit avatar
  ProfileHeaderCard->>AvatarPickerModal: Open modal
  User->>AvatarPickerModal: Select preset & Click Save
  AvatarPickerModal->>ProfileHeaderCard: onPresetSelect(selectedSrc)
  ProfileHeaderCard->>AvatarAPI: PATCH { avatar: selectedSrc } + CSRF
  AvatarAPI->>Database: Update user.image = selectedSrc
  Database-->>AvatarAPI: OK
  AvatarAPI-->>ProfileHeaderCard: { success: true }
  ProfileHeaderCard->>NextAuthSession: update({ image: selectedSrc })
  ProfileHeaderCard->>User: Close modal, show toast
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

quality:clean

Suggested reviewers

  • Anushreebasics

Poem

🐰 I nibble pixels, colors aglow,
Preset faces lined up in a row.
Click a sprite, save with a tap,
A tiny rabbit-approved profile snap.
Hooray — new avatars, ready to show!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(profile): add preset avatar picker #246' clearly summarizes the main change: adding a preset avatar picker feature to the profile component.
Linked Issues check ✅ Passed The PR successfully implements all core requirements from issue #246: preset avatar picker modal with categorized avatars, single-click selection, visual feedback for current selection, preserved upload/crop functionality, and session synchronization.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the preset avatar picker feature from issue #246; no unrelated modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 `@app/profile/ProfileHeaderCard.tsx`:
- Around line 290-291: The local selectedAvatar state in ProfileHeaderCard is
initialized from currentAvatar but never re-syncs, causing stale highlights in
AvatarPickerModal; add a useEffect that listens to the boolean that controls
AvatarPickerModal's open prop (the modal's "open" state) and resets
setSelectedAvatar(currentAvatar) whenever the modal opens (open transitions to
true) or whenever currentAvatar changes while the modal is open so the picker
selection always reflects the real current avatar.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e71c117-bbad-4299-a4d4-831991b5a98e

📥 Commits

Reviewing files that changed from the base of the PR and between 1da4dc6 and 57a7451.

📒 Files selected for processing (3)
  • app/api/profile/avatar/route.ts
  • app/profile/ProfileHeaderCard.tsx
  • lib/presetAvatars.ts

Comment thread app/profile/ProfileHeaderCard.tsx
@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
linkid Ready Ready Preview, Comment Jun 1, 2026 1:20pm

@vishnukothakapu

Copy link
Copy Markdown
Owner

Hi @Diyapareta,

Thanks for the PR, Could you please address the CodeRabbit review comment above regarding the "selectedAvatar" state not re-syncing with "currentAvatar"? Since the modal remains mounted, the current implementation may lead to stale selection states when reopening the picker or after avatar updates.

Please make the necessary changes, resolve the review comment, and mark it as resolved once completed.

Thanks!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 `@app/profile/ProfileHeaderCard.tsx`:
- Around line 292-296: The effect in ProfileHeaderCard that calls
setSelectedAvatar(currentAvatar) inside useEffect causes the
react-hooks/set-state-in-effect lint error; remove that state update and instead
either (A) force a remount of the picker/modal subtree by giving the inner
picker/dialog content a key derived from currentAvatar (keep the outer Dialog
component mounted so close animation still runs) or (B) stop syncing state and
derive the shown avatar value directly during render from currentAvatar when
open is true; locate the useEffect, setSelectedAvatar, currentAvatar, open and
Dialog/picker components and implement one of these fixes so no state is set
inside the effect.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cff82789-c856-4fb7-81e0-40c7eb34ce7f

📥 Commits

Reviewing files that changed from the base of the PR and between 57a7451 and b7fc2aa.

📒 Files selected for processing (2)
  • app/api/profile/avatar/route.ts
  • app/profile/ProfileHeaderCard.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/api/profile/avatar/route.ts

Comment thread app/profile/ProfileHeaderCard.tsx Outdated

@Anushreebasics Anushreebasics left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for PR!
Pls resolve this issues:

  • [route.ts]: Accept a preset id (e.g. "fox") instead of the full [src](; lookup the canonical [src] server-side and update DB. Adds robustness and avoids comparing long data-URIs.

  • [ProfileHeaderCard.tsx]: Send the preset id on save (not the [src]), and use the project absolute import ([@/lib/presetAvatars]) for consistency.

  • [presetAvatars.ts]: Export a PresetAvatar type and keep the array typed as PresetAvatar[]; consider serving presets as static assets for caching instead of large data-URIs.

  • Add unit tests for the new [PATCH /api/profile/avatar] endpoint (happy path, invalid id, unauthenticated).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Add preset avatar picker for profile customization

3 participants