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

Skip to content

Commit c74086d

Browse files
committed
Add global loading indicator when fetching
1 parent 535a8af commit c74086d

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/components/AppNavBar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NavBar, Button, Menu, Avatar } from '@/ui'
22
import { signIn, signOut, useSession } from 'next-auth/client'
3-
import { Logo, DonateModal } from '@/components'
3+
import { Logo, DonateModal, GlobalLoadingIndicator } from '@/components'
44
import Link from 'next/link'
55
import { useRouter } from 'next/router'
66
import { User } from 'src/pages/members'
@@ -72,6 +72,7 @@ export default function AppNavBar() {
7272
}
7373
rightDesktopItems={
7474
<>
75+
<GlobalLoadingIndicator />
7576
<DonateModal
7677
isOpen={isDonateModalOpen}
7778
setIsOpen={setIsDonateModalOpen}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useIsFetching } from 'react-query'
2+
3+
export default function GlobalLoadingIndicator() {
4+
const isFetching = useIsFetching()
5+
6+
if (!isFetching) {
7+
return null
8+
}
9+
10+
return (
11+
<svg
12+
className="animate-spin -ml-1 mr-3 h-5 w-5 text-brand-600"
13+
xmlns="http://www.w3.org/2000/svg"
14+
fill="none"
15+
viewBox="0 0 24 24"
16+
>
17+
<circle
18+
className="opacity-25"
19+
cx="12"
20+
cy="12"
21+
r="10"
22+
stroke="currentColor"
23+
strokeWidth="4"
24+
></circle>
25+
<path
26+
className="opacity-75"
27+
fill="currentColor"
28+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
29+
></path>
30+
</svg>
31+
)
32+
}

src/components/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export { default as Hero } from './Hero'
1313
export * from './modal'
1414
export { Pre } from './Code'
1515
export { useLikes } from './useLikes'
16+
export { default as GlobalLoadingIndicator } from './GlobalLoadingIndicator'

0 commit comments

Comments
 (0)