Skip to content

Commit

Permalink
fix: send a heart error (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeungJL authored Apr 24, 2024
2 parents f2feb48 + 001aeae commit fa27818
Showing 1 changed file with 29 additions and 32 deletions.
61 changes: 29 additions & 32 deletions pageTemplates/profile/profileOverview/ProfileInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { faHeart as faSolidHeart } from "@fortawesome/pro-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import dayjs from "dayjs";
import { useSession } from "next-auth/react";
import { useState } from "react";
import styled from "styled-components";

import Avatar from "../../../components/atoms/Avatar";
Expand All @@ -15,7 +14,6 @@ import { USER_ROLE } from "../../../constants/settingValue/role";
import { useAdminPointMutation } from "../../../hooks/admin/mutation";
import { useResetQueryData } from "../../../hooks/custom/CustomHooks";
import { useCompleteToast, useErrorToast, useFailToast } from "../../../hooks/custom/CustomToast";
import { useStudyAttendRecordQuery } from "../../../hooks/study/queries";
import { useUserInfoQuery } from "../../../hooks/user/queries";
import { useInteractionMutation } from "../../../hooks/user/sub/interaction/mutations";
import { IInteractionLikeStorage, IInteractionSendLike } from "../../../types/globals/interaction";
Expand All @@ -34,8 +32,8 @@ function ProfileInfo({ user }: IProfileInfo) {

const { data: userInfo } = useUserInfoQuery();

const [isConditionOk, setIsConditionOk] = useState(false);
const [isHeartLoading, setIsHeartLoading] = useState(true);
// const [isConditionOk, setIsConditionOk] = useState(false);
// const [isHeartLoading, setIsHeartLoading] = useState(true);

const status = USER_ROLE[user?.role];
const storedLikeArr: IInteractionLikeStorage[] = JSON.parse(localStorage.getItem(LIKE_HEART));
Expand All @@ -58,45 +56,44 @@ function ProfileInfo({ user }: IProfileInfo) {

const { mutate: sendAboutPoint } = useAdminPointMutation(user?.uid);

useStudyAttendRecordQuery(dayjs().subtract(4, "day"), dayjs().add(1, "day"), {
enabled: !isGuest,
onSuccess(data) {
data.forEach((study) => {
study.arrivedInfoList.forEach((arrivedInfoList) => {
const bothAttend = arrivedInfoList.arrivedInfo.filter(
(item) => item.uid === user.uid || item.uid === session.user.uid,
);
if (bothAttend.length >= 2) {
setIsConditionOk(true);
}
});
});
setIsHeartLoading(false);
},
});
// useStudyAttendRecordQuery(dayjs().subtract(4, "day"), dayjs().add(1, "day"), {
// enabled: !isGuest,
// onSuccess(data) {
// data.forEach((study) => {
// study.arrivedInfoList.forEach((arrivedInfoList) => {
// const bothAttend = arrivedInfoList.arrivedInfo.filter(
// (item) => item.uid === user.uid || item.uid === session.user.uid,
// );
// if (bothAttend.length >= 2) {
// setIsConditionOk(true);
// }
// });
// });
// setIsHeartLoading(false);
// },
// });

const onClickHeart = () => {
if (isGuest) {
failToast("free", "게스트에게는 불가능합니다.");
return;
}
if (isHeart) return;
// eslint-disable-next-line prefer-const
let interval;
const checkCondition = () => {
if (isHeartLoading) return;
clearInterval(interval);
handleHeart();
};
handleHeart();

// let interval;
// const checkCondition = () => {
// if (isHeartLoading) return;
// clearInterval(interval);
// handleHeart();
// };

interval = setInterval(checkCondition, 100);
// interval = setInterval(checkCondition, 100);
};

const handleHeart = () => {
if (
!userInfo?.friend.includes(user?.uid) &&
!isConditionOk &&
user.birth.slice(2) !== dayjs().format("MMDD")
) {
if (!userInfo?.friend.includes(user?.uid) && user.birth.slice(2) !== dayjs().format("MMDD")) {
failToast(
"free",
"최근 같은 스터디에 참여한 멤버 또는 친구로 등록된 인원, 생일인 인원에게만 보낼 수 있어요!",
Expand Down

0 comments on commit fa27818

Please sign in to comment.