Skip to content

West Midlands | 26 March SDC | Iswat Bello | Sprint 1 | Purple Forest/New Feature/Unfollow#227

Open
Iswanna wants to merge 2 commits into
CodeYourFuture:mainfrom
Iswanna:new-feature/unfollow
Open

West Midlands | 26 March SDC | Iswat Bello | Sprint 1 | Purple Forest/New Feature/Unfollow#227
Iswanna wants to merge 2 commits into
CodeYourFuture:mainfrom
Iswanna:new-feature/unfollow

Conversation

@Iswanna

@Iswanna Iswanna commented Jun 27, 2026

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

This PR enables users to un-follow accounts they are no longer interested in. This required a "Reverse Path" implementation in the database and a dynamic UI update on the profile page.

Key Changes:

  • Backend Data: Created the unfollow function in data/follows.py using SQL DELETE logic with parameterized queries to prevent SQL injection.
  • Backend API: Added a POST /unfollow/<target_username> endpoint. This matches the existing Frontend contract while maintaining security via @jwt_required.
  • Frontend UI:
    • Updated the createProfile component to keep the follow button visible when is_following is true.
    • Implemented a text toggle to switch the button label between "Follow" and "Un-follow" based on user state.
    • Modified the handleFollow event handler to act as a "Smart Switch," calling either the follow or unfollow API depending on the current button state.

Iswanna added 2 commits June 27, 2026 01:08
- Added `unfollow` function to the data layer with SQL DELETE logic.
- Created and registered the `/unfollow/<username>` endpoint in the backend.
- Updated the profile UI to toggle the follow button visibility and text.
- Modified the click handler to conditionally call follow or unfollow APIs.
Added a detailed project log documenting the full-stack
implementation of the unfollow functionality. The file records
the logic for SQL deletions, backend route synchronization,
and frontend UI toggle states.
@Iswanna Iswanna added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Legacy-Code The name of the module. labels Jun 27, 2026
@nedssoft nedssoft added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jul 1, 2026

@nedssoft nedssoft left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Iswat — this is a really clean, well-executed feature. What stands out most is how neatly your do_unfollow mirrors the existing do_follow: the same get_user lookup, the same None → 404 guard, @jwt_required on the door, and a properly parameterized DELETE targeting both follower and followee so you only remove the one relationship. That instinct to match the patterns already in the codebase is exactly what makes legacy work go smoothly. Your CHANGES-MADE.md write-up is a pleasure to read, too.

I've left one entirely optional question inline — a design thing to mull over, not a fix. You've met the task cleanly, so I'm marking this Complete. Lovely work. 🎉

if (!username) return;

await apiService.followUser(username);
if (button.textContent === "Un-follow") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your "Smart Switch" works, and I like that you found a single handler for both directions. One thing to chew on — no change needed here, just a thought for future you: the handler decides which API to call by reading the button's visible text, button.textContent === "Un-follow". That quietly ties your logic to whatever the label happens to say. What do you think would happen to this if if someone later renamed the button to "Unfollow" (no hyphen), translated the page, or dropped an icon inside the button?

You already hold the real answer to "am I following this person?" in your data — profileData.is_following. Is there a way you could branch on that state instead of the on-screen wording? Something to explore when you're curious, not to change for this PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback. In the future, I'll try to use the data state (like a data-following attribute) to drive the logic so the frontend logic doesn't have to rely on what the UI is showing. Thanks for the suggestion.

@nedssoft nedssoft added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jul 1, 2026
@Iswanna

Iswanna commented Jul 4, 2026

Copy link
Copy Markdown
Author

Iswat — this is a really clean, well-executed feature. What stands out most is how neatly your do_unfollow mirrors the existing do_follow: the same get_user lookup, the same None → 404 guard, @jwt_required on the door, and a properly parameterized DELETE targeting both follower and followee so you only remove the one relationship. That instinct to match the patterns already in the codebase is exactly what makes legacy work go smoothly. Your CHANGES-MADE.md write-up is a pleasure to read, too.

I've left one entirely optional question inline — a design thing to mull over, not a fix. You've met the task cleanly, so I'm marking this Complete. Lovely work. 🎉

Thank you so much @nedssoft, for the review and for marking the task as complete! I made a conscious effort to mirror the existing do_follow pattern to ensure the codebase stays consistent and easy to maintain.

I will read the inline question to think about the suggested edge case.

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

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Legacy-Code The name of the module. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants