stacker.news/components/search-items.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-01-27 19:18:48 +00:00
import { useQuery } from '@apollo/client'
import { ItemSkeleton } from './item'
import styles from './items.module.css'
import { ITEM_SEARCH } from '../fragments/items'
import MoreFooter from './more-footer'
2023-05-06 21:51:17 +00:00
import { Fragment } from 'react'
import { CommentFlat } from './comment'
2022-01-27 19:18:48 +00:00
import ItemFull from './item-full'
export default function SearchItems ({ variables, items, pins, cursor }) {
const { data, fetchMore } = useQuery(ITEM_SEARCH, { variables })
if (!data && !items) {
return <ItemsSkeleton />
}
if (data) {
({ search: { items, cursor } } = data)
}
return (
<>
<div className={styles.grid}>
{items.map((item, i) => (
2023-05-06 21:51:17 +00:00
<Fragment key={item.id}>
2022-01-27 19:18:48 +00:00
{item.parentId
2023-05-06 21:51:17 +00:00
? <><div /><CommentFlat item={item} noReply includeParent /></>
2022-01-27 19:18:48 +00:00
: <><div /><div className={item.text ? 'pb-3' : ''}><ItemFull item={item} noReply /></div></>}
2023-05-06 21:51:17 +00:00
</Fragment>
2022-01-27 19:18:48 +00:00
))}
</div>
<MoreFooter
cursor={cursor} fetchMore={fetchMore}
2022-01-27 20:31:16 +00:00
noMoreText='EMPTY'
2022-01-27 19:18:48 +00:00
Skeleton={() => <ItemsSkeleton />}
/>
</>
)
}
function ItemsSkeleton () {
const items = new Array(21).fill(null)
return (
<div className={styles.grid}>
{items.map((_, i) => (
<ItemSkeleton key={i} />
))}
</div>
)
}