11import React from "react" ;
2- import { Empty } from "antd" ;
3- import { Repo , Tabs , SimplePagination , Card } from "shared/components" ;
4- import { str , dom } from "shared/helpers" ;
52import { useReposQuery } from "./queries.gen" ;
6- import { useFilters , PAGE_SIZE , useStarring } from "./hooks" ;
7- import { tabsMap } from "./params" ;
3+ import { useFilters , useStarring } from "./hooks" ;
4+ import Tabs from "./tabs" ;
5+ import Items from "./items" ;
6+ import Pagination from "./pagination" ;
87import "./index.scss" ;
98
109type Props = {
@@ -15,6 +14,7 @@ type Props = {
1514/**
1615 * @feature Список репозиториев пользователя
1716 * FIXME: rename to UserRepoList? (coz - user as dep)
17+ * FIXME: simplify inner components
1818 */
1919const RepoList = ( { username } : Props ) => {
2020 const { handleTabClick, handlePaginationClick, config } = useFilters ( ) ;
@@ -23,60 +23,23 @@ const RepoList = ({ username }: Props) => {
2323 } ) ;
2424 // TODO: transmit id and viewerHasStarred of nodes to handler func
2525 const starring = useStarring ( variables ) ;
26- const { pageInfo, totalCount = 0 , nodes } = data ?. user ?. repositories || { } ;
27- const length = nodes ?. length ;
26+ const { repositories } = data ?. user || { } ;
2827
2928 return (
3029 < div className = "repo-list" >
31- < Tabs className = "repo-list__tabs" >
32- { Object . keys ( tabsMap ) . map ( ( type ) => (
33- < Tabs . Item
34- key = { type }
35- name = { str . capitalize ( type ) }
36- className = "repo-list__tab"
37- active = { config . tab === type }
38- onClick = { ( ) => handleTabClick ( type ) }
39- label = { config . tab === type && ! loading ? String ( totalCount ) : undefined }
40- />
41- ) ) }
42- </ Tabs >
43-
44- < div className = "repo-list__items mt-6" >
45- { /* NOTE: А то все {PAGE_SIZE} плейсхолдеров слишком много */ }
46- { loading && < Card . SkeletonGroup amount = { 10 } /> }
47- { length !== 0 ? (
48- data ?. user ?. repositories . nodes ?. map ( ( node ) => (
49- < Repo
50- onStarring = { ( ) => starring . handle ( node ?. id , node ?. viewerHasStarred ) }
51- key = { node ?. id }
52- data = { node }
53- loading = { starring . debouncedLoadingId === node ?. id }
54- />
55- ) )
56- ) : (
57- < Empty
58- className = "repo-list__placeholder"
59- description = { < h2 > { username } doesn’t have any repositories yet.</ h2 > }
60- />
61- ) }
62- </ div >
63- < div className = "repo-list__pagination my-6" >
64- { totalCount > PAGE_SIZE && pageInfo && (
65- < SimplePagination
66- onPrev = { ( ) => {
67- handlePaginationClick ( { before : pageInfo . startCursor } ) ;
68- dom . scrollToTop ( ) ;
69- } }
70- onNext = { ( ) => {
71- handlePaginationClick ( { after : pageInfo . endCursor } ) ;
72- dom . scrollToTop ( ) ;
73- } }
74- hasNextPage = { pageInfo . hasNextPage }
75- hasPrevPage = { pageInfo . hasPreviousPage }
76- center
77- />
78- ) }
79- </ div >
30+ < Tabs
31+ handleTabClick = { handleTabClick }
32+ config = { config }
33+ loading = { loading }
34+ totalCount = { repositories ?. totalCount }
35+ />
36+ < Items
37+ loading = { loading }
38+ nodes = { repositories ?. nodes }
39+ starring = { starring }
40+ username = { username }
41+ />
42+ < Pagination handlePaginationClick = { handlePaginationClick } { ...repositories } />
8043 </ div >
8144 ) ;
8245} ;
0 commit comments