Skip to content

Commit

Permalink
将视频页的瀑布流修改为feed流
Browse files Browse the repository at this point in the history
  • Loading branch information
master1lan committed Jan 7, 2023
1 parent 23aab6c commit 827d028
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 134 deletions.
32 changes: 32 additions & 0 deletions src/components/image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,35 @@ export default memo(function Image({
</InView>
);
});

export function ImageBasic({
url,
fallbackUrl = DefaultFallbackUrl,
observer,
callback,
children,
}: Omit<ImageProps, "width" | "height"> & {
children?: ReactElement;
}) {
const res = useLoading(url),
{ isLoaded, success } = res,
real_fallback_url = fallbackUrl || DefaultFallbackUrl;
const once_callback = useCallback(Once(callback!!), []);
return (
<InView>
{({ inView, ref, entry }) => (
<div ref={ref} className={styles.imgWrapper}>
<img
src={isLoaded && success ? url : real_fallback_url}
style={{
opacity: isLoaded ? 1.0 : 0.09,
}}
alt=''
/>
<>{observer && inView && once_callback(inView)}</>
{children}
</div>
)}
</InView>
);
}
26 changes: 13 additions & 13 deletions src/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
margin: 0;
}

.feedContainer {
margin: 0 auto;
max-width: 1200px;
display: flex;
align-items: flex-start;
position: relative;
width: 100%;
// .feedContainer {
// margin: 0 auto;
// // max-width: 1200px;
// display: flex;
// align-items: flex-start;
// position: relative;
// width: 100%;

.element-item {
min-width: 200px;
box-sizing: border-box;
padding: 0 5px;
}
}
// .element-item {
// min-width: 200px;
// box-sizing: border-box;
// padding: 0 5px;
// }
// }
2 changes: 1 addition & 1 deletion src/routers/video/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default function VideoPage() {
return (
<>
<h1>videopage</h1>
{/* <VideoMasonry /> */}
<VideoMasonry />
</>
);
}
39 changes: 24 additions & 15 deletions src/routers/video/masonry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ImageSize,
} from "@components/image/tool";
import { Masonry as Masonic_masonry } from "masonic";
import Grid from "@mui/material/Unstable_Grid2";
import ImageShouldResizeProview from "@components/proview/imageSize";
import { VideoRouterImageCard } from "./masonryItem";
/**
Expand Down Expand Up @@ -50,13 +51,13 @@ export default function VideoMasonry(props: any) {
"face"
);

if (imageSize.success === true) {
return {
...itemRes,
width: order_width,
height: getResizeHeight(imageSize, order_width),
};
}
// if (imageSize.success === true) {
// return {
// ...itemRes,
// width: order_width,
// height: Math.floor((order_width * 3) / 4),
// };
// }
return itemRes;
}),
]);
Expand All @@ -66,14 +67,22 @@ export default function VideoMasonry(props: any) {
return (
<div className='feedContainer'>
<ImageShouldResizeProview>
<Masonic_masonry
items={lists}
columnWidth={order_width}
rowGutter={10}
maxColumnCount={5}
render={VideoRouterImageCard}
overscanBy={Infinity}
/>
<Grid
container
spacing={2}
columns={{
lg: 10,
md: 8,
sm: 6,
xs: 4,
}}
>
{lists.map((item, index) => (
<Grid key={index} xs={2}>
<VideoRouterImageCard data={item} />
</Grid>
))}
</Grid>
</ImageShouldResizeProview>
</div>
);
Expand Down
13 changes: 6 additions & 7 deletions src/routers/video/masonryItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Image from "@components/image";
import { ImageBasic } from "@components/image";
import { FC } from "react";
import SlowMotionVideoSharpIcon from "@mui/icons-material/SlowMotionVideoSharp";
import SubjectSharpIcon from "@mui/icons-material/SubjectSharp";
Expand All @@ -16,14 +16,14 @@ export const VideoRouterImageCard: FC<{ data: VideoRouterImageCardType }> = ({
}) => {
const { pic, bvid } = data;
return (
<section className='element-item'>
<section className={styles["video-section"]}>
<Link
target='_blank'
href={`https://www.bilibili.com/video/${bvid}`}
underline='none'
color='inherit'
>
<Image
<ImageBasic
url={pic}
{...Omit(
data,
Expand All @@ -43,7 +43,7 @@ export const VideoRouterImageCard: FC<{ data: VideoRouterImageCardType }> = ({
)}
>
<VideoData {...Pick(data, "view", "danmaku", "duration")} />
</Image>
</ImageBasic>
</Link>
<VideoInfo
{...Pick(
Expand All @@ -70,11 +70,11 @@ const VideoData: FC<
<div className={styles["video-data-left"]}>
<span title='播放量'>
<SlowMotionVideoSharpIcon fontSize='small' />
{view}
{getFixedNumber(view)}
</span>
<span title='弹幕数'>
<SubjectSharpIcon fontSize='small' />
{danmaku}
{getFixedNumber(danmaku)}
</span>
</div>
<span title='视频时长'>{getVideoTime(duration)}</span>
Expand Down Expand Up @@ -132,7 +132,6 @@ const VideoInfo: FC<
</div>
);
};
// 1-6 todo:写完视频页面展示瀑布图

export const CoinIcon: FC<{
height: number | string;
Expand Down
Loading

0 comments on commit 827d028

Please sign in to comment.