-
-
Notifications
You must be signed in to change notification settings - Fork 141
Show Users Their Own Follower Counts #1912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Mephistic
merged 11 commits into
codeforboston:main
from
jicruz96:edit-profile-followers-tab
Aug 26, 2025
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c8f9157
Create getFollowers firebase function
jicruz96 4a2d877
add Followers tab to Edit Profile page
jicruz96 5c48c56
revert inclusion of `ConfirmFollowModal`
jicruz96 e5c00b3
minor edits
jicruz96 d5b6b26
add "profile" to getStaticProps translation keys
jicruz96 3fb91be
refactor: improve FollowerCard component structure and loading state …
jicruz96 c5b8d07
undo changes to unused StyledTabNav
jicruz96 fabb537
Merge branch 'main' into edit-profile-followers-tab
jicruz96 0ec76fc
PR review fixes
jicruz96 361cc0a
return followerIds only in getFollowers
jicruz96 ed0e705
Merge branch 'main' into edit-profile-followers-tab
jicruz96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { functions } from "components/firebase" | ||
import { httpsCallable } from "firebase/functions" | ||
import type { | ||
GetFollowersRequest, | ||
GetFollowersResponse | ||
} from "functions/src/subscriptions/getFollowers" | ||
import { useTranslation } from "next-i18next" | ||
import { Dispatch, ReactNode, SetStateAction, useEffect, useState } from "react" | ||
import { useAuth } from "../auth" | ||
import { usePublicProfile } from "components/db" | ||
import { Internal } from "components/links" | ||
import { FollowUserButton } from "components/shared/FollowButton" | ||
import React from "react" | ||
import { Col, Row, Spinner, Stack } from "../bootstrap" | ||
import { TitledSectionCard } from "../shared" | ||
import { OrgIconSmall } from "./StyledEditProfileComponents" | ||
|
||
export const FollowersTab = ({ | ||
className, | ||
setFollowerCount | ||
}: { | ||
className?: string | ||
setFollowerCount: Dispatch<SetStateAction<number | null>> | ||
}) => { | ||
const uid = useAuth().user?.uid | ||
const [followerIds, setFollowerIds] = useState<string[]>([]) | ||
const { t } = useTranslation("editProfile") | ||
|
||
useEffect(() => { | ||
const fetchFollowers = async (uid: string) => { | ||
try { | ||
const { data: followerIds } = await httpsCallable< | ||
GetFollowersRequest, | ||
GetFollowersResponse | ||
>( | ||
functions, | ||
"getFollowers" | ||
)({ uid }) | ||
setFollowerIds(followerIds) | ||
setFollowerCount(followerIds.length) | ||
} catch (err) { | ||
console.error("Error fetching followerIds", err) | ||
return | ||
} | ||
} | ||
if (uid) fetchFollowers(uid) | ||
}, [uid]) | ||
return ( | ||
<TitledSectionCard className={className}> | ||
<div className={`mx-4 mt-3 d-flex flex-column gap-3`}> | ||
<Stack> | ||
<h2>{t("follow.your_followers")}</h2> | ||
<p className="mt-0 text-muted"> | ||
{t("follow.follower_info_disclaimer")} | ||
</p> | ||
<div className="mt-3"> | ||
{followerIds.map((profileId, i) => ( | ||
<FollowerCard key={i} profileId={profileId} /> | ||
))} | ||
</div> | ||
</Stack> | ||
</div> | ||
</TitledSectionCard> | ||
) | ||
} | ||
|
||
const FollowerCard = ({ profileId }: { profileId: string }) => { | ||
const { result: profile, loading } = usePublicProfile(profileId) | ||
const { t } = useTranslation("profile") | ||
if (loading) { | ||
return ( | ||
<FollowerCardWrapper> | ||
<Spinner animation="border" className="mx-auto" /> | ||
</FollowerCardWrapper> | ||
) | ||
} | ||
const { fullName, profileImage, public: isPublic } = profile || {} | ||
const displayName = isPublic && fullName ? fullName : t("anonymousUser") | ||
return ( | ||
<FollowerCardWrapper> | ||
<Col className="d-flex align-items-center flex-grow-1 p-0 text-start"> | ||
<OrgIconSmall | ||
className="mr-4 mt-0 mb-0 ms-0" | ||
profileImage={profileImage} | ||
/> | ||
{isPublic ? ( | ||
<Internal href={`/profile?id=${profileId}`}>{displayName}</Internal> | ||
) : ( | ||
<span>{displayName}</span> | ||
)} | ||
</Col> | ||
{isPublic ? ( | ||
<Col | ||
xs="auto" | ||
className="d-flex justify-content-end ms-auto text-end p-0" | ||
> | ||
<FollowUserButton profileId={profileId} /> | ||
</Col> | ||
) : ( | ||
<></> | ||
)} | ||
</FollowerCardWrapper> | ||
) | ||
} | ||
|
||
const FollowerCardWrapper = ({ children }: { children: ReactNode }) => ( | ||
<div className={`fs-3 lh-lg`}> | ||
<Row className="align-items-center justify-content-between g-0 w-100"> | ||
{children} | ||
</Row> | ||
<hr className={`mt-3`} /> | ||
</div> | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { getFirestore } from "firebase-admin/firestore" | ||
import * as functions from "firebase-functions" | ||
|
||
export interface GetFollowersRequest { | ||
uid: string | ||
} | ||
export type GetFollowersResponse = string[] | ||
|
||
export const getFollowers = functions.https.onCall( | ||
async ({ uid }: GetFollowersRequest, context) => { | ||
if (!context.auth) { | ||
jicruz96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new functions.https.HttpsError( | ||
"failed-precondition", | ||
"The function must be called while authenticated." | ||
) | ||
} | ||
|
||
functions.logger.log( | ||
`[getFollowers] Finding followers for user UID: ${uid}` | ||
) | ||
|
||
return await getFirestore() | ||
.collectionGroup("activeTopicSubscriptions") | ||
.where("userLookup.profileId", "==", uid) | ||
jicruz96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.get() | ||
.then(snapshot => { | ||
const followers = new Set<string>() | ||
snapshot.forEach(doc => { | ||
const followerUid = doc.ref.parent.parent?.id | ||
jicruz96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (followerUid && followerUid !== uid) followers.add(followerUid) | ||
}) | ||
functions.logger.log( | ||
`[getFollowers] Found ${followers.size} followers for user UID: ${uid}` | ||
) | ||
return Array.from(followers) | ||
jicruz96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
.catch(error => { | ||
functions.logger.error("[getFollowers] Caught error:", error) | ||
throw new functions.https.HttpsError( | ||
"internal", | ||
"Failed to retrieve followers and reciprocal status.", | ||
error | ||
) | ||
}) | ||
} | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.