Skip to content

Commit 7af773d

Browse files
committed
feat: 일지 제목 추가
1 parent 20f44a9 commit 7af773d

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

app/(with-sidebar)/write/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Editor from '@/components/write/Editor';
22

33
const Page = () => {
44
return (
5-
<div className="bg-background flex min-h-screen flex-col gap-8">
5+
<div className="bg-background flex min-h-screen flex-col gap-8 p-4">
66
<Editor />
77
</div>
88
);

components/write/Editor.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const MDEditor = dynamic<MDEditorProps>(() => import('@uiw/react-md-editor'), {
1414

1515
const Editor = () => {
1616
const [value, setValue] = useState<string>('');
17+
const [title, setTitle] = useState<string>('');
1718
const router = useRouter();
1819

1920
const onClickCancel = () => {
@@ -26,13 +27,17 @@ const Editor = () => {
2627
alert('로그인이 필요합니다');
2728
return;
2829
}
30+
if (!title.trim()) {
31+
alert('제목을 입력하세요');
32+
return;
33+
}
2934
if (!value.trim()) {
3035
alert('내용을 입력하세요');
3136
return;
3237
}
3338

3439
try {
35-
const id = await createPost(user.uid, value);
40+
const id = await createPost(user.uid, value, title);
3641
alert('저장 완료!');
3742
console.log('postId:', id);
3843

@@ -43,15 +48,25 @@ const Editor = () => {
4348
}
4449
};
4550

51+
const onChangeTitle = (e: React.ChangeEvent<HTMLInputElement>) => {
52+
setTitle(e.target.value);
53+
};
54+
4655
return (
4756
<div
4857
data-color-mode="light"
4958
className="mx-auto mt-8 flex w-full max-w-5xl flex-col gap-8 rounded-2xl px-4 [&_.w-md-editor]:border-0! [&_.w-md-editor]:bg-transparent! [&_.w-md-editor]:shadow-none [&_.w-md-editor-text]:bg-transparent! [&_.w-md-editor-toolbar]:bg-transparent! [&_.wmde-markdown]:bg-transparent!"
5059
>
60+
<input
61+
type="text"
62+
placeholder="제목을 입력하세요"
63+
onChange={onChangeTitle}
64+
className="py-3 text-3xl focus:ring-0 focus:outline-none"
65+
/>
5166
<MDEditor
5267
value={value}
5368
onChange={(v) => setValue(v ?? '')}
54-
height={800}
69+
height={700}
5570
preview="live"
5671
textareaProps={{
5772
placeholder: '내용을 입력하세요',

services/write/post.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export type PostData = {
1717

1818
export type Post = PostData & { id: string };
1919

20-
export async function createPost(uid: string, content: string, title?: string) {
20+
export async function createPost(uid: string, content: string, title: string) {
2121
const postsCol = collection(db, 'users', uid, 'posts');
2222
const docRef = await addDoc(postsCol, {
23-
title: title ?? '',
23+
title: title,
2424
content,
2525
createdAt: serverTimestamp(),
2626
updatedAt: serverTimestamp(),
@@ -39,7 +39,8 @@ function parsePostData(raw: unknown): PostData | null {
3939
const content = raw.content;
4040
if (typeof content !== 'string') return null; // content는 필수
4141

42-
const title = typeof raw.title === 'string' ? raw.title : '';
42+
const title = raw.title;
43+
if (typeof title !== 'string') return null;
4344

4445
const createdAt = raw.createdAt instanceof Timestamp ? raw.createdAt : null;
4546

@@ -52,7 +53,7 @@ export async function fetchMyPost(
5253
uid: string | null | undefined,
5354
postId: string | null | undefined
5455
): Promise<Post | null> {
55-
// 여기서 uid/postId 실물 확인
56+
// 여기서 uid/postId 실물 확인
5657
console.log('[fetchMyPost] path =', { uid, postId });
5758

5859
if (!uid || !postId) return null;

0 commit comments

Comments
 (0)