-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add feature to load load inifnite words
- Loading branch information
Showing
30 changed files
with
301 additions
and
128 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { useEffect } from 'react' | ||
|
||
import { Grid, GridProps } from '@chakra-ui/react' | ||
import { useInView } from 'react-intersection-observer' | ||
|
||
export interface InfiniteScrollGridProps extends GridProps { | ||
onViewChange?: () => void | ||
} | ||
|
||
export function InfiniteScrollGrid({ | ||
onViewChange = () => void 0, | ||
children, | ||
maxHeight = 'md', | ||
templateColumns = ['repeat(3, 1fr)', 'repeat(4, 1fr)', 'repeat(5, 1fr)'], | ||
gap = 0, | ||
...props | ||
}: InfiniteScrollGridProps) { | ||
const { ref, inView } = useInView() | ||
|
||
useEffect(() => { | ||
onViewChange() | ||
}, [onViewChange, inView]) | ||
|
||
return ( | ||
<Grid | ||
templateColumns={templateColumns} | ||
gap={gap} | ||
overflowY="scroll" | ||
maxHeight={maxHeight} | ||
{...props}> | ||
{children} | ||
<div ref={ref} /> | ||
</Grid> | ||
) | ||
} | ||
|
||
export default InfiniteScrollGrid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { InfiniteScrollGrid } from './InfiniteScrollGrid' | ||
|
||
export { InfiniteScrollGrid } | ||
export default InfiniteScrollGrid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
src/features/wordslist/components/FavoritesGrid/Favorites.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
src/features/wordslist/components/FavoritesList/FavoritesList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React, { useState } from 'react' | ||
|
||
import { Item } from 'features/wordslist/components/Item' | ||
import { useWordContext } from 'hooks/useWordContext' | ||
import { InfiniteScrollGrid } from 'components/InfiniteScrollGrid' | ||
|
||
interface Props {} | ||
|
||
export function FavoritesList({}: Props) { | ||
const { favoriteWord } = useWordContext() | ||
const [favorites] = useState(favoriteWord.getAll()) | ||
|
||
return ( | ||
<InfiniteScrollGrid> | ||
{favorites.map(favorite => ( | ||
<Item | ||
key={favorite.id} | ||
data={favorite} | ||
/> | ||
))} | ||
</InfiniteScrollGrid> | ||
) | ||
} | ||
|
||
export default FavoritesList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { FavoritesList } from './FavoritesList' | ||
|
||
export { FavoritesList } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react' | ||
import { GridItem, GridItemProps } from '@chakra-ui/react' | ||
|
||
import { IWord } from 'models/Word' | ||
import useWordContext from 'hooks/useWordContext' | ||
|
||
export interface ItemProps extends GridItemProps { | ||
isFavorite?: boolean | ||
data: IWord | ||
} | ||
|
||
export function Item({ | ||
children, | ||
isFavorite, | ||
data, | ||
borderColor = 'blackAlpha.300', | ||
...props | ||
}: ItemProps) { | ||
const { setSelectedWord } = useWordContext() | ||
|
||
return ( | ||
<GridItem | ||
borderStyle="solid" | ||
borderWidth={1} | ||
borderColor={borderColor} | ||
textAlign="center" | ||
cursor="pointer" | ||
padding={[2, 5]} | ||
onClick={() => setSelectedWord(data)} | ||
wordBreak="break-all" | ||
{...props}> | ||
{data.word} | ||
</GridItem> | ||
) | ||
} | ||
|
||
export default Item |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Item } from './Item' | ||
|
||
export { Item } | ||
export default Item |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react' | ||
|
||
import useWordsLoadMore from 'features/wordslist/hooks/useWordsLoadMore' | ||
import { Item } from 'features/wordslist/components/Item' | ||
import { useWordContext } from 'hooks/useWordContext' | ||
import { InfiniteScrollGrid } from 'components/InfiniteScrollGrid' | ||
|
||
interface Props {} | ||
|
||
export function WordsList({}: Props) { | ||
const { data, fetchNextPage } = useWordsLoadMore() | ||
const { favoriteWord } = useWordContext() | ||
|
||
return ( | ||
<InfiniteScrollGrid onViewChange={fetchNextPage}> | ||
{data?.pages.map((page, i) => { | ||
return ( | ||
<React.Fragment key={i}> | ||
{page.data.map(word => ( | ||
<Item | ||
key={word.id} | ||
data={word} | ||
/> | ||
))} | ||
</React.Fragment> | ||
) | ||
})} | ||
</InfiniteScrollGrid> | ||
) | ||
} | ||
|
||
export default WordsList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { WordsList } from './WordsList' | ||
|
||
export { WordsList } |
Oops, something went wrong.