feat: add price list page
This commit is contained in:
parent
fbf4068f58
commit
32d1dca9b6
61
src/components/EmailsList/index.tsx
Normal file
61
src/components/EmailsList/index.tsx
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import { getRandomArbitrary, getRandomName } from '@/services/random-value'
|
||||||
|
import EmailItem, { IEmailItem } from '../EmailItem'
|
||||||
|
import styles from './styles.module.css'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
|
||||||
|
const emails: IEmailItem[] = []
|
||||||
|
|
||||||
|
for (let i = 0; i < 25; i++) {
|
||||||
|
const sublist = []
|
||||||
|
for (let j = 0; j < 4; j++) {
|
||||||
|
sublist.push({
|
||||||
|
email: getRandomName(),
|
||||||
|
price: 9
|
||||||
|
})
|
||||||
|
}
|
||||||
|
sublist[getRandomArbitrary(0, 4)].price = [5, 13.67][getRandomArbitrary(0, 2)]
|
||||||
|
emails.push(...sublist)
|
||||||
|
}
|
||||||
|
|
||||||
|
function EmailsList(): JSX.Element {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const [countUsers, setCountUsers] = useState(752)
|
||||||
|
const itemsRef = useRef<HTMLDivElement[]>([]);
|
||||||
|
let elementIdx = 0
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const randomDelay = getRandomArbitrary(3000, 5000)
|
||||||
|
const countUsersTimeOut = setTimeout(() => {
|
||||||
|
setCountUsers((prevState) => prevState + 1)
|
||||||
|
}, randomDelay)
|
||||||
|
return () => clearTimeout(countUsersTimeOut)
|
||||||
|
}, [countUsers, elementIdx])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const itemsRefInterval = setInterval(() => {
|
||||||
|
|
||||||
|
if (itemsRef.current[elementIdx]?.style) {
|
||||||
|
itemsRef.current[elementIdx].className = styles.hidden
|
||||||
|
}
|
||||||
|
elementIdx++
|
||||||
|
}, 3000)
|
||||||
|
return () => clearTimeout(itemsRefInterval)
|
||||||
|
}, [elementIdx])
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.container}>
|
||||||
|
<span className={styles['title']}>{t('people_joined_today', { countPeoples: <strong>{countUsers}</strong> })}</span>
|
||||||
|
<div className={styles['emails-container']}>
|
||||||
|
{emails.map(({email, price}, idx) => (
|
||||||
|
<div ref={(el: HTMLDivElement) => itemsRef.current[idx] = el} key={idx}>
|
||||||
|
<EmailItem email={email} price={price} />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EmailsList
|
||||||
Loading…
Reference in New Issue
Block a user