Skip to content

Commit ec6ef16

Browse files
committed
feat: add loaders for Settings page and News Monitor page links
1 parent 11fd91a commit ec6ef16

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

apps/xen-tg-app/src/App.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
1-
import { Link } from 'react-router'
1+
import { useState } from 'react'
2+
import { useNavigate } from 'react-router'
23
import SettingsIcon from './assets/settings'
3-
import XEN_IMAGE from '/xen.png'
44
import Capabilities from './components/Capabilities'
5+
import Spinner from './components/Spinner'
56
import Wallet from './components/Wallet'
7+
import XEN_IMAGE from '/xen.png'
68

79
const App = () => {
10+
const [isWaiting, setIsWaiting] = useState(false)
11+
const navigate = useNavigate()
812
const tg = window.Telegram.WebApp
913
if (!tg.isExpanded) tg.expand()
1014

1115
return (
1216
<>
13-
<Link
14-
to="/settings"
15-
className="absolute top-5 right-4 rounded-full border border-(--color-opposite-text) bg-(--color-light-white-bg) p-2 backdrop-blur-3xl backdrop-opacity-80 dark:border-(--color-main-text)/30"
17+
<button
18+
role="link"
19+
onClick={() => {
20+
setIsWaiting(true)
21+
navigate('/settings')
22+
}}
23+
disabled={isWaiting}
24+
className="absolute top-5 right-4 h-9.5 w-9.5 rounded-full border border-(--color-opposite-text) bg-(--color-light-white-bg) p-2 backdrop-blur-3xl backdrop-opacity-80 dark:border-(--color-main-text)/30"
1625
>
17-
<SettingsIcon />
18-
</Link>
26+
{isWaiting ? (
27+
<div className="flex h-full w-full items-center justify-center">
28+
<Spinner />
29+
</div>
30+
) : (
31+
<SettingsIcon />
32+
)}
33+
</button>
1934
<div className="z-1 m-2.5 flex w-[210px] justify-center overflow-hidden rounded-full border border-(--color-opposite-text) select-none dark:border-(--color-main-text)/30">
2035
<img src={XEN_IMAGE} alt="xen-photo" className="h-full w-full" />
2136
</div>

apps/xen-tg-app/src/components/Agent.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, startTransition, useEffect, useMemo } from 'react'
1+
import { FC, startTransition, useEffect, useMemo, useState } from 'react'
22
// import UnlinkOutlineIcon from '../assets/unlink-outline'
33
import ArrowForwardIcon from '@/assets/arrow-forward'
44
import { Switch } from '@/components/ui/switch'
@@ -42,6 +42,7 @@ type TAgentProps = {
4242
}
4343

4444
const Agent: FC<TAgentProps> = ({ capabilitiy }) => {
45+
const [isWaiting, setIsWaiting] = useState(false)
4546
const navigate = useNavigate()
4647
const queryClient = useQueryClient()
4748

@@ -55,7 +56,10 @@ const Agent: FC<TAgentProps> = ({ capabilitiy }) => {
5556
const action = useMemo(() => {
5657
// ToDo: better to use capabilitiy.id?
5758
if (capabilitiy.name === 'news-monitor')
58-
return () => startTransition(() => navigate('/news-monitor'))
59+
return () => {
60+
setIsWaiting(true)
61+
startTransition(() => navigate('/news-monitor'))
62+
}
5963
}, [capabilitiy, navigate])
6064

6165
const handleChangeStatus = () =>
@@ -83,9 +87,13 @@ const Agent: FC<TAgentProps> = ({ capabilitiy }) => {
8387
<div className="group flex items-center gap-2 pt-1 pb-0.25 text-left text-[14px]/[125%] font-semibold wrap-anywhere">
8488
{capabilitiy.title ?? capabilitiy.name}
8589
{action ? (
86-
<div className="text-(--color-gray-text) transition group-hover:text-(--color-main-text)">
87-
<ArrowForwardIcon />
88-
</div>
90+
isWaiting ? (
91+
<span className="h-3 w-3 animate-spin rounded-[6px] border-2 border-(--color-opposite-text) border-b-(--color-gray-text)"></span>
92+
) : (
93+
<div className="text-(--color-gray-text) transition group-hover:text-(--color-main-text)">
94+
<ArrowForwardIcon />
95+
</div>
96+
)
8997
) : null}
9098
</div>
9199
{capabilitiy.title ? (

apps/xen-tg-app/src/main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
2-
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
2+
// import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
33
import { lazy, StrictMode, Suspense } from 'react'
44
import { createRoot } from 'react-dom/client'
55
import { createBrowserRouter, RouterProvider } from 'react-router'
@@ -67,7 +67,7 @@ createRoot(document.getElementById('root')!).render(
6767
<StrictMode>
6868
<QueryClientProvider client={queryClient}>
6969
<RouterProvider router={router} />
70-
<ReactQueryDevtools initialIsOpen={false} />
70+
{/* <ReactQueryDevtools initialIsOpen={false} /> */}
7171
</QueryClientProvider>
7272
</StrictMode>
7373
)

0 commit comments

Comments
 (0)