|
1 |
| -import React from 'react' |
| 1 | +import React, { useCallback, useEffect } from 'react' |
2 | 2 | import { graphql, usePaginationFragment } from 'react-relay'
|
3 | 3 | import { IssuesFromLastRepo$key } from '../../queries/__generated__/IssuesFromLastRepo.graphql'
|
4 |
| -import { IssuesFromLastRepo_Query } from '../../queries/__generated__/IssuesFromLastRepo_Query.graphql' |
5 |
| -import { UserDetails_user$key } from '../../queries/__generated__/UserDetails_user.graphql' |
| 4 | +import { FaChevronRight } from '@react-icons/all-files/fa/FaChevronRight' |
6 | 5 | import Issue from './Issue'
|
7 | 6 |
|
8 | 7 | type IssuesFromLastRepoProps = {
|
@@ -32,27 +31,70 @@ const IssuesFromLastRepo = ({ user }: IssuesFromLastRepoProps) => {
|
32 | 31 | user
|
33 | 32 | )
|
34 | 33 |
|
| 34 | + const scrollableElement = React.useRef<HTMLDivElement>(null) |
| 35 | + |
| 36 | + enum scrollDirection { |
| 37 | + Left = -1, |
| 38 | + Right = 1, |
| 39 | + } |
| 40 | + |
| 41 | + const scrollHorizontally = useCallback((direction: scrollDirection) => { |
| 42 | + scrollableElement.current && |
| 43 | + (scrollableElement.current.scrollLeft += direction * 550) |
| 44 | + }, []) |
| 45 | + |
| 46 | + const handleScrollRight = () => { |
| 47 | + if (hasNext) { |
| 48 | + loadNext(2) |
| 49 | + } |
| 50 | + scrollHorizontally(scrollDirection.Right) |
| 51 | + } |
| 52 | + |
| 53 | + useEffect(() => { |
| 54 | + console.log('IssuesFromLastRepo: useEffect', data.issuesFromLastRepo.edges) |
| 55 | + scrollHorizontally(scrollDirection.Right) |
| 56 | + }, [data.issuesFromLastRepo.edges, scrollHorizontally, scrollDirection.Right]) |
| 57 | + |
35 | 58 | if (!data || data.issuesFromLastRepo.edges.length === 0) {
|
36 | 59 | return <></>
|
37 | 60 | }
|
38 | 61 |
|
39 | 62 | return (
|
40 | 63 | <div className="mt-10">
|
41 | 64 | <h3 className="font-bold text-gray-500 text-lg">Issues from last repo</h3>
|
42 |
| - <div className="grid grid-cols-2 xl:grid-cols-2 gap-4 mt-4"> |
43 |
| - {data.issuesFromLastRepo.edges.map( |
44 |
| - (issue) => issue && <Issue issue={issue.node} key={issue.node.id} /> |
45 |
| - )} |
46 |
| - {hasNext ? ( |
47 |
| - <button |
48 |
| - onClick={() => { |
49 |
| - loadNext(3) |
50 |
| - }} |
51 |
| - > |
52 |
| - Load more |
53 |
| - </button> |
54 |
| - ) : null} |
| 65 | + <div className="relative"> |
| 66 | + <div |
| 67 | + className=" flex overflow-x-auto space-x-4 no-scrollbar scroll-smooth" |
| 68 | + ref={scrollableElement} |
| 69 | + > |
| 70 | + {data.issuesFromLastRepo.edges.map( |
| 71 | + (issue) => issue && <Issue issue={issue.node} key={issue.node.id} /> |
| 72 | + )} |
| 73 | + </div> |
| 74 | + <button |
| 75 | + className="absolute right-8 bottom-0 mr-4 mt-4" |
| 76 | + onClick={() => scrollHorizontally(scrollDirection.Left)} |
| 77 | + > |
| 78 | + <FaChevronRight className="b-0 w-6 h-6 rotate-180 dark:text-gray-300 bg-gray-300 dark:bg-dark-900 rounded-full p-1 font-bold" /> |
| 79 | + </button> |
| 80 | + <button |
| 81 | + className="absolute right-0 bottom-0 mr-4 mt-4" |
| 82 | + onClick={() => handleScrollRight()} |
| 83 | + > |
| 84 | + <FaChevronRight className="b-0 w-6 h-6 dark:text-gray-300 bg-gray-300 dark:bg-dark-900 rounded-full p-1 font-bold" /> |
| 85 | + </button> |
55 | 86 | </div>
|
| 87 | + <style jsx> |
| 88 | + {` |
| 89 | + .no-scrollbar::-webkit-scrollbar { |
| 90 | + display: none; |
| 91 | + } |
| 92 | + .no-scrollbar { |
| 93 | + -ms-overflow-style: none; /* IE and Edge */ |
| 94 | + scrollbar-width: none; |
| 95 | + } |
| 96 | + `} |
| 97 | + </style> |
56 | 98 | </div>
|
57 | 99 | )
|
58 | 100 | }
|
|
0 commit comments