-
Notifications
You must be signed in to change notification settings - Fork 28
[Mission4/전승환] - Project_Notion_VanillaJS #29
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
base: 3/#4_jeonseunghwan
Are you sure you want to change the base?
Changes from 22 commits
c1f2afb
250e899
940d3f8
137d636
2737c23
169014c
803bd4f
89ae913
2355c53
014ee5f
74b5a86
409269c
c317732
f55b762
bb3acae
db21074
abd5f45
010431c
7b74168
27638ce
61f8ed4
b091456
720cdfc
0aa6450
634e1a9
5f652f4
95ba0cc
fd8744e
1c4d05f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # dependencies | ||
| /node_modules | ||
| /package-lock.json | ||
| /.pnp | ||
| .pnp.js | ||
| /url.js | ||
| # intellij configs | ||
| .idea/ | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>Title</title> | ||
| <link rel="stylesheet" href="src/style/index.css" /> | ||
| </head> | ||
| <body> | ||
| <div class="app"></div> | ||
| <script src="main.js" type="module"></script> | ||
| <script src="https://kit.fontawesome.com/982b34221e.js" crossorigin="anonymous"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import App from './src/App.js'; | ||
|
|
||
| const app = document.querySelector('.app'); | ||
|
|
||
| new App({ target: app }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "name": "fedc3-4_project_notion_vanillajs", | ||
| "version": "1.0.0", | ||
| "description": "- 프로젝트 기한\r - 프로젝트 수행 기간 : 2022년 11월 8일(화) ~ 2022년 11월 16일(수)\r - 멘티 코드 리뷰 기간 : 2022년 11월 17일(목) ~ 2022년 11월 20일(일)\r - 멘토 코드 리뷰 기간 : 2022년 11월 17일(목) ~ 2022년 11월 22일(화)\r - 코드 리뷰 반영 기간 : 2022년 11월 23일(수) ~ 2022년 11월 25일(금)\r - 내용\r - **Day 17 [프로젝트] 노션 클로닝 요구사항** 확인 부탁드립니다.", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/prgrms-fe-devcourse/FEDC3-4_Project_Notion_VanillaJS.git" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "bugs": { | ||
| "url": "https://github.com/prgrms-fe-devcourse/FEDC3-4_Project_Notion_VanillaJS/issues" | ||
| }, | ||
| "homepage": "https://github.com/prgrms-fe-devcourse/FEDC3-4_Project_Notion_VanillaJS#readme", | ||
| "devDependencies": { | ||
| "prettier": "2.7.1" | ||
| }, | ||
| "prettier": { | ||
| "singleQuote": true, | ||
| "semi": true, | ||
| "useTabs": false, | ||
| "tabWidth": 2, | ||
| "trailingComma": "all", | ||
| "printWidth": 100, | ||
| "bracketSpacing": true, | ||
| "arrowParens": "always" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import Navbar from './Navbar/Navbar.js'; | ||
| import { documentsUrl } from './utils/util.js'; | ||
| import { initRouter } from './utils/route.js'; | ||
| import Editor from './Editor/Editor.js'; | ||
|
|
||
| function App({ target }) { | ||
| const navbarPage = new Navbar({ target }); | ||
| const postEditPage = new Editor({ | ||
| target, | ||
| initialState: { | ||
| title: '', | ||
| content: '', | ||
| }, | ||
| }); | ||
|
|
||
| this.route = async () => { | ||
| target.innerHTML = ''; | ||
| const { pathname } = location; | ||
|
|
||
| if (pathname === '/') { | ||
| navbarPage.setState(); | ||
| } else if (pathname.indexOf(`${documentsUrl}/`) === 0) { | ||
| const [, , postId] = pathname.split('/'); | ||
|
|
||
| await navbarPage.setState(); | ||
| await postEditPage.setState({ postId }); | ||
| } | ||
| }; | ||
|
|
||
| this.route(); | ||
| initRouter(() => this.route()); | ||
| } | ||
|
|
||
| export default App; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { createElement } from '../utils/dom.js'; | ||
| import { isNew, isObject } from '../utils/errorHandler.js'; | ||
| import { request } from '../utils/api.js'; | ||
| import { putContentMethod, putTitleMethod } from '../utils/optionsMethod.js'; | ||
| import EditorTitle from './EditorTitle.js'; | ||
| import EditorContent from './EditorContent.js'; | ||
| import { documentsUrl } from '../utils/util.js'; | ||
| import EditorSubContetn from './EditorSubContetn.js'; | ||
|
|
||
| function Editor({ target, initialState }) { | ||
| isNew(new.target); | ||
| const page = createElement('section'); | ||
| page.className = 'content'; | ||
|
|
||
| const editor = createElement('div'); | ||
| editor.className = 'editor'; | ||
|
|
||
| this.state = initialState; | ||
| const postTitle = new EditorTitle({ | ||
| div: editor, | ||
| initialState: initialState, | ||
|
|
||
| onChangeTitle: async ({ id, title }) => { | ||
| setTimeout(await putTitleMethod(id, title), 2000); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요런 매직 넘버들도 상수로 관리해주세요~
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 확실히 상수로 관리하니깐 코드가 가독성이 좋아지는 것 같습니다 👍 수정하겠습니다 : ) |
||
| }, | ||
| }); | ||
|
|
||
| const postContent = new EditorContent({ | ||
| div: editor, | ||
| initialState: initialState, | ||
|
|
||
| onChangeContent: async ({ id, content }) => { | ||
| setTimeout(await putContentMethod(id, content), 2000); | ||
| }, | ||
| }); | ||
|
Comment on lines
+32
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p5) keyup 시 들어있는 벨류 값이 api 통신으로 들아가게 작성하신 것 같습니다. 제대로 작성이 안됬는지 Debounce 혹은 Throttle을 적용시켜서 통신의 간격을 두는 법 혹은
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니다~ Debounce 들어만 봤는데 한번 공부해보고 적용 시켜보겠습니다 👍 |
||
|
|
||
| const postSub = new EditorSubContetn({ | ||
| div: editor, | ||
| initialState: initialState, | ||
| }); | ||
|
|
||
| this.setState = async (nextState) => { | ||
| const post = await request(`${documentsUrl}/${nextState.postId}`); | ||
| isObject(post); | ||
| postTitle.setState(post); | ||
| postContent.setState(post); | ||
| postSub.setState(post); | ||
| this.render(); | ||
| }; | ||
|
|
||
| this.render = () => { | ||
| // editor2.innerHTML = createSubDoucuments(); | ||
| page.appendChild(editor); | ||
| target.appendChild(page); | ||
| }; | ||
|
|
||
| this.render(); | ||
| } | ||
|
|
||
| export default Editor; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { createElement } from '../utils/dom.js'; | ||
| import { isNew, isString } from '../utils/errorHandler.js'; | ||
|
|
||
| function EditorContent({ div, initialState, onChangeContent }) { | ||
| isNew(new.target); | ||
| const editorContent = createElement('div'); | ||
| editorContent.className = 'editor-content'; | ||
|
|
||
| this.state = initialState; | ||
|
|
||
| this.setState = (nextState) => { | ||
| this.state = nextState; | ||
| const { content } = this.state; | ||
|
|
||
| this.render(); | ||
| editorContent.querySelector('.content').value = content && content; | ||
| }; | ||
|
|
||
| this.render = () => { | ||
| const { content } = this.state; | ||
| editorContent.innerHTML = `<textarea name="content" placeholder="내용 없음" | ||
| class=" | ||
| content | ||
| ">${content}</textarea>`; | ||
|
|
||
| div.appendChild(editorContent); | ||
| }; | ||
|
|
||
| const onKeyUpContent = () => { | ||
| editorContent.addEventListener('keyup', (e) => { | ||
| const { name } = e.target; | ||
| const contentValue = e.target.value; | ||
| isString(contentValue); | ||
| const nextState = { | ||
| ...this.state, | ||
| [name]: contentValue, | ||
| }; | ||
|
|
||
| onChangeContent(nextState); | ||
| }); | ||
| }; | ||
|
|
||
| this.render(); | ||
| onKeyUpContent(); | ||
| } | ||
|
|
||
| export default EditorContent; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { createElement } from '../utils/dom.js'; | ||
|
||
|
|
||
| function EditorSubContetn({ div, initialState }) { | ||
| const editorDocuments = createElement('div'); | ||
| editorDocuments.className = 'editor-documents'; | ||
|
|
||
| this.state = initialState; | ||
|
|
||
| this.setState = (nextState) => { | ||
| this.state = nextState; | ||
| this.render(); | ||
| }; | ||
|
|
||
| const createSubDocuments = (documents) => { | ||
| console.log(documents); | ||
| }; | ||
|
|
||
| this.render = () => { | ||
| // editorDocuments.innerHTML = createSubDocuments(this.state); | ||
| // div.appendChild(editorDocuments); | ||
|
||
| }; | ||
|
|
||
| this.render(); | ||
| } | ||
|
|
||
| export default EditorSubContetn; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { createElement } from '../utils/dom.js'; | ||
| import { isNew, isString } from '../utils/errorHandler.js'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p5) 👍 |
||
|
|
||
| function EditorTitle({ div, initialState, onChangeTitle }) { | ||
| isNew(new.target); | ||
| const editorTitle = createElement('div'); | ||
| editorTitle.className = 'editor-title'; | ||
| this.state = initialState; | ||
|
|
||
| div.appendChild(editorTitle); | ||
|
|
||
| this.setState = (nextState) => { | ||
| this.state = nextState; | ||
| const { title } = this.state; | ||
| this.render(); | ||
| editorTitle.querySelector('.title').value = title && title; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. title && title은 뭘까요?_? ㅎㅎ
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. zzzzㅋㅋ 다른 분들 코드보고 만들다가 삼항연산자 대신에 사용했는데 없어도 되겠네요! |
||
| }; | ||
|
|
||
| this.render = () => { | ||
| const { title } = this.state; | ||
| editorTitle.innerHTML = `<input type="text" name="title" class="title" placeholder="제목 없음" value="${title}"/>`; | ||
| div.appendChild(editorTitle); | ||
| }; | ||
|
|
||
| const onKeyupEditorTitle = () => { | ||
| editorTitle.addEventListener('keyup', (e) => { | ||
| const { name } = e.target; | ||
| const titleValue = e.target.value; | ||
|
|
||
| isString(titleValue); | ||
|
|
||
| const nextState = { | ||
| ...this.state, | ||
| [name]: titleValue, | ||
| }; | ||
|
|
||
| onChangeTitle(nextState); | ||
| }); | ||
| }; | ||
| this.render(); | ||
| onKeyupEditorTitle(); | ||
| } | ||
|
|
||
| export default EditorTitle; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
설정파일을 분리해서 사용하면 이후에 재사용하는데 있어서 용이할거에요 ㅎㅎ