diff --git a/components/EditProfilePage/FollowingTab.tsx b/components/EditProfilePage/FollowingTab.tsx index ef1940cf0..4eba063d5 100644 --- a/components/EditProfilePage/FollowingTab.tsx +++ b/components/EditProfilePage/FollowingTab.tsx @@ -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" @@ -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() @@ -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([])