필수입력사항입니다!
diff --git a/apps/client/src/components/PleaseTitle.tsx b/apps/client/src/components/PleaseTitle.tsx
new file mode 100644
index 0000000..275bed9
--- /dev/null
+++ b/apps/client/src/components/PleaseTitle.tsx
@@ -0,0 +1,27 @@
+import React from "react";
+import {
+ ModalOverlay,
+ ModalContent,
+ CloseButton,
+ Title,
+ Description,
+ Buttons
+} from "../app/style/Modal"
+
+interface ModalProps {
+ onClose: () => void;
+}
+
+export default function PleaseTitle({ onClose }: ModalProps) {
+ return (
+
+
+ 안내
+ AI 선지 추천을 사용하시려면 투표제목을 입력해주세요.
+
+ 확인
+
+
+
+ );
+}
From 855854b4c9637ad531257f94680c83c67cb97ec6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EA=B9=80=ED=83=9C=ED=98=84?=
<143389711+taehyun00@users.noreply.github.com>
Date: Mon, 14 Jul 2025 09:27:17 +0900
Subject: [PATCH 09/11] refactor :: backend connect code refact
---
apps/client/src/app/component/votepage.tsx | 17 ++++----
apps/client/src/app/mutations.js | 17 ++++++++
apps/client/src/app/tailvote/page.tsx | 20 ++++++++--
apps/client/src/app/votemake/page.tsx | 1 -
apps/client/src/app/votemenu/page.tsx | 46 +++++++++++++++++++---
5 files changed, 83 insertions(+), 18 deletions(-)
diff --git a/apps/client/src/app/component/votepage.tsx b/apps/client/src/app/component/votepage.tsx
index d828121..22d1fd1 100644
--- a/apps/client/src/app/component/votepage.tsx
+++ b/apps/client/src/app/component/votepage.tsx
@@ -10,11 +10,11 @@ import {
DateText,
InfoWrapper,
TitleText,
- MenuWrapper
+ MenuWrapper,
} from "../style/votepage";
-import { useQuery } from '@apollo/client';
-import { GET_ALL_VOTES } from '../queries';
+import { useQuery } from "@apollo/client";
+import { GET_ALL_VOTES } from "../queries";
export default function Votepage() {
const { loading, error, data } = useQuery(GET_ALL_VOTES);
@@ -23,12 +23,9 @@ export default function Votepage() {
if (error) return
에러 발생: {error.message}
;
if (!data?.vote?.getAllVotes) return
투표 데이터 없음
;
-
-
return (
{data.vote.getAllVotes.map((vote: any) => (
-
@@ -43,8 +40,12 @@ export default function Votepage() {
-
-
+
+
))}
diff --git a/apps/client/src/app/mutations.js b/apps/client/src/app/mutations.js
index 786c46d..4b9893f 100644
--- a/apps/client/src/app/mutations.js
+++ b/apps/client/src/app/mutations.js
@@ -7,4 +7,21 @@ export const POST_VOTE = gql`
}
}
}
+`;
+
+
+export const POST_VOTERESUlT = gql`
+mutation MyMutation($voteId : ID!,$optionId : ID!) {
+ voteResponse {
+ createVoteResponse(input: {voteId: $voteId, optionId: $optionId}) {
+ id
+ optionContent
+ optionId
+ userId
+ voteTitle
+ voteId
+ createdAt
+ }
+ }
+}
`;
\ No newline at end of file
diff --git a/apps/client/src/app/tailvote/page.tsx b/apps/client/src/app/tailvote/page.tsx
index 2e4f3b2..8456007 100644
--- a/apps/client/src/app/tailvote/page.tsx
+++ b/apps/client/src/app/tailvote/page.tsx
@@ -2,6 +2,7 @@
import React, { useState } from "react";
import Tailvote_modal from "../Tailvote_modal/page";
import { useRouter } from "next/navigation";
+import { useSearchParams } from "next/navigation";
import {
Overlay,
Wrapper,
@@ -18,9 +19,22 @@ import {
} from "../style/Tailvote";
export default function Tailvote() {
- const category = "재미질문 > 꼬리질문1";
- const title = "그 존재가 가장 무서운 이유는 무엇인가요?";
- const date = "2025-05-23";
+ const searchParams = useSearchParams();
+ const choseoption = searchParams.get("choseoptions");
+ const fihishedAt = searchParams.get("fihishedAt");
+ let datas = null;
+ if(choseoption != null){
+ datas = JSON.parse(choseoption);
+
+ }
+ console.log(datas.voteResponse.createVoteResponse.optionContent)
+ const choseoptions = datas.voteResponse.createVoteResponse.optionContent
+
+ const category = "재미질문 > 꼬리질문";
+ const title = choseoptions + "을(를) 선택한 이유는 무엇인가요?";
+ const date = fihishedAt;
+
+ console.log(date)
const [textcontext, changetext] = useState("");
const [modalOpen, setModalOpen] = useState(false);
diff --git a/apps/client/src/app/votemake/page.tsx b/apps/client/src/app/votemake/page.tsx
index a9722ec..4579499 100644
--- a/apps/client/src/app/votemake/page.tsx
+++ b/apps/client/src/app/votemake/page.tsx
@@ -14,7 +14,6 @@ import {
Container,
TitleWrapper,
TitleInputWrapper,
- TitleLabel,
TitleInput,
OptionsWrapper,
OptionRow,
diff --git a/apps/client/src/app/votemenu/page.tsx b/apps/client/src/app/votemenu/page.tsx
index 4b67ff1..fbacbd4 100644
--- a/apps/client/src/app/votemenu/page.tsx
+++ b/apps/client/src/app/votemenu/page.tsx
@@ -2,6 +2,8 @@
import { useState } from "react";
import { useRouter } from "next/navigation";
+import { useSearchParams } from "next/navigation";
+
import {
Container,
VoteOption,
@@ -10,20 +12,51 @@ import {
SubmitButton,
} from "../style/Votemenu";
+import { useMutation } from "@apollo/client";
+import { POST_VOTERESUlT } from "../mutations";
-export default function Votemenu({ options }: { options: any[] }) {
-
+export default function Votemenu({
+ options,
+ voteid,
+ votefihishedAt
+}: {
+ options: any[];
+ voteid: string;
+ votefihishedAt: string // voteid를 문자열로 전달받음
+}) {
+ const searchParams = useSearchParams();
const navigate = useRouter();
const [selected, setSelected] = useState(null);
+ const [postVoteResult] = useMutation(POST_VOTERESUlT);
+
const handleChange = (index: number) => {
setSelected((prev) => (prev === index ? null : index));
};
- const voting = () => {
+ const voting = async () => {
if (selected !== null) {
- setSelected(null);
- navigate.push("/tailvote");
+ const selectedOption = options[selected]; // 선택된 옵션 가져오기
+ try {
+ console.log(voteid)
+ console.log(selectedOption.id)
+ const response = await postVoteResult({
+ variables: {
+ voteId : voteid, // 전달받은 voteid 사용
+ optionId: selectedOption.id, // 선택된 옵션 ID 전달
+ },
+ });
+ console.log("투표 성공:", response.data);
+ setSelected(null);
+ const query = new URLSearchParams({
+ choseoptions : JSON.stringify(response.data),
+ fihishedAt : String(votefihishedAt)
+ });
+ navigate.push(`/tailvote?${query}`);
+
+ } catch (error) {
+ console.error("투표 실패:", error);
+ }
} else {
alert("투표하고 진행해주세요");
}
@@ -48,7 +81,8 @@ export default function Votemenu({ options }: { options: any[] }) {
checked={selected === index}
onChange={() => handleChange(index)}
/>
- {item.content}
+ {item.content}
+ {item.id}
))}
From 78f1a4263e34d70bed0ff9d2deed2d8bdb936f8f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EA=B9=80=ED=83=9C=ED=98=84?=
<143389711+taehyun00@users.noreply.github.com>
Date: Mon, 14 Jul 2025 14:40:09 +0900
Subject: [PATCH 10/11] refactor :: backend connect code refact
---
apps/client/src/app/apolloClient.ts | 10 ++
apps/client/src/app/component/votepage.tsx | 104 +++++++++++++++------
apps/client/src/app/queries.js | 10 ++
apps/client/src/app/style/votepage.ts | 17 ++++
apps/client/src/app/success/page.tsx | 2 +-
apps/client/src/app/votemenu/page.tsx | 1 -
6 files changed, 114 insertions(+), 30 deletions(-)
create mode 100644 apps/client/src/app/apolloClient.ts
diff --git a/apps/client/src/app/apolloClient.ts b/apps/client/src/app/apolloClient.ts
new file mode 100644
index 0000000..68d3a28
--- /dev/null
+++ b/apps/client/src/app/apolloClient.ts
@@ -0,0 +1,10 @@
+// src/apolloClient.ts
+
+import { ApolloClient, InMemoryCache } from "@apollo/client";
+
+const client = new ApolloClient({
+ uri: "http://10.150.149.229:8080/graphql", // GraphQL API 엔드포인트
+ cache: new InMemoryCache(),
+});
+
+export default client;
diff --git a/apps/client/src/app/component/votepage.tsx b/apps/client/src/app/component/votepage.tsx
index 22d1fd1..83e53c4 100644
--- a/apps/client/src/app/component/votepage.tsx
+++ b/apps/client/src/app/component/votepage.tsx
@@ -1,4 +1,6 @@
"use client";
+import client from "../apolloClient";
+import { useState, useEffect } from "react";
import Votemenu from "../votemenu/page";
import {
@@ -11,43 +13,89 @@ import {
InfoWrapper,
TitleText,
MenuWrapper,
+ ALERDYTitleText,
+ ALERDYCard
} from "../style/votepage";
import { useQuery } from "@apollo/client";
-import { GET_ALL_VOTES } from "../queries";
+import { GET_ALL_VOTES, HAS_VOTED } from "../queries";
export default function Votepage() {
- const { loading, error, data } = useQuery(GET_ALL_VOTES);
+ const { loading: loadingVotes, error: errorVotes, data: dataVotes } = useQuery(GET_ALL_VOTES);
+ const [hasUserVotedResults, setHasUserVotedResults] = useState([]);
- if (loading) return 로딩 중...
;
- if (error) return 에러 발생: {error.message}
;
- if (!data?.vote?.getAllVotes) return 투표 데이터 없음
;
+ // 비동기적으로 투표 여부를 확인하여 상태 업데이트
+ useEffect(() => {
+ if (dataVotes?.vote?.getAllVotes?.length) {
+ const fetchVoteStatuses = async () => {
+ const results: boolean[] = [];
+ for (const vote of dataVotes.vote.getAllVotes) {
+ if (vote?.id) {
+ try {
+ const response = await client.query({
+ query: HAS_VOTED,
+ variables: {
+ votedId: vote.id,
+ },
+ });
+ results.push(response.data.voteResponse.hasUserVoted);
+ } catch (error) {
+
+
+ }
+ } else {
+ console.warn(`Invalid vote object detected:`, vote);
+ // 유효하지 않은 객체에 기본 값 추가
+ }
+ }
+ setHasUserVotedResults(results); // 모든 결과를 한 번에 상태 업데이트
+ };
+
+ fetchVoteStatuses();
+ }
+ }, [dataVotes]);
+
+ if (loadingVotes) return 로딩 중...
;
+ if (errorVotes) return 에러 발생: {errorVotes.message}
;
+ if (!dataVotes?.vote?.getAllVotes) return 투표 데이터 없음
;
+
+
+
return (
- {data.vote.getAllVotes.map((vote: any) => (
-
-
-
- {vote.category}
-
- {vote.title}
-
- {vote.finishedAt} 투표마감
-
-
-
-
-
-
-
-
-
-
+ {dataVotes.vote.getAllVotes.map((vote: any, i: number) => (
+ hasUserVotedResults[i++] === false ? (
+ // 투표하지 않은 경우
+
+
+
+ {vote.category}
+
+ {vote.title}
+
+ {vote.finishedAt} 투표마감
+
+
+
+
+
+
+
+
+
+ ) : (
+ // 이미 투표한 경우
+
+ )
))}
);
diff --git a/apps/client/src/app/queries.js b/apps/client/src/app/queries.js
index 9e4bf4c..a5b40bd 100644
--- a/apps/client/src/app/queries.js
+++ b/apps/client/src/app/queries.js
@@ -28,4 +28,14 @@ query MyQuery($count: Int!, $title: String!) {
}
}
}
+`;
+
+
+
+export const HAS_VOTED = gql`
+query MyQuery($votedId : ID!) {
+ voteResponse {
+ hasUserVoted(voteId: $votedId)
+ }
+}
`;
\ No newline at end of file
diff --git a/apps/client/src/app/style/votepage.ts b/apps/client/src/app/style/votepage.ts
index d5fa60d..5d66cc4 100644
--- a/apps/client/src/app/style/votepage.ts
+++ b/apps/client/src/app/style/votepage.ts
@@ -7,6 +7,17 @@ export const Container = styled.div`
`;
export const Card = styled.div`
+ border-radius : 10px;
+ background-color: #FFFFFF;
+ width: 120vh;
+ height: 60vh;
+`;
+
+export const ALERDYCard = styled.div`
+ display : flex;
+ align-items : center;
+ justify-content : center;
+ border-radius : 10px;
background-color: #FFFFFF;
width: 120vh;
height: 60vh;
@@ -36,6 +47,12 @@ export const TitleText = styled.p`
font-size: 3vh;
`;
+export const ALERDYTitleText = styled.p`
+ color: #000000;
+ font-family: 'P_Regular';
+ font-size: 3vh;
+`;
+
export const DateWrapper = styled.div`
position: absolute;
top: 4vh;
diff --git a/apps/client/src/app/success/page.tsx b/apps/client/src/app/success/page.tsx
index b038c65..db816da 100644
--- a/apps/client/src/app/success/page.tsx
+++ b/apps/client/src/app/success/page.tsx
@@ -24,7 +24,7 @@ export default function Endvote() {
const [post_vote, { loading, error }] = useMutation(POST_VOTE);
const router = useRouter();
- const category = searchParams.get("catego") as string || ""; // 변수명 맞춤
+ const category = searchParams.get("category") as string || ""; // 변수명 맞춤
const title = searchParams.get("title") as string || "";
const optionsss = searchParams.get("options");
diff --git a/apps/client/src/app/votemenu/page.tsx b/apps/client/src/app/votemenu/page.tsx
index fbacbd4..5c66e1e 100644
--- a/apps/client/src/app/votemenu/page.tsx
+++ b/apps/client/src/app/votemenu/page.tsx
@@ -82,7 +82,6 @@ export default function Votemenu({
onChange={() => handleChange(index)}
/>
{item.content}
- {item.id}
))}
From 9bd57a63e312c5ecce3ca8bec3a7c252e87d9913 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EA=B9=80=ED=83=9C=ED=98=84?=
<143389711+taehyun00@users.noreply.github.com>
Date: Mon, 14 Jul 2025 14:51:07 +0900
Subject: [PATCH 11/11] refactor :: env file set
---
apps/client/src/app/apolloClient.ts | 2 +-
apps/client/src/app/layout.tsx | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/apps/client/src/app/apolloClient.ts b/apps/client/src/app/apolloClient.ts
index 68d3a28..bbe3680 100644
--- a/apps/client/src/app/apolloClient.ts
+++ b/apps/client/src/app/apolloClient.ts
@@ -3,7 +3,7 @@
import { ApolloClient, InMemoryCache } from "@apollo/client";
const client = new ApolloClient({
- uri: "http://10.150.149.229:8080/graphql", // GraphQL API 엔드포인트
+ uri: process.env.NEXT_PUBLIC_BACKEND_URL, // GraphQL API 엔드포인트
cache: new InMemoryCache(),
});
diff --git a/apps/client/src/app/layout.tsx b/apps/client/src/app/layout.tsx
index 96e9c5f..4774fd3 100644
--- a/apps/client/src/app/layout.tsx
+++ b/apps/client/src/app/layout.tsx
@@ -10,7 +10,7 @@ import {
const client = new ApolloClient({
- uri: 'http://10.150.149.229:8080/graphql',
+ uri: process.env.NEXT_PUBLIC_BACKEND_URL,
cache: new InMemoryCache(),
});