2022-01-01 20:42:25 +01:00
|
|
|
import useTranslation from 'next-translate/useTranslation'
|
|
|
|
import { useEffect, useState } from 'react'
|
2021-11-13 21:50:34 +01:00
|
|
|
import InfiniteScroll from 'react-infinite-scroll-component'
|
|
|
|
|
2022-01-07 21:21:38 +01:00
|
|
|
import { useAuthentication } from '../../../tools/authentication'
|
|
|
|
import { GuildPublic as GuildPublicType } from '../../../models/Guild'
|
|
|
|
import { Loader } from '../../design/Loader'
|
2022-01-01 20:42:25 +01:00
|
|
|
import { GuildPublic } from './GuildPublic'
|
2022-01-07 21:21:38 +01:00
|
|
|
import { usePagination } from '../../../hooks/usePagination'
|
2021-11-13 21:50:34 +01:00
|
|
|
|
|
|
|
export const JoinGuildsPublic: React.FC = () => {
|
2022-01-01 20:42:25 +01:00
|
|
|
const [search, setSearch] = useState('')
|
2021-11-13 21:50:34 +01:00
|
|
|
const { authentication } = useAuthentication()
|
2022-01-01 20:42:25 +01:00
|
|
|
const { t } = useTranslation()
|
2021-11-13 21:50:34 +01:00
|
|
|
|
2022-01-01 20:42:25 +01:00
|
|
|
const { items, hasMore, nextPage, resetPagination } =
|
|
|
|
usePagination<GuildPublicType>({
|
|
|
|
api: authentication.api,
|
|
|
|
url: '/guilds/public'
|
2021-11-13 21:50:34 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-01-01 20:42:25 +01:00
|
|
|
resetPagination()
|
|
|
|
nextPage({ search })
|
|
|
|
}, [resetPagination, nextPage, search])
|
2021-11-13 21:50:34 +01:00
|
|
|
|
|
|
|
const handleChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
|
2022-01-01 20:42:25 +01:00
|
|
|
setSearch(event.target.value)
|
2021-11-13 21:50:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<input
|
|
|
|
data-cy='search-guild-input'
|
|
|
|
onChange={handleChange}
|
|
|
|
className='w-10/12 sm:w-8/12 md:w-6/12 lg:w-5/12 bg-white dark:bg-[#3B3B3B] border-gray-500 dark:border-gray-700 p-3 my-6 mt-16 mx-auto rounded-md border'
|
|
|
|
type='search'
|
|
|
|
name='search-guild'
|
2022-01-01 20:42:25 +01:00
|
|
|
placeholder={`🔎 ${t('application:search')}...`}
|
2021-11-13 21:50:34 +01:00
|
|
|
/>
|
|
|
|
<div className='w-full flex items-center justify-center p-12'>
|
|
|
|
<InfiniteScroll
|
2022-01-01 20:42:25 +01:00
|
|
|
className='guilds-public-list max-w-[1600px] grid grid-cols-1 xl:grid-cols-3 md:grid-cols-2 sm:grid-cols-1 gap-8 !overflow-hidden'
|
|
|
|
dataLength={items.length}
|
|
|
|
next={nextPage}
|
2021-11-13 21:50:34 +01:00
|
|
|
scrollableTarget='application-page-content'
|
|
|
|
hasMore={hasMore}
|
|
|
|
loader={<Loader />}
|
|
|
|
>
|
2022-01-01 20:42:25 +01:00
|
|
|
{items.map((guild) => {
|
|
|
|
return <GuildPublic guild={guild} key={guild.id} />
|
2021-11-13 21:50:34 +01:00
|
|
|
})}
|
|
|
|
</InfiniteScroll>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|