Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Block Explorer UI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
Block Explorer UI
Commits
4cbd6a63
Commit
4cbd6a63
authored
3 months ago
by
Lukas
Browse files
Options
Downloads
Patches
Plain Diff
Create context for searches
parent
efc64642
No related branches found
Branches containing commit
No related tags found
1 merge request
!494
Lbudginas/#392 part1 reduce searches component
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
contexts/SearchesContext.tsx
+149
-0
149 additions, 0 deletions
contexts/SearchesContext.tsx
with
149 additions
and
0 deletions
contexts/SearchesContext.tsx
0 → 100644
+
149
−
0
View file @
4cbd6a63
import
React
,
{
createContext
,
SetStateAction
,
useContext
,
useState
,
Dispatch
,
}
from
"
react
"
;
import
Explorer
from
"
@/types/Explorer
"
;
import
useSearchRanges
from
"
@/hooks/common/useSearchRanges
"
;
export
type
SearchKey
=
"
block
"
|
"
account
"
|
"
comment
"
|
"
comment-permlink
"
;
type
CommentType
=
"
all
"
|
"
post
"
|
"
comment
"
;
export
interface
SearchesContextType
{
previousCommentSearchProps
:
Explorer
.
CommentSearchProps
|
undefined
;
setPreviousCommentSearchProps
:
Dispatch
<
SetStateAction
<
Explorer
.
CommentSearchProps
|
undefined
>
>
;
previousAccountOperationsSearchProps
:
|
Explorer
.
AccountSearchOperationsProps
|
undefined
;
setPreviousAccountOperationsSearchProps
:
Dispatch
<
SetStateAction
<
Explorer
.
AccountSearchOperationsProps
|
undefined
>
>
;
commentPaginationPage
:
number
;
setCommentPaginationPage
:
Dispatch
<
SetStateAction
<
number
>>
;
accountOperationsPage
:
number
|
undefined
;
setAccountOperationsPage
:
Dispatch
<
SetStateAction
<
number
|
undefined
>>
;
lastSearchKey
:
SearchKey
|
undefined
;
setLastSearchKey
:
Dispatch
<
SetStateAction
<
SearchKey
|
undefined
>>
;
blockSearchProps
:
Explorer
.
BlockSearchProps
|
undefined
;
setBlockSearchProps
:
Dispatch
<
SetStateAction
<
Explorer
.
BlockSearchProps
|
undefined
>
>
;
commentSearchProps
:
Explorer
.
CommentSearchProps
|
undefined
;
setCommentSearchProps
:
Dispatch
<
SetStateAction
<
Explorer
.
CommentSearchProps
|
undefined
>
>
;
permlinkSearchProps
:
Explorer
.
PermlinkSearchProps
|
undefined
;
setPermlinkSearchProps
:
Dispatch
<
SetStateAction
<
Explorer
.
PermlinkSearchProps
|
undefined
>
>
;
accountOperationsSearchProps
:
|
Explorer
.
AccountSearchOperationsProps
|
undefined
;
setAccountOperationsSearchProps
:
Dispatch
<
SetStateAction
<
Explorer
.
AccountSearchOperationsProps
|
undefined
>
>
;
commentType
:
CommentType
|
undefined
;
setCommentType
:
Dispatch
<
SetStateAction
<
CommentType
|
undefined
>>
;
searchRanges
:
any
;
}
export
const
SearchesContext
=
createContext
<
SearchesContextType
|
undefined
>
(
undefined
);
export
const
useSearchesContext
=
()
=>
{
const
context
=
useContext
(
SearchesContext
);
if
(
context
===
undefined
)
{
throw
new
Error
(
"
useSearchesContext must be used inside it`s context
"
);
}
return
context
;
};
export
const
SearchesContextProvider
:
React
.
FC
<
{
children
:
React
.
ReactNode
;
}
>
=
({
children
})
=>
{
const
[
previousCommentSearchProps
,
setPreviousCommentSearchProps
]
=
useState
<
Explorer
.
CommentSearchProps
|
undefined
>
(
undefined
);
const
[
previousAccountOperationsSearchProps
,
setPreviousAccountOperationsSearchProps
,
]
=
useState
<
Explorer
.
AccountSearchOperationsProps
|
undefined
>
(
undefined
);
const
[
commentPaginationPage
,
setCommentPaginationPage
]
=
useState
<
number
>
(
1
);
const
[
accountOperationsPage
,
setAccountOperationsPage
]
=
useState
<
number
|
undefined
>
(
undefined
);
const
[
lastSearchKey
,
setLastSearchKey
]
=
useState
<
SearchKey
|
undefined
>
(
undefined
);
const
[
blockSearchProps
,
setBlockSearchProps
]
=
useState
<
Explorer
.
BlockSearchProps
|
undefined
>
(
undefined
);
const
[
commentSearchProps
,
setCommentSearchProps
]
=
useState
<
Explorer
.
CommentSearchProps
|
undefined
>
(
undefined
);
const
[
permlinkSearchProps
,
setPermlinkSearchProps
]
=
useState
<
Explorer
.
PermlinkSearchProps
|
undefined
>
(
undefined
);
const
[
accountOperationsSearchProps
,
setAccountOperationsSearchProps
]
=
useState
<
Explorer
.
AccountSearchOperationsProps
|
undefined
>
(
undefined
);
const
[
commentType
,
setCommentType
]
=
useState
<
CommentType
|
undefined
>
(
undefined
);
const
searchRanges
=
useSearchRanges
(
"
lastBlocks
"
);
return
(
<
SearchesContext
.
Provider
value
=
{
{
previousCommentSearchProps
,
setPreviousCommentSearchProps
,
previousAccountOperationsSearchProps
,
setPreviousAccountOperationsSearchProps
,
commentPaginationPage
,
setCommentPaginationPage
,
accountOperationsPage
,
setAccountOperationsPage
,
lastSearchKey
,
setLastSearchKey
,
blockSearchProps
,
setBlockSearchProps
,
commentSearchProps
,
setCommentSearchProps
,
permlinkSearchProps
,
setPermlinkSearchProps
,
accountOperationsSearchProps
,
setAccountOperationsSearchProps
,
commentType
,
setCommentType
,
searchRanges
,
}
}
>
{
children
}
</
SearchesContext
.
Provider
>
);
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment