From ecf1c971f6021dd6c3ccbb497bb991044db7a37d Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Tue, 27 Aug 2024 15:07:32 +0500 Subject: [PATCH] feat: add user block action and banner if user is blocked by another user --- app/components/Profile/Profile.Actions.tsx | 80 ++++++++++++------- .../Profile/Profile.PrivacyBanner.tsx | 18 ++++- app/components/Profile/Profile.User.tsx | 2 +- app/pages/Profile.tsx | 4 +- 4 files changed, 71 insertions(+), 33 deletions(-) diff --git a/app/components/Profile/Profile.Actions.tsx b/app/components/Profile/Profile.Actions.tsx index 5b2a1e4..3ee6c83 100644 --- a/app/components/Profile/Profile.Actions.tsx +++ b/app/components/Profile/Profile.Actions.tsx @@ -18,12 +18,13 @@ export const ProfileActions = (props: { my_profile_id: number; friendStatus: number; token: string; + is_me_blocked: boolean; + is_blocked: boolean; }) => { const router = useRouter(); - const z2 = props.my_profile_id < props.profile_id; - let profileIdIsSmaller = z2 ? true : false; - - const [friendRequestDisabled, setfriendRequestDisabled] = useState(false); + const profileIdIsSmaller = props.my_profile_id < props.profile_id; + const [friendRequestDisabled, setFriendRequestDisabled] = useState(false); + const [blockRequestDisabled, setBlockRequestDisabled] = useState(false); function _getFriendStatus() { const num = props.friendStatus; @@ -35,8 +36,9 @@ export const ProfileActions = (props: { if (num == 2) { return 1; } - let z3 = (num == 0 && z2) || (num == 1 && !z2); - if ((num != 1 || z2) && (num != 0 || !z2)) { + let z3 = + (num == 0 && profileIdIsSmaller) || (num == 1 && !profileIdIsSmaller); + if ((num != 1 || profileIdIsSmaller) && (num != 0 || !profileIdIsSmaller)) { z = false; } if (z3) { @@ -58,7 +60,8 @@ export const ProfileActions = (props: { function _addToFriends() { let url = `${ENDPOINTS.user.profile}/friend/request`; - setfriendRequestDisabled(true); + setFriendRequestDisabled(true); + setBlockRequestDisabled(true); FriendStatus == 1 ? (url += "/remove/") @@ -70,7 +73,22 @@ export const ProfileActions = (props: { fetch(url).then((res) => { setTimeout(() => { window.location.reload(); - }, 1000); + }, 100); + }); + } + + function _addToBlocklist() { + let url = `${ENDPOINTS.user.profile}/blocklist`; + setBlockRequestDisabled(true); + setFriendRequestDisabled(true); + + !props.is_blocked ? (url += "/add/") : (url += "/remove/"); + + url += `${props.profile_id}?token=${props.token}`; + fetch(url).then((res) => { + setTimeout(() => { + window.location.reload(); + }, 100); }); } @@ -85,26 +103,34 @@ export const ProfileActions = (props: { <> {(!props.isFriendRequestsDisallowed || FriendStatus == 1 || - isRequestedStatus) && ( - - )} - + ? "Заявка отправлена" + : "Добавить в друзья"} + + )} + )} diff --git a/app/components/Profile/Profile.PrivacyBanner.tsx b/app/components/Profile/Profile.PrivacyBanner.tsx index eb6e807..cc99ff5 100644 --- a/app/components/Profile/Profile.PrivacyBanner.tsx +++ b/app/components/Profile/Profile.PrivacyBanner.tsx @@ -1,12 +1,22 @@ -export const ProfilePrivacyBanner = (props: { is_privacy: boolean }) => { +export const ProfilePrivacyBanner = (props: { + is_privacy: boolean; + is_me_blocked: boolean; +}) => { return ( <> {props.is_privacy && ( -
+

- У пользователя установлены настройки приватности. Некоторая - информация для вас может быть недоступна. + {!props.is_me_blocked + ? "У пользователя установлены настройки приватности. Некоторая информация для вас может быть недоступна." + : "Вы заблокированы данным пользователем. Его информация для вас не доступна."}

diff --git a/app/components/Profile/Profile.User.tsx b/app/components/Profile/Profile.User.tsx index afc9a1a..2cdaa99 100644 --- a/app/components/Profile/Profile.User.tsx +++ b/app/components/Profile/Profile.User.tsx @@ -48,7 +48,7 @@ export const ProfileUser = (props: { )} {props.chips.isBlocked && ( - + )} {props.chips.roles && props.chips.roles.length > 0 && diff --git a/app/pages/Profile.tsx b/app/pages/Profile.tsx index a9e9276..bbcf197 100644 --- a/app/pages/Profile.tsx +++ b/app/pages/Profile.tsx @@ -98,7 +98,7 @@ export const ProfilePage = (props: any) => { ban_reason={user.ban_reason} ban_expires={user.ban_expires} /> - +
{ friendStatus={user.friend_status} my_profile_id={authUser.user.id} token={authUser.token} + is_me_blocked={user.is_me_blocked} + is_blocked={user.is_blocked} /> )} {!user.is_stats_hidden && (