Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions components/Newsfeed/Newsfeed.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ErrorPage from "next/error"
import { Timestamp } from "firebase/firestore"
import { useTranslation } from "next-i18next"
import { useEffect, useState } from "react"
import { useEffect, useMemo, useState } from "react"
import { Frequency, useAuth } from "../auth"
import { Col, Row, Spinner } from "../bootstrap"
import { Profile, useProfile, usePublicProfile } from "../db"
Expand Down Expand Up @@ -30,17 +30,15 @@ export default function Newsfeed() {
const [isShowingBills, setIsShowingBills] = useState<boolean>(true)

const [allResults, setAllResults] = useState<Notifications>([])
const [filteredResults, setFilteredResults] = useState<Notifications>([])
const [notificationsLoading, setNotificationsLoading] = useState(true)

useEffect(() => {
const results = allResults.filter(result => {
if (isShowingOrgs && result.type == `testimony`) return true
if (isShowingBills && result.type == `bill`) return true
const filteredResults = useMemo(() => {
return allResults.filter(result => {
if (isShowingOrgs && result.type === "testimony") return true
if (isShowingBills && result.type === "bill") return true
return false
})

setFilteredResults(results)
}, [isShowingOrgs, isShowingBills, allResults])
}, [allResults, isShowingOrgs, isShowingBills])

const onOrgFilterChange = (isShowing: boolean) => {
setIsShowingOrgs(isShowing)
Expand All @@ -56,12 +54,14 @@ export default function Newsfeed() {
if (uid) {
const notifications = await notificationQuery(uid)
setAllResults(notifications)
setFilteredResults(notifications)
}
} catch (error) {
console.error("Error fetching notifications: " + error)
} finally {
setNotificationsLoading(false)
}
}
setNotificationsLoading(true)
fetchNotifications()
}, [uid])

Expand Down Expand Up @@ -190,7 +190,7 @@ export default function Newsfeed() {

return (
<>
{result.loading && uid ? (
{(uid && result.loading) || notificationsLoading ? (
<Row>
<Spinner animation="border" className="mx-auto" />
</Row>
Expand Down
Loading