Skip to content

Commit

Permalink
fix favorite error and renew login page
Browse files Browse the repository at this point in the history
  • Loading branch information
SeungJL committed Sep 26, 2024
1 parent 0738fc9 commit 7a22887
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
41 changes: 21 additions & 20 deletions components/molecules/cards/PostThumbnailCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Box, Flex } from "@chakra-ui/react";
import dayjs from "dayjs";
import { useSession } from "next-auth/react";
import Image from "next/image";
import Link from "next/link";
import { useEffect, useState } from "react";
import { useSession } from "next-auth/react";
import { useQueryClient } from "react-query";
import styled from "styled-components";

Expand Down Expand Up @@ -62,7 +61,9 @@ export function PostThumbnailCard({
const toast = useToast();
const isGuest = session?.user.name === "guest";

const { data: userInfo } = useUserInfoQuery({ enabled: isGuest === false });
const { data: userInfo, isLoading: userLoading } = useUserInfoQuery({
enabled: isGuest === false,
});
const preference = userInfo?.studyPreference;

const userAvatarArr = participants
Expand All @@ -72,19 +73,11 @@ export function PostThumbnailCard({
...(par.avatar?.type !== null ? { avatar: par.avatar } : {}),
}));

const CLOSED_TEXT_ARR = ["모집 마감", "닫힘"];

const [heartType, setHeartType] = useState<"main" | "sub" | null>();
const isMyPrefer = preference?.place === id || preference?.subPlace?.includes(id);

useEffect(() => {
if (!preference) return;
const { place, subPlace } = preference || { place: null, subPlace: [] };

if (place === id) setHeartType("main");
else if (subPlace?.includes(id)) setHeartType("sub");
}, [preference, id]);
const CLOSED_TEXT_ARR = ["모집 마감", "닫힘"];

const { mutate: patchStudyPreference } = useStudyPreferenceMutation("patch", {
const { mutate: patchStudyPreference, isLoading } = useStudyPreferenceMutation("patch", {
onSuccess() {
toast("success", "변경되었습니다.");
queryClient.refetchQueries([USER_INFO]);
Expand All @@ -93,13 +86,21 @@ export function PostThumbnailCard({

const toggleHeart = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
if (isLoading || userLoading) return;

const preferMain = preference?.place;

const preferenceType =
preference?.place === id
? "main"
: preference?.subPlace?.includes(id)
? "sub"
: preferMain
? "sub"
: "main";

const preferenceType = heartType || preference?.place ? "sub" : "main";
// const A =
// heartType === "first" ? "main" : heartType === "second" ? "sub" : preferMain ? "sub" : "main";
console.log(id, preferenceType);
patchStudyPreference({ id, type: preferenceType });
setHeartType(preferenceType);

queryClient.invalidateQueries([USER_INFO]);
};

Expand Down Expand Up @@ -131,7 +132,7 @@ export function PostThumbnailCard({
color="white"
onClick={toggleHeart}
>
{heartType ? (
{isMyPrefer ? (
<i className="fa-solid fa-heart fa-sm" />
) : (
<i className="fa-regular fa-heart fa-sm" />
Expand Down
2 changes: 1 addition & 1 deletion pageTemplates/home/HomeRecommendationSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function HomeRecommendationSection() {
enabled: !!userLocation || !!session?.user.location,
},
);
console.log(32, studyVoteData);

useEffect(() => {
if (studyVoteData) {
setStudyPairArr(studyVoteData);
Expand Down
5 changes: 1 addition & 4 deletions pageTemplates/home/study/HomeStudyCol.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ThemeTypings } from "@chakra-ui/react";
import dayjs from "dayjs";
import { useSession } from "next-auth/react";
import { useSearchParams } from "next/navigation";
import { useSession } from "next-auth/react";
import { useEffect, useState } from "react";
import { useRecoilValue } from "recoil";

Expand All @@ -17,7 +17,6 @@ import {
STUDY_DATE_START_HOUR,
STUDY_RESULT_HOUR,
} from "../../../constants/serviceConstants/studyConstants/studyTimeConstant";
import { useStudyResultDecideMutation } from "../../../hooks/study/mutations";
import StudyOpenCheckModal from "../../../modals/study/StudyOpenCheckModal";
import { studyDateStatusState } from "../../../recoils/studyRecoils";
import { IParticipation, StudyStatus } from "../../../types/models/studyTypes/studyDetails";
Expand Down Expand Up @@ -49,8 +48,6 @@ function HomeStudyCol({ studyVoteData, isLoading, date, isShort }: HomeStudyColP
const [studyCardColData, setStudyCardColData] = useState<IPostThumbnailCard[]>();
const [dismissedStudy, setDismissedStudy] = useState<IParticipation>();

const { mutate: decideStudyResult } = useStudyResultDecideMutation(date);

useEffect(() => {
if (!studyVoteData || !studyVoteData.length || !session?.user || !studyDateStatus) {
setStudyCardColData(null);
Expand Down
2 changes: 1 addition & 1 deletion pages/group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function GroupPage() {
function StatusSelector() {
return <Selector defaultValue={status} setValue={setStatus} options={["모집중", "종료"]} />;
}
console.log(24, myGroups);

return (
<>
<Header title="소모임" url="/home" isBack={false} />
Expand Down
Binary file modified public/loginBackground.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7a22887

Please sign in to comment.