Skip to content
GitLab
Explore
Sign in
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
b2d24c23
Commit
b2d24c23
authored
4 months ago
by
Lukas
Browse files
Options
Downloads
Patches
Plain Diff
Update comments page
parent
0c968705
No related branches found
No related tags found
1 merge request
!499
#392_part2_simplify_URL_route_build
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pages/comments/[[...accountName]].tsx
+26
-109
26 additions, 109 deletions
pages/comments/[[...accountName]].tsx
types/Explorer.ts
+1
-1
1 addition, 1 deletion
types/Explorer.ts
with
27 additions
and
110 deletions
pages/comments/[[...accountName]].tsx
+
26
−
109
View file @
b2d24c23
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
React
,
{
useEffect
}
from
"
react
"
;
import
{
config
}
from
"
@/Config
"
;
import
Hive
from
"
@/types/Hive
"
;
import
Explorer
from
"
@/types/Explorer
"
;
import
{
formatAccountName
}
from
"
@/utils/StringUtils
"
;
import
CommentsSearch
from
"
@/components/home/searches/CommentsSearch
"
;
import
{
Card
,
CardContent
}
from
"
@/components/ui/card
"
;
import
CommentSearchResults
from
"
@/components/home/searches/searchesResults/CommentSearchResults
"
;
import
{
useRouter
}
from
"
next/router
"
;
import
{
useSearchesContext
}
from
"
@/contexts/SearchesContext
"
;
import
{
trimAccountName
}
from
"
@/utils/StringUtils
"
;
import
{
convertBooleanArrayToIds
,
convertCommentsOperationResultToTableOperations
,
parseUrlFlagsIntoBooleanArray
,
}
from
"
@/lib/utils
"
;
import
useCommentSearch
from
"
@/hooks/api/common/useCommentSearch
"
;
import
useOperationsFormatter
from
"
@/hooks/common/useOperationsFormatter
"
;
import
useURLParams
from
"
@/hooks/common/useURLParams
"
;
import
CustomPagination
from
"
@/components/CustomPagination
"
;
import
JumpToPage
from
"
@/components/JumpToPage
"
;
import
CommentsSearch
from
"
@/components/home/searches/CommentsSearch
"
;
import
OperationsTable
from
"
@/components/OperationsTable
"
;
import
{
Card
,
CardContent
}
from
"
@/components/ui/card
"
;
const
defaultSearchParams
:
Explorer
.
CommentSearchParams
=
{
accountName
:
""
,
permlink
:
""
,
fromBlock
:
undefined
,
toBlock
:
undefined
,
startDate
:
undefined
,
endDate
:
undefined
,
lastBlocks
:
undefined
,
lastTime
:
undefined
,
timeUnit
:
"
days
"
,
rangeSelectKey
:
"
none
"
,
page
:
1
,
filters
:
undefined
,
};
import
Explorer
from
"
@/types/Explorer
"
;
import
{
ParsedUrlQuery
}
from
"
querystring
"
;
const
Comments
:
React
.
FC
=
()
=>
{
const
[
initialSearch
,
setInitialSearch
]
=
useState
(
false
);
const
[
commentSearchProps
,
setCommentSearchProps
]
=
useState
<
Explorer
.
CommentSearchProps
|
undefined
>
(
undefined
);
const
[
previousCommentSearchProps
,
setPreviousCommentSearchProps
]
=
useState
<
Explorer
.
CommentSearchProps
|
undefined
>
(
undefined
);
const
router
=
useRouter
();
const
commentSearch
=
useCommentSearch
(
formatSearchProps
(
commentSearchProps
));
const
{
paramsState
,
setParams
}
=
useURLParams
(
defaultSearchParams
,
[
"
accountName
"
,
"
permlink
"
,
]);
const
{
commentSearchProps
,
const
formattedOperations
=
useOperationsFormatter
(
commentSearch
?.
commentSearchData
)
as
Hive
.
CommentOperationResponse
;
setCommentSearchProps
,
}
=
useSearchesContext
();
const
s
tar
tCommentSearch
=
async
(
props
:
Explorer
.
CommentSearchParams
)
=>
{
const
s
e
tCommentSearch
PropsFromUrl
=
async
(
props
:
ParsedUrlQuery
)
=>
{
if
(
!!
props
.
accountName
)
{
const
searchProps
=
{
...
(
props
as
Explorer
.
CommentSearchProps
)
,
...
props
,
operationTypes
:
props
.
filters
?
convertBooleanArrayToIds
(
props
.
filters
)
?
convertBooleanArrayToIds
(
parseUrlFlagsIntoBooleanArray
(
props
.
filters
as
string
)
)
:
undefined
,
accountName
:
trimAccountName
(
router
.
query
.
accountName
?.[
0
]
as
string
),
permlink
:
router
.
query
.
permlink
as
string
,
};
setCommentSearchProps
(
searchProps
);
setPreviousCommentSearchProps
(
searchProps
);
setParams
({
...
paramsState
,
...
props
});
setInitialSearch
(
true
);
}
};
function
formatSearchProps
(
props
?:
Explorer
.
CommentSearchProps
)
{
if
(
props
)
{
if
(
Array
.
isArray
(
props
.
accountName
))
{
props
.
accountName
=
formatAccountName
(
props
.
accountName
[
0
]);
}
else
{
props
.
accountName
=
formatAccountName
(
props
.
accountName
);
}
}
return
props
;
}
const
changeCommentSearchPagination
=
(
newPageNum
:
number
)
=>
{
if
(
previousCommentSearchProps
?.
accountName
)
{
const
newSearchProps
:
Explorer
.
CommentSearchProps
=
{
...
previousCommentSearchProps
,
pageNumber
:
newPageNum
,
};
setCommentSearchProps
(
newSearchProps
);
setParams
({
...
paramsState
,
page
:
newPageNum
});
}
};
useEffect
(()
=>
{
if
(
paramsState
&&
!
initial
Search
)
{
s
tar
tCommentSearch
(
paramsState
);
if
(
!
comment
Search
Props
)
{
s
e
tCommentSearch
PropsFromUrl
(
router
.
query
);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[
paramsState
]);
},
[
router
.
query
]);
return
(
<
div
...
...
@@ -105,39 +54,7 @@ const Comments: React.FC = () => {
<
CommentsSearch
/>
</
CardContent
>
</
Card
>
{
commentSearch
.
commentSearchData
&&
(
<>
<
div
className
=
"w-full flex justify-center items-center mt-4 mb-2"
>
<
CustomPagination
currentPage
=
{
paramsState
.
page
}
totalCount
=
{
commentSearch
.
commentSearchData
?.
total_operations
}
pageSize
=
{
config
.
standardPaginationSize
}
onPageChange
=
{
changeCommentSearchPagination
}
/>
<
div
className
=
"justify-self-end"
>
<
JumpToPage
currentPage
=
{
paramsState
.
page
}
onPageChange
=
{
changeCommentSearchPagination
}
/>
</
div
>
</
div
>
{
formattedOperations
?.
operations_result
?
(
<
OperationsTable
operations
=
{
convertCommentsOperationResultToTableOperations
(
formattedOperations
?.
operations_result
)
}
unformattedOperations
=
{
convertCommentsOperationResultToTableOperations
(
commentSearch
.
commentSearchData
.
operations_result
)
}
className
=
"text-white"
/>
)
:
(
<
div
className
=
"flex justify-center w-full text-black"
>
No operations matching given criteria
</
div
>
)
}
</>
)
}
<
CommentSearchResults
/>
</
div
>
);
};
...
...
This diff is collapsed.
Click to expand it.
types/Explorer.ts
+
1
−
1
View file @
b2d24c23
...
...
@@ -96,7 +96,7 @@ declare module Explorer {
pageSize
?:
number
;
direction
?:
"
asc
"
|
"
desc
"
;
dataSizeLimit
?:
number
;
rangeSelectKey
:
string
|
undefined
;
rangeSelectKey
?
:
string
|
undefined
;
lastTimeUnitValue
?:
Date
|
string
;
lastBlocksValue
?:
string
|
number
;
timeUnitSelectKey
?:
number
|
string
;
...
...
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