diff --git a/app/api/config.ts b/app/api/config.ts index 083ce23..0746eb2 100644 --- a/app/api/config.ts +++ b/app/api/config.ts @@ -1,4 +1,4 @@ -export const CURRENT_APP_VERSION = "3.5.0"; +export const CURRENT_APP_VERSION = "3.6.0"; export const API_URL = "https://api.anixart.tv"; export const API_PREFIX = "/api/proxy"; diff --git a/app/components/ContinueWatching/ContinueWatching.tsx b/app/components/ContinueWatching/ContinueWatching.tsx new file mode 100644 index 0000000..aabc78a --- /dev/null +++ b/app/components/ContinueWatching/ContinueWatching.tsx @@ -0,0 +1,90 @@ +"use client"; + +import { Card } from "flowbite-react"; +import { ReleaseLinkList } from "#/components/ReleaseLink/ReleaseLinkList"; +import { useUserStore } from "#/store/auth"; +import { ENDPOINTS } from "#/api/config"; +import { BookmarksList, useSWRfetcher } from "#/api/utils"; +import useSWR from "swr"; +import { useEffect, useState } from "react"; + +export const ContinueWatching = () => { + const userStore = useUserStore(); + + function useFetchReleases(listName: string) { + let url: string; + if (userStore.token) { + url = `${ENDPOINTS.user.bookmark}/all/${BookmarksList[listName]}/0?sort=1&token=${userStore.token}`; + } + const { data, isLoading, error } = useSWR(url, useSWRfetcher); + return [data, isLoading, error]; + } + + const [watchingData, watchingLoading, watchingError] = + useFetchReleases("watching"); + const [plannedData, plannedLoading, plannedError] = + useFetchReleases("planned"); + const [delayedData, delayedLoading, delayedError] = + useFetchReleases("delayed"); + + const [releaseData, setReleaseData] = useState([]); + + const firstN = (arr, n = 1) => arr.slice(0, n); + function _randomize(array: any[], limit: number) { + const toRand = array.slice(); + let currentIndex = toRand.length; + while (currentIndex != 0) { + let randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex--; + [toRand[currentIndex], toRand[randomIndex]] = [ + toRand[randomIndex], + toRand[currentIndex], + ]; + } + return firstN(toRand, limit); + } + + useEffect(() => { + if (!watchingLoading && !plannedLoading && !delayedLoading) { + const data = [ + ...(watchingData.content || []), + ...(plannedData.content || []), + ...(delayedData.content || []), + ]; + console.log("loaded data:", data); + const randomizedData = _randomize(data, 3); + setReleaseData(randomizedData); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [watchingLoading, plannedLoading, delayedLoading]); + + if ( + !userStore.isAuth || + watchingLoading || + plannedLoading || + delayedLoading || + releaseData.length == 0 + ) + return <>; + + console.log("randomized data:", releaseData); + + return ( + +
+

Продолжить просмотр

+
+
+ {releaseData.map((release: any) => { + return ( + + ); + })} +
+
+ ); +}; diff --git a/app/components/Profile/Profile.ActivityComment.tsx b/app/components/Profile/Profile.ActivityComment.tsx index 455771d..23909f0 100644 --- a/app/components/Profile/Profile.ActivityComment.tsx +++ b/app/components/Profile/Profile.ActivityComment.tsx @@ -17,7 +17,7 @@ export const ProfileActivityComment = (props: { key={`comment-${comment.id}`} >