Skip to content

Commit 6d9b2ad

Browse files
committed
add limit to list items
1 parent 630e040 commit 6d9b2ad

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/components/List/ListComponent.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ReactNode } from 'react'
22
import { Placeholder } from 'src/components/placeholders'
3+
import { MAX_ITEMS_PER_CARD } from 'src/config'
34
import { CarbonAd } from 'src/features/carbonAds'
45
import { BaseEntry } from 'src/types'
56

@@ -11,10 +12,19 @@ export type ListComponentPropsType<T extends BaseEntry> = {
1112
placeholder?: React.ReactNode
1213
refresh?: boolean
1314
error?: any
15+
limit?: number
1416
}
1517

1618
export function ListComponent<T extends BaseEntry>(props: ListComponentPropsType<T>) {
17-
const { items, isLoading, error, renderItem, withAds, placeholder = <Placeholder /> } = props
19+
const {
20+
items,
21+
isLoading,
22+
error,
23+
renderItem,
24+
withAds,
25+
placeholder = <Placeholder />,
26+
limit = MAX_ITEMS_PER_CARD,
27+
} = props
1828

1929
if (error) {
2030
return <p className="errorMsg">{error?.message || error}</p>
@@ -25,7 +35,7 @@ export function ListComponent<T extends BaseEntry>(props: ListComponentPropsType
2535
return
2636
}
2737

28-
return items.map((item, index) => {
38+
return items.slice(0, limit).map((item, index) => {
2939
let content: ReactNode[] = [renderItem(item, index)]
3040
if (withAds && index === 0) {
3141
content.unshift(<CarbonAd key={'carbonAd0'} />)

src/config/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,4 @@ export const MY_LANGUAGES_TAG = {
188188
mediumValues: ['myLangs'],
189189
freecodecampValues: ['myLangs'],
190190
}
191-
export const MAX_MERGED_ITEMS_PER_LANGUAGE = 10
191+
export const MAX_ITEMS_PER_CARD = 50

0 commit comments

Comments
 (0)