Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd18b3f

Browse files
committed
Remove unnecssary loading state in home page feed
1 parent 613aa3b commit bd18b3f

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

src/components/HomePageFeed.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
import { User } from 'src/pages/members'
2626
import AppNavBar from './AppNavBar'
2727
import AppFooter from './AppFooter'
28-
import { useRouter } from 'next/router'
2928
import useFollowUser from './profile/useFollowUser'
3029

3130
type LikeData = {
@@ -267,10 +266,7 @@ export default function HomePageFeed({
267266
}
268267

269268
function HomePageSideNavBar() {
270-
const [session, loading] = useSession()
271-
if (loading) {
272-
return <p>loading...</p>
273-
}
269+
const [session] = useSession()
274270
return (
275271
<>
276272
<nav
@@ -391,18 +387,13 @@ function FollowButton({ user }: { user: User }) {
391387
}
392388

393389
function HomePageAside({ updates }: { updates: HomePageFeedUpdateType[] }) {
394-
const router = useRouter()
395-
const [session, loading] = useSession()
390+
const [session] = useSession()
396391
const { isLoading, isError, data: response } = useQuery(
397392
'api/fauna/who-to-follow',
398393
() => {
399394
return fetch(`/api/fauna/who-to-follow`).then((res) => res.json())
400395
}
401396
)
402-
if (loading) {
403-
return <p>loading...</p>
404-
}
405-
console.log({ response })
406397

407398
return (
408399
<>

src/pages/index.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type HomePageFeedUpdateType = {
2525
}
2626

2727
export default function Home() {
28-
const [session, loading] = useSession()
28+
const [session] = useSession()
2929

3030
const { isLoading, isError, data } = useQuery('/api/fauna/all-updates', () =>
3131
fetch(`/api/fauna/all-updates`).then((res) => {
@@ -49,22 +49,18 @@ export default function Home() {
4949
})
5050
})
5151

52-
if (loading || isLoading || isGoalLoading) {
53-
return <p>loading...</p>
54-
}
55-
5652
if (isError || isGoalError) {
5753
return <p>Something went wrong!!!</p>
5854
}
5955

60-
const updates = data.updates.data
61-
6256
return (
6357
<>
6458
<HomePageFeed
65-
updates={updates}
66-
showGoal={Boolean(session && goalData?.goal)}
67-
goal={goalData.goal}
59+
updates={isLoading ? [] : data.updates.data}
60+
showGoal={Boolean(
61+
!isGoalLoading && !isGoalError && session && goalData?.goal
62+
)}
63+
goal={goalData?.goal}
6864
/>
6965
</>
7066
)

0 commit comments

Comments
 (0)