diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9903a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cSpell.words": ["autoincrement"] +} diff --git a/app/create/page.tsx b/app/create/page.tsx index 8fc0afd..9eec296 100644 --- a/app/create/page.tsx +++ b/app/create/page.tsx @@ -1,27 +1,17 @@ "use client"; +import { createDiary } from "@/src/features/diary/actions/createDiary"; +import Moods from "@/src/features/diary/ui/moods"; import Link from "next/link"; -import { useState } from "react"; - -export default function CreateDiary() { - const [formData, setFormData] = useState({ - title: "", - content: "", - mood: "", - weather: "", - categoryId: "", - tags: "", - isPublic: false, - }); +import { useActionState, useEffect } from "react"; - const moods = [ - { value: "happy", label: "๐Ÿ˜Š ํ–‰๋ณต", emoji: "๐Ÿ˜Š" }, - { value: "sad", label: "๐Ÿ˜ข ์Šฌํ””", emoji: "๐Ÿ˜ข" }, - { value: "angry", label: "๐Ÿ˜  ํ™”๋‚จ", emoji: "๐Ÿ˜ " }, - { value: "excited", label: "๐Ÿคฉ ์‹ ๋‚จ", emoji: "๐Ÿคฉ" }, - { value: "calm", label: "๐Ÿ˜Œ ํ‰์˜จ", emoji: "๐Ÿ˜Œ" }, - { value: "nervous", label: "๐Ÿ˜ฐ ๊ธด์žฅ", emoji: "๐Ÿ˜ฐ" }, - ]; +const initialState = { + success: false, + message: "", +}; + +export default function CreateDiaryPage() { + const [state, formAction] = useActionState(createDiary, initialState); const weathers = [ { value: "sunny", label: "โ˜€๏ธ ๋ง‘์Œ", emoji: "โ˜€๏ธ" }, @@ -38,15 +28,12 @@ export default function CreateDiary() { { id: "5", name: "๊ฟˆ", color: "#F59E0B" }, ]; - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); - // ์‹ค์ œ ์ €์žฅ ๋กœ์ง์€ ๋‚˜์ค‘์— ๊ตฌํ˜„ - console.log("์ผ๊ธฐ ์ €์žฅ:", formData); - }; + useEffect(() => { + console.log(state); + }); return (
- {/* Navigation */}
- {/* Main Content */}

์ƒˆ๋กœ์šด ์ผ๊ธฐ ์ž‘์„ฑ

์˜ค๋Š˜์˜ ์†Œ์ค‘ํ•œ ์ˆœ๊ฐ„์„ ๊ธฐ๋กํ•ด๋ณด์„ธ์š”

-
+ + {/* ์ˆจ๊ฒจ์ง„ ํ•„์ˆ˜ ํ•„๋“œ๋“ค */} + +
- {/* Title */}
- + setFormData((prev) => ({ ...prev, title: e.target.value }))} placeholder="์˜ค๋Š˜์˜ ์ผ๊ธฐ ์ œ๋ชฉ์„ ์ž…๋ ฅํ•˜์„ธ์š”" className="w-full px-4 py-3 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white" required />
- {/* Mood & Weather */}
- {moods.map((mood) => ( - - ))} +
@@ -122,9 +89,8 @@ export default function CreateDiary() {
- {/* Content */}
- {/* Category */}
@@ -161,9 +123,8 @@ export default function CreateDiary() {
- {/* Tags */}
- {/* Public/Private */}

๊ณต๊ฐœ๋กœ ์„ค์ •ํ•˜๋ฉด ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๋“ค์ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค

- {/* Action Buttons */} + {/* ์„œ๋ฒ„ ์‘๋‹ต ์ƒํƒœ ํ‘œ์‹œ */} + {state.message && ( +
+

{state.message}

+
+ )} +
{ - "use server"; - // ์‚ญ์ œ ํ™•์ธ ๋ฐ ์‚ญ์ œ ๋กœ์ง - if (confirm("์ •๋ง๋กœ ์ด ์ผ๊ธฐ๋ฅผ ์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?")) { - console.log("์ผ๊ธฐ ์‚ญ์ œ"); - } - }; - return (
{/* Navigation */} @@ -83,9 +76,6 @@ export default function DiaryDetail({ params }: { params: { id: string } }) { ํ™ˆ - - ์†Œ๊ฐœ - โœ๏ธ ์ผ๊ธฐ ์“ฐ๊ธฐ @@ -150,7 +140,7 @@ export default function DiaryDetail({ params }: { params: { id: string } }) { โœ๏ธ ์ˆ˜์ • + ))} +
+ + ); +} diff --git a/src/app/db/db.ts b/src/shared/db/db.ts similarity index 100% rename from src/app/db/db.ts rename to src/shared/db/db.ts diff --git a/src/shared/libs/getMoodEmoji.ts b/src/shared/libs/getMoodEmoji.ts new file mode 100644 index 0000000..59c6533 --- /dev/null +++ b/src/shared/libs/getMoodEmoji.ts @@ -0,0 +1,11 @@ +export const getMoodEmoji = (mood: string) => { + const moodMap: { [key: string]: string } = { + happy: "๐Ÿ˜Š", + sad: "๐Ÿ˜ข", + angry: "๐Ÿ˜ ", + excited: "๐Ÿคฉ", + calm: "๐Ÿ˜Œ", + nervous: "๐Ÿ˜ฐ", + }; + return moodMap[mood] || "๐Ÿ˜"; +}; diff --git a/src/shared/libs/getWeatherEmoji.ts b/src/shared/libs/getWeatherEmoji.ts new file mode 100644 index 0000000..a66c347 --- /dev/null +++ b/src/shared/libs/getWeatherEmoji.ts @@ -0,0 +1,9 @@ +export const getWeatherEmoji = (weather: string) => { + const weatherMap: { [key: string]: string } = { + sunny: "โ˜€๏ธ", + rainy: "๐ŸŒง๏ธ", + cloudy: "โ˜๏ธ", + snowy: "โ„๏ธ", + }; + return weatherMap[weather] || "๐ŸŒค๏ธ"; +}; diff --git a/src/shared/types/db.ts b/src/shared/types/db.ts new file mode 100644 index 0000000..ff234e6 --- /dev/null +++ b/src/shared/types/db.ts @@ -0,0 +1,9 @@ +import { Prisma } from "@prisma/client"; + +export type Diary = Prisma.DiaryGetPayload<{ + include: { + category: true; + tags: true; + user: true; + }; +}>;