diff --git a/app/api/config.ts b/app/api/config.ts index 083ce23..a4fc159 100644 --- a/app/api/config.ts +++ b/app/api/config.ts @@ -19,14 +19,6 @@ export const ENDPOINTS = { history: `${API_PREFIX}/history`, favorite: `${API_PREFIX}/favorite`, blocklist: `${API_PREFIX}/profile/blocklist`, - friend: { - list: `${API_PREFIX}/profile/friend/all`, - add: `${API_PREFIX}/profile/friend/request/send`, - remove: `${API_PREFIX}/profile/friend/request/remove`, - hide: `${API_PREFIX}/profile/friend/request/hide`, - in: `${API_PREFIX}/profile/friend/requests/in`, - out: `${API_PREFIX}/profile/friend/requests/out`, - }, settings: { my: `${API_PREFIX}/profile/preference/my`, login: { diff --git a/app/components/Profile/Profile.Activity.tsx b/app/components/Profile/Profile.Activity.tsx index 1c02ab6..9438cec 100644 --- a/app/components/Profile/Profile.Activity.tsx +++ b/app/components/Profile/Profile.Activity.tsx @@ -1,24 +1,24 @@ "use client"; import { Button, ButtonGroup, Card } from "flowbite-react"; +// import Link from "next/link"; +// import { numberDeclension } from "#/api/utils"; import { ProfileActivityCollections } from "./Profile.ActivityCollections"; import { useEffect, useState } from "react"; +import { CollectionCourusel } from "../CollectionCourusel/CollectionCourusel"; import { ProfileActivityFriends } from "./Profile.ActivityFriends"; -import { ProfileActivityComment } from "./Profile.ActivityComment"; export function ProfileActivity(props: { profile_id: number; commentCount: number; - commentPreview: any; + videoCount: number; collectionCount: number; collectionPreview: any; friendsCount: number; friendsPreview: any; - token: string; - isMyProfile: boolean; }) { - const [tab, setTab] = useState<"collections" | "comments" | "friends">( - "collections" - ); + const [tab, setTab] = useState< + "collections" | "comments" | "friends" | "videos" + >("collections"); const [collections, setCollections] = useState>({}); @@ -62,28 +62,25 @@ export function ProfileActivity(props: { color={tab == "collections" ? "blue" : "light"} onClick={() => setTab("collections")} > -
-

Коллекции

-

( {props.collectionCount} )

-
+ Коллекции | {props.collectionCount} + @@ -93,20 +90,9 @@ export function ProfileActivity(props: { profile_id={props.profile_id} /> )} - {tab == "comments" && ( - - )} - {tab == "friends" && ( - - )} + {tab == "comments" && <>comments} + {tab == "friends" && } + {tab == "videos" && <>videos} ); } diff --git a/app/components/Profile/Profile.ActivityCollections.tsx b/app/components/Profile/Profile.ActivityCollections.tsx index 3e083e5..42e0fe7 100644 --- a/app/components/Profile/Profile.ActivityCollections.tsx +++ b/app/components/Profile/Profile.ActivityCollections.tsx @@ -41,9 +41,11 @@ export const ProfileActivityCollections = (props: { key={`col-prev-${collection.id}`} style={{ width: "fit-content" }} > -
- -
+ +
+ +
+ ); })} @@ -51,7 +53,7 @@ export const ProfileActivityCollections = (props: { {props.content && props.content.length > 0 ? -
+

Все коллекции

diff --git a/app/components/Profile/Profile.ActivityComment.tsx b/app/components/Profile/Profile.ActivityComment.tsx deleted file mode 100644 index 455771d..0000000 --- a/app/components/Profile/Profile.ActivityComment.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import Link from "next/link"; -import Image from "next/image"; -import { sinceUnixDate, unixToDate } from "#/api/utils"; - -export const ProfileActivityComment = (props: { - content: any; - profile_id: number; -}) => { - return ( - <> - {props.content && props.content.length > 0 ? - props.content.map((comment) => { - let isHidden = comment.isSpoiler || comment.likes_count < -5 || false; - return ( -
-
-
- - - {comment.profile.login} - -

- -

-

0 ? - "text-green-500 dark:text-green-400 border-green-500 dark:border-green-400" - : comment.likes_count < 0 ? - "text-red-500 dark:text-red-400 border-red-500 dark:border-red-400" - : "text-gray-500 dark:text-gray-400 border-gray-500 dark:border-gray-400" - }`} - > - {comment.likes_count} -

-
-
-
- {comment.release && typeof comment.release != "number" && ( - -

- {!comment.isDeleted ? - `К релизу: ${comment.release.title_ru || comment.release.title_alt || comment.release.title_original} (${comment.release.year || "?"}) >>` - : ""} -

- - )} -

- {!comment.isDeleted ? - comment.message - : "Комментарий был удалён."} -

- {isHidden && ( - - )} -
-
- ); - }) - :

Пользователь не оставлял комментарии

} - - ); -}; diff --git a/app/components/Profile/Profile.ActivityFriends.tsx b/app/components/Profile/Profile.ActivityFriends.tsx index 7f67712..78e2ac2 100644 --- a/app/components/Profile/Profile.ActivityFriends.tsx +++ b/app/components/Profile/Profile.ActivityFriends.tsx @@ -4,84 +4,67 @@ import "swiper/css/navigation"; import "swiper/css/mousewheel"; import "swiper/css/scrollbar"; import { Navigation, Mousewheel, Scrollbar } from "swiper/modules"; +import { CollectionLink } from "../CollectionLink/CollectionLink"; import Link from "next/link"; import { Avatar, Button } from "flowbite-react"; -import { useState } from "react"; -import { ProfileFriendModal } from "./Profile.FriendsModal"; - -export const ProfileActivityFriends = (props: { - content: any; - token: string; - isMyProfile: boolean; - profile_id: number; -}) => { - const [isFriendModalOpen, setIsFriendModalOpen] = useState(false); +export const ProfileActivityFriends = (props: { content: any }) => { return ( - <> -
- - {props.content && - props.content.length > 0 && - props.content.map((profile) => { - return ( - - -
- -

{profile.login}

-
- -
- ); - })} - {(props.content && props.content.length > 0) || props.isMyProfile ? - - - - :

У пользователя нет друзей

} -
-
- - +
+ + {props.content && + props.content.length > 0 && + props.content.map((profile) => { + return ( + + +
+ +

{profile.login}

+
+ +
+ ); + })} + {props.content && props.content.length > 0 ? + + + + :

У пользователя нет друзей

} +
+
); }; diff --git a/app/components/Profile/Profile.FriendsModal.tsx b/app/components/Profile/Profile.FriendsModal.tsx deleted file mode 100644 index fed9122..0000000 --- a/app/components/Profile/Profile.FriendsModal.tsx +++ /dev/null @@ -1,346 +0,0 @@ -import { ENDPOINTS } from "#/api/config"; -import { tryCatchAPI, unixToDate, useSWRfetcher } from "#/api/utils"; -import { - Avatar, - Button, - Modal, - ModalHeader, - useThemeMode, -} from "flowbite-react"; -import { useCallback, useEffect, useState } from "react"; -import useSWRInfinite from "swr/infinite"; -import { Spinner } from "../Spinner/Spinner"; -import { toast } from "react-toastify"; -import useSWR, { mutate } from "swr"; -import Link from "next/link"; - -export const ProfileFriendModal = (props: { - isOpen: boolean; - setIsOpen: (isOpen: boolean) => void; - token: string; - isMyProfile: boolean; - profile_id: number; -}) => { - const [currentRef, setCurrentRef] = useState(null); - const theme = useThemeMode(); - const [actionsDisabled, setActionsDisabled] = useState(false); - // const [requestInUsers, setRequestInUsers] = useState([]); - // const [requestOutUsers, setRequestOutUsers] = useState([]); - const [friends, setFriends] = useState([]); - - const modalRef = useCallback((ref) => { - setCurrentRef(ref); - }, []); - - const useFetchRequests = (url: string) => { - const { data, error, isLoading } = useSWR(url, useSWRfetcher); - return [data, error, isLoading]; - }; - - const [requestInUsersData, requestInUsersError, requestInUsersIsLoading] = - useFetchRequests( - props.isMyProfile ? - `${ENDPOINTS.user.friend.in}/last?token=${props.token}&count=8` - : "" - ); - - const [requestOutUsersData, requestOutUsersError, requestOutUsersIsLoading] = - useFetchRequests( - props.isMyProfile ? - `${ENDPOINTS.user.friend.out}/last?token=${props.token}&count=8` - : "" - ); - - async function _hideRequestIn(profile_id) { - const tid = toast.loading("Скрываем заявку...", { - position: "bottom-center", - hideProgressBar: true, - closeOnClick: false, - pauseOnHover: false, - draggable: false, - theme: theme.mode == "light" ? "light" : "dark", - }); - - let url = `${ENDPOINTS.user.friend.hide}/${profile_id}?token=${props.token}`; - const { data, error } = await tryCatchAPI(fetch(url)); - if (error) { - toast.update(tid, { - render: "Ошибка скрытия заявки", - type: "error", - autoClose: 2500, - isLoading: false, - closeOnClick: true, - draggable: true, - }); - return; - } - - toast.update(tid, { - render: "Заявка скрыта", - type: "success", - autoClose: 2500, - isLoading: false, - closeOnClick: true, - draggable: true, - }); - mutate(`${ENDPOINTS.user.friend.in}/last?token=${props.token}&count=8`); - } - - async function _acceptRequestIn(profile_id) { - const tid = toast.loading("Принимаем запрос...", { - position: "bottom-center", - hideProgressBar: true, - closeOnClick: false, - pauseOnHover: false, - draggable: false, - theme: theme.mode == "light" ? "light" : "dark", - }); - - let url = `${ENDPOINTS.user.friend.add}/${profile_id}?token=${props.token}`; - const { data, error } = await tryCatchAPI(fetch(url)); - if (error) { - toast.update(tid, { - render: "Ошибка приёма запроса", - type: "error", - autoClose: 2500, - isLoading: false, - closeOnClick: true, - draggable: true, - }); - return; - } - - toast.update(tid, { - render: "Запрос принят", - type: "success", - autoClose: 2500, - isLoading: false, - closeOnClick: true, - draggable: true, - }); - mutate(`${ENDPOINTS.user.friend.in}/last?token=${props.token}&count=8`); - } - - async function _cancelRequestOut(profile_id) { - const tid = toast.loading("Отменяем запрос...", { - position: "bottom-center", - hideProgressBar: true, - closeOnClick: false, - pauseOnHover: false, - draggable: false, - theme: theme.mode == "light" ? "light" : "dark", - }); - - let url = `${ENDPOINTS.user.friend.remove}/${profile_id}?token=${props.token}`; - const { data, error } = await tryCatchAPI(fetch(url)); - if (error) { - toast.update(tid, { - render: "Ошибка отмена запроса", - type: "error", - autoClose: 2500, - isLoading: false, - closeOnClick: true, - draggable: true, - }); - return; - } - - toast.update(tid, { - render: "Запрос отменён", - type: "success", - autoClose: 2500, - isLoading: false, - closeOnClick: true, - draggable: true, - }); - mutate(`${ENDPOINTS.user.friend.out}/last?token=${props.token}&count=8`); - } - - const getKey = (pageIndex: number, previousPageData: any) => { - if (previousPageData && !previousPageData.content.length) return null; - let url = `${ENDPOINTS.user.friend.list}/${props.profile_id}/${pageIndex}?token=${props.token}`; - return url; - }; - - const { data, error, isLoading, size, setSize } = useSWRInfinite( - getKey, - useSWRfetcher, - { initialSize: 2 } - ); - - useEffect(() => { - if (data) { - let allFriends = []; - for (let i = 0; i < data.length; i++) { - allFriends.push(...data[i].content); - } - setFriends(allFriends); - } - }, [data]); - - const [scrollPosition, setScrollPosition] = useState(0); - function handleScroll() { - const height = currentRef.scrollHeight - currentRef.clientHeight; - const windowScroll = currentRef.scrollTop; - const scrolled = (windowScroll / height) * 100; - setScrollPosition(Math.floor(scrolled)); - } - - useEffect(() => { - if (scrollPosition >= 95 && scrollPosition <= 96) { - setSize(size + 1); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [scrollPosition]); - - return ( - <> - props.setIsOpen(false)} - size={"4xl"} - > - Друзья -
- {props.isMyProfile && ( - <> -
-

Входящие заявки

- {( - requestInUsersData && - requestInUsersData.content && - requestInUsersData.content.length > 0 - ) ? - requestInUsersData.content.map((user) => { - return ( -
- -
- -
-

- {user.login} -

-

Друзей: {user.friend_count}

-
-
- -
- - -
-
- ); - }) - :

Нет входящих заявок

} -
-
-

Исходящие заявки

- {( - requestOutUsersData && - requestOutUsersData.content && - requestOutUsersData.content.length > 0 - ) ? - requestOutUsersData.content.map((user) => { - return ( -
- -
- -
-

- {user.login} -

-

Друзей: {user.friend_count}

-
-
- -
- -
-
- ); - }) - :

Нет исходящих заявок

} -
- - )} -
-

Все друзья

- {friends && friends.length > 0 ? - friends.map((user) => { - return ( -
- -
- -
-

{user.login}

-

Друзей: {user.friend_count}

-
-
- -
- ); - }) - :

Нет друзей

} -
- {isLoading && } -
-
- - ); -}; diff --git a/app/pages/Profile.tsx b/app/pages/Profile.tsx index fdd44b4..5721be6 100644 --- a/app/pages/Profile.tsx +++ b/app/pages/Profile.tsx @@ -129,13 +129,11 @@ export const ProfilePage = (props: any) => { )} {!user.is_stats_hidden && (