diff --git a/packages/fakeyou.com/src/v2/view/pages/explore/tabs/FeaturedTab.tsx b/packages/fakeyou.com/src/v2/view/pages/explore/tabs/FeaturedTab.tsx index 443719aab8..0583a25370 100644 --- a/packages/fakeyou.com/src/v2/view/pages/explore/tabs/FeaturedTab.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/explore/tabs/FeaturedTab.tsx @@ -1,154 +1,185 @@ -import React, { useEffect, useRef, useState } from "react"; +import React, { useRef, useState } from "react"; import { useLocation } from "react-router-dom"; import MasonryGrid from "components/common/MasonryGrid/MasonryGrid"; import MediaCards from "components/common/Card/MediaCards"; -import { Link } from "react-router-dom"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { faChevronRight } from "@fortawesome/pro-solid-svg-icons"; -import { MediaFile } from "@storyteller/components/src/api/media_files/GetMedia"; -import { useBookmarks, useRatings } from "hooks"; -import { ListFeaturedMediaFiles } from "@storyteller/components/src/api/media_files/ListFeaturedMediaFiles"; -import { FetchStatus } from "@storyteller/components/src/api/_common/SharedFetchTypes"; +import { Button, TempSelect as Select } from "components/common"; +import { + faArrowDownWideShort, + faFilter, +} from "@fortawesome/pro-solid-svg-icons"; +import AudioPlayerProvider from "components/common/AudioPlayer/AudioPlayerContext"; import SkeletonCard from "components/common/Card/SkeletonCard"; -// import { SegmentButtons } from "components/common"; -import "./FeaturedTab.scss"; +import { MediaFile } from "@storyteller/components/src/api/media_files/GetMedia"; +import { + useBookmarks, + useLazyLists, + useLocalize, + useOnScreen, + useRatings, +} from "hooks"; +import InfiniteScroll from "react-infinite-scroll-component"; +import prepFilter from "resources/prepFilter"; +import { ListFeaturedMediaFiles } from "@storyteller/components/src/api/media_files/ListFeaturedMediaFiles"; +import { + EntityInputMode, + EntityFilterOptions, +} from "components/entities/EntityTypes"; -export default function FeaturedTab() { - const { pathname: source } = useLocation(); +export default function MediaTab() { + const { pathname: source, search } = useLocation(); + const urlQueries = new URLSearchParams(search); const bookmarks = useBookmarks(); const ratings = useRatings(); + const toTopBtnRef = useRef(null); + const onScreen = useOnScreen(toTopBtnRef, "0px"); + const { t } = useLocalize("EntityGeneral"); + const gridContainerRef = useRef(null); + const [mediaType, mediaTypeSet] = useState( + urlQueries.get("filter_media_type") || "video" + ); + const [showMasonryGrid, setShowMasonryGrid] = useState(true); const [list, listSet] = useState([]); - const [ - listType, - // listTypeSet - ] = useState("media"); - // const [showMasonryGrid, setShowMasonryGrid] = useState(true); - const [status, statusSet] = useState(FetchStatus.ready); - const isLoading = - status === FetchStatus.ready || status === FetchStatus.in_progress; + const media = useLazyLists({ + addQueries: { + page_size: urlQueries.get("page_size") || "24", + ...prepFilter(mediaType, "filter_media_type"), + }, + addSetters: { mediaTypeSet }, + fetcher: ListFeaturedMediaFiles, + list, + listSet, + onInputChange: () => setShowMasonryGrid(false), + onSuccess: res => { + ratings.gather({ res, expand: true, key: "token" }); // expand rather than replace for lazy loading + bookmarks.gather({ res, expand: true, key: "token" }); // expand rather than replace for lazy loading + setShowMasonryGrid(true); + }, + requestList: true, + }); - // const options = [{ label: "Media", value: "media" },{ label: "Weights", value: "weight" }]; - // const onChange = ({ target }: any) => { - // listTypeSet(target.value === "weight" ? target.value : "media"); - // // clear list - // // statusSet(FetchStatus.ready) - // }; + const filterOptions = EntityFilterOptions(EntityInputMode.media, t); - useEffect(() => { - if (status === FetchStatus.ready) { - statusSet(FetchStatus.in_progress); - if (listType === "media") { - ListFeaturedMediaFiles("", {}).then((res: any) => { - console.log("🏮", res); - statusSet(FetchStatus.success); - if (res.results) { - listSet(res.results); - } - }); - } - // else if (listType === "weight") {} - } - }, [listType, status]); + const sortOptions = [ + { value: false, label: "Newest" }, + { value: true, label: "Oldest" }, + // { value: "mostliked", label: "Most Liked" }, + ]; return ( -
-
-
-

Featured

- { - // // switch between media/weights control - } - - View media - - + <> +
+
+
- - {isLoading && !list.length ? ( + {media.urlCursor ? ( +
+
+ ) : null} +
+ {media.urlCursor && !onScreen ? ( +
- {/*
-
-

- Featured Image Weights -

- - View all - - -
- - {isLoading ? ( -
- {Array.from({ length: 6 }).map((_, index) => ( - - ))} -
- ) : ( - console.log("Layout complete!")} - > - {data.map((data, index) => { - let card = ( - - ); - return ( -
- {card} + +
+ Loading... +
- ); - })} -
+ ) + } + endMessage={ +

No more results.

+ } + className="overflow-hidden" + > + {showMasonryGrid && ( + <> + {media.list.length === 0 && media.status === 3 ? ( +
+ No media created yet. +
+ ) : ( + console.log("Layout complete!")} + > + {media.list.map((data: any, key: number) => { + let props = { + bookmarks, + data, + source, + ratings, + type: "media", + showCreator: true, + }; + + return ( +
+ +
+ ); + })} +
+ )} + + )} + )} -
*/} -
+ + ); }