Skip to content

Commit 10bd9ab

Browse files
authored
Merge pull request #34 from OpenKetchupSource/feat/33
Feat/33 : 직접 작성 일기 api 연결
2 parents b5fcca9 + 8e3a76b commit 10bd9ab

File tree

6 files changed

+70
-6
lines changed

6 files changed

+70
-6
lines changed

index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/images/icon.png" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<meta property="og:image" content="/images/meta.png" />
8-
<meta property="og:title" content="SoulMate" />
9-
<meta property="og:description" content="매일 마음을 기록하는 나만의 AI 친구, Soulmate" />
7+
<meta property="og:image" content="/images/meta.png" />
8+
<meta property="og:title" content="SoulMate" />
9+
<meta
10+
property="og:description"
11+
content="매일 마음을 기록하는 나만의 AI 친구, Soulmate"
12+
/>
1013
<link rel="preconnect" href="https://fonts.googleapis.com" />
1114
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1215
<link

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import ChatPage from "./pages/chatting/ChatPage";
1111
import styled from "styled-components";
1212
import WritingPage from "./pages/writing/WritingPage";
1313
import Testpage from "./pages/Testpage";
14+
import EditPage from "./pages/writing/EditPage";
1415

1516
function App() {
1617
return (
@@ -24,6 +25,7 @@ function App() {
2425
<Route path="/setChatting" element={<SettingPage />} />
2526
<Route path="/chat/:chatId/:character" element={<ChatPage />} />
2627
<Route path="/writing" element={<WritingPage />} />
28+
<Route path="/edit/:chatId" element={<EditPage />} />
2729

2830
<Route path="/comments" element={<Comments />} />
2931
<Route path="/hashtags" element={<Hashtags />} />

src/pages/DiaryDetail.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import styled from "styled-components";
2-
import { IoHomeOutline } from "react-icons/io5";
2+
import { IoHomeOutline, IoTrashBinOutline } from "react-icons/io5";
33
import { BsPencil } from "react-icons/bs";
44
import { useNavigate, useParams } from "react-router-dom";
55
import { useEffect, useState } from "react";
@@ -62,7 +62,9 @@ const DiaryDetail = () => {
6262
<Header>
6363
<HomeIcon onClick={() => navigate("/")} />
6464
<DateText>{formatDate(diary.date)}</DateText>
65-
<EditIcon onClick={() => navigate(`/edit/${diary.id}`)} />
65+
<TrashIcon onClick={() => alert("삭제 기능은 준비 중입니다.")} />
66+
<EditIcon onClick={() => alert("수정 기능은 준비 중입니다.")} />
67+
{/* <EditIcon onClick={() => navigate(`/edit/${diary.id}`)} /> */}
6668
</Header>
6769

6870
<Body>
@@ -127,6 +129,16 @@ const HomeIcon = styled(IoHomeOutline)`
127129
color: #1e2a52;
128130
`;
129131

132+
const TrashIcon = styled(IoTrashBinOutline)`
133+
position: absolute;
134+
top: 50%;
135+
right: 56px;
136+
transform: translateY(-50%);
137+
font-size: 20px;
138+
color: #1e2a52;
139+
size: 40px;
140+
`;
141+
130142
const EditIcon = styled(BsPencil)`
131143
position: absolute;
132144
top: 50%;

src/pages/writing/EditPage.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const EditPage = () => {
2+
return <div>일기 수정 기능은 준비 중입니다.</div>;
3+
};
4+
5+
export default EditPage;

src/pages/writing/WritingPage.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,40 @@ import styled from "styled-components";
33
import { BsArrowRight } from "react-icons/bs";
44
import { IoHomeOutline } from "react-icons/io5";
55
import { useNavigate } from "react-router-dom";
6+
import { postWritingDiary } from "../../services/apis/diary/writing";
67

78
const WritingPage = () => {
89
const [title, setTitle] = useState("");
910
const [tags, setTags] = useState("");
1011
const [content, setContent] = useState("");
1112
const navigate = useNavigate();
1213

14+
const handleSubmit = async () => {
15+
const confirmed = window.confirm("작성을 종료하시겠습니까?");
16+
if (!confirmed) return;
17+
try {
18+
const response = await postWritingDiary({
19+
date: "2025-05-30",
20+
title,
21+
content,
22+
hashtag: tags,
23+
character: "앙글이",
24+
});
25+
26+
// 예: 생성된 일기의 ID가 response.data.id에 있다고 가정
27+
navigate(`/diary/${response.data.id}`);
28+
} catch (error) {
29+
console.error("일기 저장 실패:", error);
30+
alert("일기 저장 중 오류가 발생했습니다.");
31+
}
32+
};
33+
1334
return (
1435
<Container>
1536
<Header>
1637
<HomeIcon onClick={() => navigate("/")} />
1738
<DateText>2025.05.01.</DateText>
18-
<ArrowIcon onClick={() => navigate("/diary/1")} />
39+
<ArrowIcon onClick={handleSubmit} />
1940
</Header>
2041
<Body>
2142
<TextInput

src/services/apis/diary/writing.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { CreateAxiosInstanceWithToken } from "../axiosInstanceWithToken";
2+
3+
const axiosInstanceWithToken = CreateAxiosInstanceWithToken();
4+
5+
export async function postWritingDiary(diaryData: {
6+
date: string;
7+
title: string;
8+
content: string;
9+
hashtag: string;
10+
character: string;
11+
}) {
12+
try {
13+
const response = await axiosInstanceWithToken.post(
14+
`/api/diary/create`,
15+
diaryData,
16+
);
17+
return response;
18+
} catch (error) {
19+
throw error;
20+
}
21+
}

0 commit comments

Comments
 (0)