reza added scroll

master
Reza_ashrafi 3 years ago
parent e90cea120d
commit 7d639b0683
  1. 4
      src/redux/reducers/public.tsx
  2. 3
      src/util/scroll.js
  3. 2
      src/views/Subscription/index.tsx
  4. 34
      src/views/VideoTube/LessonPlayList/index.tsx
  5. 34
      src/views/VideoTube/index.tsx

@ -75,9 +75,7 @@ export default function publicApi(state = initialState, action: PublicAction) {
loading: false, loading: false,
bookSection: data, bookSection: data,
error: null, error: null,
selectedVideo: videoId selectedVideo: data?.vods?.filter((item: any) => item.name === videoId)[0]
? data?.vods?.filter((item: any) => item.name === videoId)[0]
: data?.vods[0],
}; };
case "public/vod/bookCourse": case "public/vod/bookCourse":

@ -4,6 +4,9 @@ class scroll {
goToTop = () => { goToTop = () => {
window.scrollTo(0,0); window.scrollTo(0,0);
} }
listScroll = () => {
}
} }
const _scroll = new scroll(); const _scroll = new scroll();

@ -29,7 +29,7 @@ function Subscription({ listVOD, getList, loading, selectedVOD, payment, verify
))} ))}
<DiscountCode /> <DiscountCode />
<div className="d-flex justify-content-end py-4"> <div className="d-flex justify-content-end py-4">
<button className="submit submit-large" onClick={() => payment({productId : selectedVOD.id }, {}) }>تایید و پرداخت</button> <button className="submit submit-large" onClick={() => payment({productId : selectedVOD.id }) }>تایید و پرداخت</button>
</div> </div>
</main> </main>
<Footer /> <Footer />

@ -1,4 +1,4 @@
import React from "react"; import React, { useEffect } from "react";
import "./index.scss"; import "./index.scss";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { publicApi } from "../../../redux/actions"; import { publicApi } from "../../../redux/actions";
@ -9,8 +9,30 @@ function LessonPlayList({
setVideoActive, setVideoActive,
catergories, catergories,
realCategories, realCategories,
vods,
}: any) { }: any) {
const bookId = localStorage.getItem("bookId"); const bookId = localStorage.getItem("bookId");
useEffect(() => {
if (localStorage.getItem("scroll-list") && vods) {
const list: HTMLElement = document.getElementById("list") as HTMLElement;
const listItem: HTMLElement = document.getElementById(
"listItem" + selectedVideo.id
) as HTMLElement;
const elementHeight: any = (listItem as any)?.offsetHeight;
const listHeight: any = (list as any).offsetHeight;
const index = vods.findIndex((
(item: any) => item.name === selectedVideo.name
));
console.log(index);
console.log(listHeight,elementHeight * (Number(index) + 1));
if( elementHeight * (Number(index) + 1) > listHeight){
list.scrollTo(0, (elementHeight * (Number(index) + 1)) + elementHeight);
}
localStorage.removeItem("scroll-list");
}
}, [vods]);
return ( return (
<> <>
{ {
@ -18,9 +40,10 @@ function LessonPlayList({
{bookId && ( {bookId && (
<header> <header>
<h3> <h3>
{ realCategories.filter( {
(item: any) => item.id === category[0].categoryId realCategories.filter(
)[0].name (item: any) => item.id === category[0].categoryId
)[0].name
} }
</h3> </h3>
<span></span> <span></span>
@ -37,6 +60,7 @@ function LessonPlayList({
"lesson-playlist__item--active") "lesson-playlist__item--active")
} }
key={i} key={i}
id={"listItem" + video.id}
onClick={() => setVideoActive(video)} onClick={() => setVideoActive(video)}
> >
<span className="lesson-playlist__item--count"> <span className="lesson-playlist__item--count">
@ -69,6 +93,7 @@ function LessonPlayList({
"lesson-playlist__item--active") "lesson-playlist__item--active")
} }
onClick={() => setVideoActive(category)} onClick={() => setVideoActive(category)}
id={"listItem" + category.id}
> >
<span className="lesson-playlist__item--count"></span> <span className="lesson-playlist__item--count"></span>
<div className="lesson-playlist__item--video"> <div className="lesson-playlist__item--video">
@ -99,6 +124,7 @@ export default connect(
(state: any) => ({ (state: any) => ({
selectedVideo: state.publicApi.selectedVideo, selectedVideo: state.publicApi.selectedVideo,
realCategories: state.publicApi.bookInfo?.categories, realCategories: state.publicApi.bookInfo?.categories,
vods: state.publicApi.bookSection?.vods,
}), }),
{ {
setVideoActive: publicApi.setVideoActive, setVideoActive: publicApi.setVideoActive,

@ -23,29 +23,26 @@ function VodTube({
getInfo, getInfo,
categories, categories,
setVideoActive, setVideoActive,
allBooks,
}: any) { }: any) {
const videoListTag = useRef(null); const videoListTag = useRef(null);
useEffect(() => { useEffect(() => {
localStorage.setItem("scroll-list", "on");
scroll.goToTop(); scroll.goToTop();
// getInfo({ getInfo({
// bookId: 1, bookId: localStorage.getItem("bookId")
// // window.location.pathname.slice( ? localStorage.getItem("bookId")
// // window.location.pathname.lastIndexOf("/") + 1, : localStorage.getItem("category")?.split(",")[0],
// // window.location.pathname.length });
// // ),
// });
getInfo({ bookId: localStorage.getItem("bookId") });
}, []); }, []);
useEffect(() => { useEffect(() => {
if (!info && localStorage.getItem("category")) { if (allBooks && localStorage.getItem("category")) {
const cat: any = localStorage.getItem("category")?.split(","); const cat: any = localStorage.getItem("category")?.split(",");
bookSection({ bookId: cat[0], categoryId: cat[1] }); bookSection({ bookId: cat[0], categoryId: cat[1] });
} }
if(info && localStorage.getItem("category")){ }, [allBooks]);
// document.getElementsByClassName('video-tube__sidebar--playlist___list').scrollTo(0,)
}
}, [info]);
return ( return (
<> <>
<div <div
@ -94,12 +91,16 @@ function VodTube({
</div> </div>
<img src={listIcon} alt="" /> <img src={listIcon} alt="" />
</header> </header>
<div ref={videoListTag} className="video-tube__sidebar--playlist___list d-flex flex-column"> <div
ref={videoListTag}
className="video-tube__sidebar--playlist___list d-flex flex-column"
id="list"
>
{localStorage.getItem("bookId") {localStorage.getItem("bookId")
? categories?.map((video: any, i: any) => ( ? categories?.map((video: any, i: any) => (
<LessonPlayList category={video} key={i} /> <LessonPlayList category={video} key={i} />
)) ))
: info?.vods?.map((video: any, i: any) => ( : info?.vods.map((video: any, i: any) => (
<LessonPlayList category={video} key={i} /> <LessonPlayList category={video} key={i} />
))} ))}
</div> </div>
@ -125,7 +126,7 @@ function VodTube({
<span>تا 50% تخفیف </span> <span>تا 50% تخفیف </span>
</header> </header>
<div className="video-tube__sidebar--suggests___list d-flex justify-content-between align-items-center"> <div className="video-tube__sidebar--suggests___list d-flex justify-content-between align-items-center">
{info?.related?.map((item: any, i: any) => ( {info?.related.slice(0,3).map((item: any, i: any) => (
<Book data={item} key={i} /> <Book data={item} key={i} />
))} ))}
</div> </div>
@ -163,6 +164,7 @@ export default connect(
info: state.publicApi.bookSection, info: state.publicApi.bookSection,
loading: state.publicApi.loading, loading: state.publicApi.loading,
categories: state.publicApi.categories, categories: state.publicApi.categories,
allBooks: state.publicApi.bookInfo?.vods,
}), }),
{ {
getInfo: publicApi.bookInfo, getInfo: publicApi.bookInfo,

Loading…
Cancel
Save