2021-04-22 22:14:32 +00:00
|
|
|
import { useQuery } from '@apollo/client'
|
|
|
|
import Item, { ItemSkeleton } from './item'
|
2021-04-14 23:56:29 +00:00
|
|
|
import styles from './items.module.css'
|
|
|
|
|
2021-04-22 22:14:32 +00:00
|
|
|
export default function Items ({ query, rank }) {
|
|
|
|
const { loading, error, data } = useQuery(query)
|
|
|
|
if (error) return <div>Failed to load!</div>
|
|
|
|
if (loading) {
|
2021-05-06 21:15:22 +00:00
|
|
|
const items = new Array(20).fill(null)
|
2021-04-22 22:14:32 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.grid}>
|
|
|
|
{items.map((_, i) => (
|
|
|
|
<ItemSkeleton rank={i + 1} key={i} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-04-14 23:56:29 +00:00
|
|
|
const { items } = data
|
|
|
|
return (
|
|
|
|
<div className={styles.grid}>
|
|
|
|
{items.map((item, i) => (
|
2021-04-22 22:14:32 +00:00
|
|
|
<Item item={item} rank={rank && i + 1} key={item.id} />
|
2021-04-14 23:56:29 +00:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|