Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
414a9ed5
Commit
414a9ed5
authored
Jan 16, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save indexing status in cookie
parent
6e48647c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
3 deletions
+20
-3
cookies.ts
lib/cookies.ts
+1
-0
IndexingAlert.tsx
ui/home/IndexingAlert.tsx
+19
-3
No files found.
lib/cookies.ts
View file @
414a9ed5
...
...
@@ -7,6 +7,7 @@ export enum NAMES {
API_TOKEN
=
'
_explorer_key
'
,
TXS_SORT
=
'
txs_sort
'
,
COLOR_MODE
=
'
chakra-ui-color-mode
'
,
INDEXING_ALERT
=
'
indexing_alert
'
,
}
export
function
get
(
name
?:
NAMES
|
undefined
|
null
,
serverCookie
?:
string
)
{
...
...
ui/home/IndexingAlert.tsx
View file @
414a9ed5
import
{
Alert
,
AlertIcon
,
AlertTitle
,
chakra
}
from
'
@chakra-ui/react
'
;
import
{
Alert
,
AlertIcon
,
AlertTitle
,
chakra
,
Skeleton
}
from
'
@chakra-ui/react
'
;
import
{
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
React
from
'
react
'
;
...
...
@@ -6,6 +6,8 @@ import type { SocketMessage } from 'lib/socket/types';
import
type
{
IndexingStatus
}
from
'
types/api/indexingStatus
'
;
import
useApiQuery
,
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
{
useAppContext
}
from
'
lib/appContext
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
{
nbsp
,
ndash
}
from
'
lib/html-entities
'
;
import
useSocketChannel
from
'
lib/socket/useSocketChannel
'
;
...
...
@@ -14,7 +16,17 @@ import useSocketMessage from 'lib/socket/useSocketMessage';
const
IndexingAlert
=
({
className
}:
{
className
?:
string
})
=>
{
const
isMobile
=
useIsMobile
();
const
{
data
}
=
useApiQuery
(
'
homepage_indexing_status
'
);
const
appProps
=
useAppContext
();
const
cookiesString
=
appProps
.
cookies
;
const
[
hasAlertCookie
]
=
React
.
useState
(
cookies
.
get
(
cookies
.
NAMES
.
INDEXING_ALERT
,
cookiesString
)
===
'
true
'
);
const
{
data
,
isError
,
isLoading
}
=
useApiQuery
(
'
homepage_indexing_status
'
);
React
.
useEffect
(()
=>
{
if
(
!
isLoading
&&
!
isError
)
{
cookies
.
set
(
cookies
.
NAMES
.
INDEXING_ALERT
,
data
.
finished_indexing
&&
data
.
finished_indexing_blocks
?
'
false
'
:
'
true
'
);
}
},
[
data
,
isError
,
isLoading
]);
const
queryClient
=
useQueryClient
();
...
...
@@ -62,10 +74,14 @@ const IndexingAlert = ({ className }: { className?: string }) => {
handler
:
handleIntermalTxsIndexStatus
,
});
if
(
!
data
)
{
if
(
isError
)
{
return
null
;
}
if
(
isLoading
)
{
return
hasAlertCookie
?
<
Skeleton
h=
{
{
base
:
'
96px
'
,
lg
:
'
48px
'
}
}
mb=
{
6
}
w=
"100%"
className=
{
className
}
/>
:
null
;
}
let
content
;
if
(
data
.
finished_indexing_blocks
===
false
)
{
content
=
`
${
data
.
indexed_blocks_ratio
&&
`
${
(
Number
(
data
.
indexed_blocks_ratio
)
*
100
).
toFixed
()
}
% Blocks Indexed
${
nbsp
}${
ndash
}
`
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment