-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/#43 게시물 등록하기 페이지 #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
The head ref may contain hidden characters: "feature/#43_\uAC8C\uC2DC\uBB3C-\uB4F1\uB85D\uD558\uAE30-\uD398\uC774\uC9C0"
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7ce025e
🌱 게시글 작성 페이지 파일 추가
haksoo0918 c12c088
Merge branch 'develop' into feature/#43_게시물-등록하기-페이지
haksoo0918 49d32e2
Merge branch 'develop' into feature/#43_게시물-등록하기-페이지
haksoo0918 35fcbe3
🔨 구조 및 기본 기능 작성
haksoo0918 cde3b3a
Merge branch 'develop' into feature/#43_게시물-등록하기-페이지
haksoo0918 3e4b8a4
🔨 글작성 api 테스트 - 인증 처리 되면 그때 다시 테스트 필요함
haksoo0918 6bc7070
🔨 날짜 및 주석 추가
haksoo0918 1609fcf
🔨 다크모드 버튼 위치 변경, 헤더 삽입
haksoo0918 a8f975f
Merge branch 'develop' into feature/#43_게시물-등록하기-페이지
haksoo0918 15e88cd
🔥공통 헤더 삭제
haksoo0918 93a9cac
🔨 타이틀 추가, 반응형 스타일 수정
haksoo0918 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import instance from 'lib/axios-client'; | ||
| import Head from 'next/head'; | ||
| import { FormEvent, useState } from 'react'; | ||
|
|
||
| import Button from '@/components/Button'; | ||
| import TextEditor from '@/components/TextEditor'; | ||
|
|
||
| // 제목 글자수 제한 | ||
| const MAX_TITLE = 30; | ||
|
|
||
| // HTML에서 Text만 추출하는 함수 | ||
| const extractContent = (str: string) => str.replace(/<[^>]*>/g, '').trim(); | ||
|
|
||
| // 포멧된 날짜 반환하는 함수 | ||
| const formatDate = (date: string) => { | ||
| const d = new Date(date); | ||
| const year = d.getFullYear(); | ||
| const month = (d.getMonth() + 1).toString().padStart(2, '0'); | ||
| const day = d.getDate().toString().padStart(2, '0'); | ||
| return `${year}. ${month}. ${day}.`; | ||
| }; | ||
|
|
||
| /** | ||
| * 게시글 등록하기 페이지 | ||
| */ | ||
| export default function Addboard() { | ||
| const [title, setTitle] = useState(''); | ||
| const [content, setContent] = useState(''); | ||
|
|
||
| // 등록 버튼 비활성화 | ||
| const submitDisabled = title.length === 0 || content.length === 0; | ||
| // 내용에서 추출된 텍스트 | ||
| const textContent = extractContent(content); | ||
| // 오늘 날짜 | ||
| const today = formatDate(new Date().toISOString()); | ||
|
|
||
| // 제목 input 콜백 함수 | ||
| const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| // console.log('handleChange:e:', e); | ||
| setTitle(e.target.value); | ||
| }; | ||
| // 내용 에디터 콜백 함수 | ||
| const handleContentChange = (value: string) => { | ||
| // console.log('value:', value); | ||
| setContent(value); | ||
| }; | ||
| // 작성 폼 서브밋 함수 | ||
| const handleSubmit = async (e: FormEvent<HTMLFormElement>) => { | ||
| e.preventDefault(); | ||
| // API 연결 및 처리 | ||
| // TODO - 로그인 및 인증되면 그때 다시 테스트 | ||
| instance | ||
| .post('/articles', { | ||
| image: '', | ||
| content, | ||
| title, | ||
| }) | ||
| .then((res) => console.log('subtmi:res:', res)) | ||
| .catch((err) => console.log('submit:err:', err)); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="min-h-svh"> | ||
| <Head> | ||
| <title>게시물 등록하기 | wikied</title> | ||
| </Head> | ||
|
|
||
| <main> | ||
| <div className="container pt-20 mo:px-0 mo:pt-[60px]"> | ||
| <div className="mb-5 mt-[54px] rounded-custom px-[30px] py-[30px] shadow-custom dark:shadow-custom-dark mo:mt-0 mo:px-5 mo:py-4 mo:shadow-none"> | ||
| <header className="my-4 flex items-center justify-between"> | ||
| <h1 className="mo:text-16sb ta:text-20sb pc:text-24sb"> | ||
| 게시물 등록하기 | ||
| </h1> | ||
junghwaYang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Button | ||
| form="write-form" | ||
| className="w-[140px] mo:w-auto" | ||
| disabled={submitDisabled} | ||
| > | ||
| 등록하기 | ||
| </Button> | ||
| </header> | ||
|
|
||
| <div className="my-6 text-16 text-gray-300 mo:my-4 mo:text-12"> | ||
| 등록일 | ||
| <span className="ml-3 mo:ml-2">{today}</span> | ||
| </div> | ||
|
|
||
| <form | ||
| id="write-form" | ||
| className="mt-[33px] mo:mt-5 ta:mt-6" | ||
| onSubmit={handleSubmit} | ||
| > | ||
| <fieldset className="my-5 flex items-center justify-between border-y border-gray-200 mo:mb-4"> | ||
| <label htmlFor="title" className="sr-only"> | ||
| 제목 | ||
| </label> | ||
| <input | ||
| id="title" | ||
| className="w-0 flex-1 bg-transparent py-3 text-20md focus-visible:outline-green-200 mo:text-16md" | ||
| type="text" | ||
| maxLength={MAX_TITLE} | ||
| value={title} | ||
| onChange={handleInputChange} | ||
| placeholder="제목을 입력해주세요" | ||
| /> | ||
| <div className="ml-4 w-10 text-14md mo:text-13md"> | ||
| {title.length}/ | ||
| <span className="text-green-200">{MAX_TITLE}</span> | ||
| </div> | ||
| </fieldset> | ||
|
|
||
| <p className="mb-[10px] mt-5 text-16md mo:my-4 mo:text-14md"> | ||
| 공백포함 : 총 {textContent.length}자 | 공백제외 총{' '} | ||
| {textContent.replaceAll(' ', '').length}자 | ||
| </p> | ||
|
|
||
| <div className="h-[520px] mo:h-[50vh] ta:h-[480px]"> | ||
| <TextEditor value={content} onChange={handleContentChange} /> | ||
| </div> | ||
| </form> | ||
| </div> | ||
|
|
||
| <div className="mb-8 text-center"> | ||
| <Button href="/boards" variant="secondary" className="w-[140px]"> | ||
| 목록으로 | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </main> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.