-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract Infinite Scroll Logic into Reusable Component
- Loading branch information
Showing
8 changed files
with
138 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { FormattedMessage } from 'react-intl' | ||
|
||
import { analytics } from '~/common/utils' | ||
import { InfiniteScroll, TagDigest } from '~/components' | ||
|
||
import styles from './styles.module.css' | ||
|
||
interface Props { | ||
edges: Array<{ node: any; cursor?: string }> | ||
pageInfo: { | ||
hasNextPage: boolean | ||
endCursor?: string | null | ||
} | ||
loadMore: () => Promise<any> | ||
trackingType: 'search_tag' | 'all_tags' | 'all_tags_recommended' | ||
searchKey?: string | ||
maxResults?: number | ||
showEOFMessage?: boolean | ||
} | ||
|
||
const InfiniteTagList = ({ | ||
edges, | ||
pageInfo, | ||
loadMore, | ||
trackingType, | ||
searchKey, | ||
maxResults = Infinity, | ||
showEOFMessage = true, | ||
}: Props) => { | ||
return ( | ||
<InfiniteScroll | ||
hasNextPage={pageInfo.hasNextPage && edges.length < maxResults} | ||
loadMore={loadMore} | ||
eof={ | ||
showEOFMessage && ( | ||
<FormattedMessage defaultMessage="End of the results" id="ui1+QC" /> | ||
) | ||
} | ||
> | ||
<ul className={styles.tagList}> | ||
{edges.map(({ node, cursor }, i) => | ||
node.__typename === 'Tag' ? ( | ||
<li key={cursor || node.id} className={styles.tagListItem}> | ||
<TagDigest.Feed | ||
tag={node} | ||
onClick={() => | ||
analytics.trackEvent('click_feed', { | ||
type: trackingType, | ||
contentType: 'tag', | ||
location: i, | ||
id: node.id, | ||
...(searchKey && { searchKey }), | ||
}) | ||
} | ||
/> | ||
</li> | ||
) : null | ||
)} | ||
</ul> | ||
</InfiniteScroll> | ||
) | ||
} | ||
|
||
export default InfiniteTagList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Infinite from './InfiniteTagList' | ||
|
||
export const TagList = { | ||
Infinite, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
.tagList { | ||
display: flex; | ||
flex-wrap: wrap; | ||
margin-top: var(--sp32); | ||
|
||
& .tagListItem { | ||
@mixin border-bottom-grey-light; | ||
|
||
position: relative; | ||
flex: 0 0 50%; | ||
padding-bottom: var(--sp20); | ||
margin-bottom: var(--sp20); | ||
border-style: dashed; | ||
|
||
&:last-child { | ||
flex-grow: 1; | ||
} | ||
} | ||
|
||
@media (--sm-down) { | ||
& .tagListItem { | ||
&:nth-child(2n + 1) { | ||
padding-right: var(--sp16); | ||
} | ||
|
||
&:last-child { | ||
padding-right: 0; | ||
|
||
& a { | ||
max-width: calc(50% - var(--sp16)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@media (--sm-up) { | ||
& .tagListItem { | ||
flex: 0 0 33.3333%; | ||
|
||
&:nth-child(3n + 1), | ||
&:nth-child(3n + 2) { | ||
padding-right: var(--sp16); | ||
} | ||
|
||
&:last-child { | ||
padding-right: 0; | ||
|
||
& a { | ||
max-width: calc(33.3333% - var(--sp16)); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters