Skip to content

Commit

Permalink
제목 추가할 수 있도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
BumgeunSong committed Oct 20, 2024
1 parent f7fc3ee commit cc5471c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/components/Pages/PostCreationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import ReactQuill from 'react-quill';
import 'react-quill/dist/quill.snow.css';

const PostCreationPage: React.FC = () => {
const [title, setTitle] = useState<string>('');
const [content, setContent] = useState<string>('');
const { currentUser } = useAuth();
const navigate = useNavigate();

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!content.trim()) return;
if (!title.trim() || !content.trim()) return;

try {
await addDoc(collection(firestore, 'posts'), {
title,
content,
authorId: currentUser?.uid,
authorName: currentUser?.displayName,
Expand All @@ -31,10 +33,26 @@ const PostCreationPage: React.FC = () => {

return (
<div>
<h1>Create Post</h1>
<h1>새 글 작성</h1>
<form onSubmit={handleSubmit}>
<ReactQuill value={content} onChange={setContent} />
<button type="submit">Post</button>
<div>
<label htmlFor="title">제목:</label>
<input
type="text"
id="title"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
/>
</div>
<div>
<label htmlFor="content">내용:</label>
<ReactQuill
value={content}
onChange={setContent}
/>
</div>
<button type="submit">게시하기</button>
</form>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion src/types/Posts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// src/types/Post.ts
export interface Post {
id: string;
title: string;
content: string;
authorId: string;
authorName: string;
createdAt: Date;
updatedAt?: Date;
}
}

0 comments on commit cc5471c

Please sign in to comment.