Skip to content

Commit

Permalink
Merge pull request #1675 from kiminkim724/improve-unfollow-button
Browse files Browse the repository at this point in the history
Used query instead of function in Firebase
  • Loading branch information
mertbagt authored Jan 15, 2025
2 parents 0690b52 + d3ad7b4 commit df1cdd7
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions components/EditProfilePage/FollowingTab.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { collection, getDocs, query, where } from "firebase/firestore"
import { getFunctions, httpsCallable } from "firebase/functions"
import { getFunctions } from "firebase/functions"
import { useTranslation } from "next-i18next"
import { useCallback, useEffect, useMemo, useState } from "react"
import { useAuth } from "../auth"
Expand All @@ -9,11 +9,7 @@ import { TitledSectionCard } from "../shared"
import UnfollowItem, { UnfollowModalConfig } from "./UnfollowModal"
import { FollowedItem } from "./FollowingTabComponents"
import { BillElement, UserElement } from "./FollowingTabComponents"

const functions = getFunctions()

const unfollowBillFunction = httpsCallable(functions, "unfollowBill")
const unfollowUserFunction = httpsCallable(functions, "unfollowUser")
import { deleteItem } from "components/shared/FollowingQueries"

export function FollowingTab({ className }: { className?: string }) {
const { user } = useAuth()
Expand Down Expand Up @@ -97,28 +93,10 @@ export function FollowingTab({ className }: { className?: string }) {
if (unfollow === null) {
return
}
// rest of what was inside the original if statement
if (unfollow.type == "bill") {
const billLookup = { billId: unfollow.typeId, court: unfollow.court }
try {
const response = await unfollowBillFunction({
billLookup
})
console.log(response.data) // This should print { status: 'success', message: 'Subscription removed' }
} catch (error: any) {
console.log(error.message)
}
} else {
const userLookup = {
profileId: unfollow.typeId,
fullName: unfollow.userName
}
try {
const response = await unfollowUserFunction({ userLookup: userLookup })
console.log(response.data) // This should print { status: 'success', message: 'Subscription removed' }
} catch (error: any) {
console.log(error.message)
}
try {
deleteItem({ uid, unfollowItem: unfollow })
} catch (error: any) {
console.log(error.message)
}

setBillsFollowing([])
Expand Down

0 comments on commit df1cdd7

Please sign in to comment.