-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
406 additions
and
38 deletions.
There are no files selected for viewing
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,38 @@ | ||
// @flow | ||
import * as React from "react"; | ||
import { GetVideoResponse } from "../../src/services/VideoService"; | ||
import { CardMedia, Stack, Typography } from "@mui/material"; | ||
import Image from "next/image"; | ||
|
||
type Props = { | ||
video: GetVideoResponse; | ||
}; | ||
|
||
export function VideoCard(props: Props) { | ||
return ( | ||
<Stack spacing={0.5} sx={{ cursor: "pointer" }}> | ||
<CardMedia | ||
component={"img"} | ||
image={ | ||
props.video.thumbnail ?? | ||
"https://helpx.adobe.com/content/dam/help/en/photoshop/using/convert-color-image-black-white/jcr_content/main-pars/before_and_after/image-before/Landscape-Color.jpg" | ||
} | ||
sx={{ | ||
height: 240, | ||
borderRadius: 6, | ||
}} | ||
/> | ||
<Typography fontSize={14}>{props.video.title}</Typography> | ||
{/*User name*/} | ||
<Stack direction={"row"} spacing={1}> | ||
<Image | ||
src={"/images/user.icon.svg"} | ||
alt={"user"} | ||
width={20} | ||
height={20} | ||
/> | ||
<Typography fontSize={14}>{props.video.title}</Typography> | ||
</Stack> | ||
</Stack> | ||
); | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,95 @@ | ||
import Head from "next/head"; | ||
import Image from "next/image"; | ||
import { useGetVideos } from "../src/hooks/useGetVideos"; | ||
import { useVirtualizer } from "@tanstack/react-virtual"; | ||
import { useEffect, useRef } from "react"; | ||
import { | ||
Box, | ||
Chip, | ||
CircularProgress, | ||
Container, | ||
Grid, | ||
Paper, | ||
Stack, | ||
useTheme, | ||
} from "@mui/material"; | ||
import { debug } from "util"; | ||
import { VideoCard } from "../components/Video/VideoCard"; | ||
|
||
export default function Home() { | ||
return <></>; | ||
const { | ||
status, | ||
data, | ||
error, | ||
isFetching, | ||
isFetchingNextPage, | ||
fetchNextPage, | ||
hasNextPage, | ||
} = useGetVideos(); | ||
|
||
const parentRef = useRef(null); | ||
|
||
const rows = data ? data.pages.flatMap((page) => page.items) : []; | ||
|
||
const rowVirtualizer = useVirtualizer({ | ||
count: hasNextPage ? rows.length + 1 : rows.length, | ||
getScrollElement: () => parentRef.current!, | ||
estimateSize: () => 100, | ||
overscan: 10, | ||
}); | ||
|
||
useEffect(() => { | ||
const [lastItem] = [...rowVirtualizer.getVirtualItems()].reverse(); | ||
if (!lastItem) { | ||
return; | ||
} | ||
|
||
if ( | ||
lastItem.index >= rows.length - 1 && | ||
hasNextPage && | ||
!isFetchingNextPage | ||
) { | ||
fetchNextPage(); | ||
} | ||
}, [ | ||
hasNextPage, | ||
fetchNextPage, | ||
rows.length, | ||
isFetchingNextPage, | ||
rowVirtualizer.getVirtualItems(), | ||
]); | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<Stack spacing={2} ref={parentRef}> | ||
<Box position={"sticky"} top={64}> | ||
<Paper | ||
elevation={0} | ||
sx={{ | ||
background: ( | ||
theme.components?.MuiAppBar?.styleOverrides?.root as any | ||
)?.backgroundColor, | ||
}} | ||
> | ||
<Stack | ||
width={"100%"} | ||
direction={"row"} | ||
justifyContent={"center"} | ||
alignItems={"center"} | ||
p={1} | ||
> | ||
<Chip label={"All"} /> | ||
</Stack> | ||
</Paper> | ||
</Box> | ||
<Grid container spacing={2} columns={{ lg: 15 }} px={10}> | ||
{rowVirtualizer.getVirtualItems().map((virtualRow) => { | ||
const row = rows[virtualRow.index]; | ||
return ( | ||
<Grid item lg={3} key={virtualRow.index}> | ||
{row ? <VideoCard video={row} /> : <CircularProgress />} | ||
</Grid> | ||
); | ||
})} | ||
</Grid> | ||
</Stack> | ||
); | ||
} |
Oops, something went wrong.
1e85a31
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
video-trading – ./
video2.trade
video-trading-git-main-etherdata-blockchain.vercel.app
video-trading.vercel.app
video-trading-etherdata-blockchain.vercel.app
www.video2.trade