diff --git a/2week/class/package.json b/2week/class/package.json index 471fac85d..6ba730739 100644 --- a/2week/class/package.json +++ b/2week/class/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { + "materialize-css": "^1.0.0", "react": "^16.7.0", "react-dom": "^16.7.0", "react-scripts": "2.1.3" diff --git a/2week/class/src/App copy.js b/2week/class/src/App copy.js new file mode 100644 index 000000000..c40095869 --- /dev/null +++ b/2week/class/src/App copy.js @@ -0,0 +1,196 @@ +import React, {Component} from "react" +import './App.css'; +import "materialize-css"; +import "materialize-css/dist/css/materialize.min.css"; +import Note from "./Note"; +import Writing from "./Writing"; + +class App extends Component { + constructor(props) { + super(props) + this.state = { + //state의 초기값을 설정합니다. + savedNotes: [ + {id: 0, title: "title1", content: "default1", status:false}, + {id: 1, title: "title2", content: "default2", status:false}, + {id: 2, title: "title3", content: "default2", status:false} + ] + } + } + + + + + + delete = (index) =>{ + const {savedNotes} = this.state; + + // filter 함수를 이용해서 삭제한 애들 Index만 뺴고 재배치 + const filteredNotes = savedNotes.filter((note) => note.id !== index); + + console.log(filteredNotes); + + this.setState({ + savedNotes: filteredNotes + }); + + console.log(index); + } + + + edit = (index) =>{ + + + const {savedNotes} = this.state; + + // console.log(savedNotes); + + // 파라미터로 받은 id 를 가지고 몇번째 아이템인지 찾습니다. + const indexes = savedNotes.findIndex(note => note.id === index); + + const selected = savedNotes[indexes]; // 선택한 객체 + + // const test = [...selected]; + + console.log(selected); + // console.log(test); + + + const nextNotes = [...savedNotes]; // 배열을 복사 + + // 기존의 값들을 복사하고, checked 값을 덮어쓰기 + nextNotes[index] = { + ...selected, + status: !selected.checked + }; + + + + this.setState({ + savedNotes: nextNotes + }); + + + + // console.log(selected); + + } + + + normal = (index) =>{ + console.log("normal"); + const {savedNotes} = this.state; + + + // 파라미터로 받은 id 를 가지고 몇번째 아이템인지 찾습니다. + const indexes = savedNotes.findIndex(note => note.id === index); + + const selected = savedNotes[indexes]; // 선택한 객체 + + + + const nextNotes = [...savedNotes]; // 배열을 복사 + + // 기존의 값들을 복사하고, checked 값을 덮어쓰기 + nextNotes[index] = { + ...selected, + status: selected.checked + }; + + this.setState({ + savedNotes: nextNotes + }); + + // console.log(index); + // console.log(selected); + } + + + + editSave = (writingState,index) => { + + + + // console.log("saved"); + const {savedNotes} = this.state; + + + + + const modifyArr = savedNotes.map(note => note.id === index ? ({...note, title:writingState.title, content:writingState.content}) : note); + + + + + // 파라미터로 받은 id 를 가지고 몇번째 아이템인지 찾습니다. + const indexes = modifyArr.findIndex(note => note.id === index); + + const selected = modifyArr[indexes]; // 선택한 객체 + + + + const nextNotes = [...modifyArr]; // 배열을 복사 + + // 기존의 값들을 복사하고, checked 값을 덮어쓰기 + nextNotes[index] = { + ...selected, + status: selected.checked + }; + + this.setState({ + savedNotes: nextNotes + }); + + // console.log("normal"); + + // console.log(savedNotes); + } + + + + + + save = writingState => { + + //설계한 함수의 상태를 확인하기 위해 save를 표시하도록 해봅시다. + // console.log(content + "is saved"); + const { savedNotes } = this.state; + + // 배열의 마지막녀석 id값을 가져옴 + const lstNoteId = savedNotes.length !== 0? savedNotes[savedNotes.length -1].id : 0; + + // 마지막 녀석의 id에 +1 하여 id로 부여 + this.setState({ + savedNotes: [...savedNotes, {id: lstNoteId+1,title: writingState.title, content: writingState.content, status: writingState.status}] + }); + + } + + render() { + return ( +
+ + {/* 원래 노트를 여러개 보내므로, Notes라고 하는게 좋겠지만 추후에 Note 컴포넌트로 활용할 예정이기 때문에 Note로 명명해 줍시다.*/} + +
+ {this.state.savedNotes.map((note,key) => ( + // arrow function 사용시 ()소괄호로 하면 바로 return 해주겠다는 의미. + + ))} +
+
+ ) + } +} + +export default App diff --git a/2week/class/src/App.css b/2week/class/src/App.css new file mode 100644 index 000000000..0dcbc4837 --- /dev/null +++ b/2week/class/src/App.css @@ -0,0 +1,14 @@ +*{ + padding: 0; + margin: 0; + box-sizing: border-box; +} + +.App { + +} + +.hsubmit{background: rgb(0, 204, 255);width: 100%;line-height: 50px;border: 1px solid blue;color: white;} + + + \ No newline at end of file diff --git a/2week/class/src/App.js b/2week/class/src/App.js index ff5fbe379..6a975126c 100644 --- a/2week/class/src/App.js +++ b/2week/class/src/App.js @@ -1,70 +1,196 @@ import React, {Component} from "react" +import './App.css'; +import "materialize-css"; +import "materialize-css/dist/css/materialize.min.css"; +import Note from "./Note"; +import Writing from "./Writing"; -class App extends Component { - constructor(props) { - super(props) - this.state = { +class App extends Component { + constructor(props) { + super(props) + this.state = { //state의 초기값을 설정합니다. - savedNotes: [{content: "default1"}, {content: "default2"}] - } - } + savedNotes: [ + {id: 0, title: "title1", content: "default1", status:false}, + {id: 1, title: "title2", content: "default2", status:false}, + {id: 2, title: "title3", content: "default2", status:false} + ] + } + } + + - save = (content) => { - //설계한 함수의 상태를 확인하기 위해 save를 표시하도록 해봅시다. - console.log(content + "is saved") - } - render() { + + delete = (index) =>{ + const {savedNotes} = this.state; + + // filter 함수를 이용해서 삭제한 애들 Index만 뺴고 재배치 + const filteredNotes = savedNotes.filter((note) => note.id !== index); + + console.log(filteredNotes); + + this.setState({ + savedNotes: filteredNotes + }); + + console.log(index); + } + + + edit = (index) =>{ + + + const {savedNotes} = this.state; + + // console.log(savedNotes); + + // 파라미터로 받은 id 를 가지고 몇번째 아이템인지 찾습니다. + const indexes = savedNotes.findIndex(note => note.id === index); + + const selected = savedNotes[indexes]; // 선택한 객체 + + // const test = [...selected]; + + console.log(selected); + // console.log(test); + + + const nextNotes = [...savedNotes]; // 배열을 복사 + + // 기존의 값들을 복사하고, checked 값을 덮어쓰기 + nextNotes[index] = { + ...selected, + status: !selected.checked + }; + + + + this.setState({ + savedNotes: nextNotes + }); + + + + // console.log(selected); + + } + + + normal = (index) =>{ + console.log("normal"); + const {savedNotes} = this.state; + + + // 파라미터로 받은 id 를 가지고 몇번째 아이템인지 찾습니다. + const indexes = savedNotes.findIndex(note => note.id === index); + + const selected = savedNotes[indexes]; // 선택한 객체 + + + + const nextNotes = [...savedNotes]; // 배열을 복사 + + // 기존의 값들을 복사하고, checked 값을 덮어쓰기 + nextNotes[index] = { + ...selected, + status: selected.checked + }; + + this.setState({ + savedNotes: nextNotes + }); + + // console.log(index); + // console.log(selected); + } + + + + editSave = (writingState,index) => { + + + + // console.log("saved"); + const {savedNotes} = this.state; + + + + + const modifyArr = savedNotes.map(note => note.id === index ? ({...note, title:writingState.title, content:writingState.content}) : note); + + + + + // 파라미터로 받은 id 를 가지고 몇번째 아이템인지 찾습니다. + const indexes = modifyArr.findIndex(note => note.id === index); + + const selected = modifyArr[indexes]; // 선택한 객체 + + + + const nextNotes = [...modifyArr]; // 배열을 복사 + + // 기존의 값들을 복사하고, checked 값을 덮어쓰기 + nextNotes[index] = { + ...selected, + status: selected.checked + }; + + this.setState({ + savedNotes: nextNotes + }); + + // console.log("normal"); + + // console.log(savedNotes); + } + + + + + + save = writingState => { + + //설계한 함수의 상태를 확인하기 위해 save를 표시하도록 해봅시다. + // console.log(content + "is saved"); + const { savedNotes } = this.state; + + // 배열의 마지막녀석 id값을 가져옴 + const lstNoteId = savedNotes.length !== 0? savedNotes[savedNotes.length -1].id : 0; + + // 마지막 녀석의 id에 +1 하여 id로 부여 + this.setState({ + savedNotes: [...savedNotes, {id: lstNoteId+1,title: writingState.title, content: writingState.content, status: writingState.status}] + }); + + } + + render() { return (
- + {/* 원래 노트를 여러개 보내므로, Notes라고 하는게 좋겠지만 추후에 Note 컴포넌트로 활용할 예정이기 때문에 Note로 명명해 줍시다.*/} - -
- ) - } -} - -class Writing extends Component { - constructor(props) { - super(props) - this.state = { - content: "" - } - } - - handleChange = (e) => { - console.log("changed") - } - - handleSubmit = (e) => { - this.props.save("content") - } - - render() { - return ( -
- - -
- ) - } -} - -class Note extends Component { - render() { - const { content } = this.props - - return ( -
- {content} -
- ) - } -} - + +
+ {this.state.savedNotes.map((note,key) => ( + // arrow function 사용시 ()소괄호로 하면 바로 return 해주겠다는 의미. + + ))} +
+ + ) + } +} + export default App diff --git a/2week/class/src/EditText.js b/2week/class/src/EditText.js new file mode 100644 index 000000000..76693db69 --- /dev/null +++ b/2week/class/src/EditText.js @@ -0,0 +1,65 @@ +import React, {Component} from "react" +class Writing extends Component { + constructor(props) { + super(props) + this.state = { + title: this.props.title, + content: this.props.content, + } + } + + handleChange = (e) => { + // console.log(e); + // console.log(e.taget); + this.setState({ + [e.target.name]:e.target.value + }) + + console.log("changed") + } + + + handleClickNormal = (e) => { + this.props.handleClickNormal(this.props.index); + e.preventDefault(); + } + + handleSubmit = (e) => { + this.props.editSave(this.state,this.props.index); + + + + e.preventDefault(); + } + + + render() { + return ( +
+
+
+ +
+ +
+ +
+ +
+
+ ) + } + } + + + export default Writing; \ No newline at end of file diff --git a/2week/class/src/Note.css b/2week/class/src/Note.css new file mode 100644 index 000000000..1bfa4bf25 --- /dev/null +++ b/2week/class/src/Note.css @@ -0,0 +1,15 @@ + +.Note { + position: relative; +} + +.DeleteBtn { + position: absolute; + left: 80%; + top:-5%; +} + +#Icon { + vertical-align: middle; + font-size:2rem; +} \ No newline at end of file diff --git a/2week/class/src/Note.js b/2week/class/src/Note.js new file mode 100644 index 000000000..2e9579195 --- /dev/null +++ b/2week/class/src/Note.js @@ -0,0 +1,65 @@ +import React, {Component} from "react" +import "./Note.css" +import EditText from './EditText'; + + +class Note extends Component { + + + handleClickDelete = () =>{ + this.props.delete(this.props.index); + } + + handleClickEdit = () =>{ + this.props.edit(this.props.index); + } + + + handleClickNormal = (indexes) =>{ + // console.log("normal"); + this.props.normal(indexes); + } + + + + render() { + const { content, title, status } = this.props + + return ( +
+ +
+
+ delete +
+
+ +
+
+ + + + + + { status ? () : ( <> {title}
{content} )} + + + { !status && (<>
수정하기
) } + + + +
+

{status}

+ + + + + +
+
+
+ ) + } + } + + export default Note; \ No newline at end of file diff --git a/2week/class/src/Writing.js b/2week/class/src/Writing.js new file mode 100644 index 000000000..bf4767093 --- /dev/null +++ b/2week/class/src/Writing.js @@ -0,0 +1,75 @@ +import React, {Component} from "react" +class Writing extends Component { + constructor(props) { + super(props) + this.state = { + title: "제목입력", + content: "이 곳에 입력해주세요", + } + } + + handleChange = (e) => { + // console.log(e); + // console.log(e.taget); + this.setState({ + [e.target.name]:e.target.value + }) + + console.log("changed") + } + + handleSubmit = (e) => { + this.props.save(this.state); + + this.setState({ + title: "", + content: "" + }); + + e.preventDefault(); + } + + + resetContent = () => { + setTimeout(() => { + this.setState({ + content:"" + }); + }, 3000); + } + + componentDidMount(){ + this.resetContent(); + } + + render() { + return ( +
+
+
+ +
+ +
+ +
+ + +
+
+ ) + } + } + + + export default Writing; \ No newline at end of file diff --git a/2week/class/src/todoform.js b/2week/class/src/todoform.js new file mode 100644 index 000000000..2647b72ad --- /dev/null +++ b/2week/class/src/todoform.js @@ -0,0 +1,40 @@ +import React from 'react'; + +export default class TodoForm extends React.Component{ + state = { + text:'' + } + +handleChange = e =>{ + this.setState({ + [e.target.name] :e.target.value + }); +} + +handleSubmit = e =>{ + e.preventDefault(); + this.props.onSubmit({ + text:this.state.text, + complete: false + }); +} + + + render(){ + return ( + <> +
+ + + + +
+ + ) + } +} \ No newline at end of file diff --git a/2week/class/src/todolist.js b/2week/class/src/todolist.js new file mode 100644 index 000000000..9af63f3bb --- /dev/null +++ b/2week/class/src/todolist.js @@ -0,0 +1,22 @@ +import React from 'react'; +import TodoForm from './todoform'; +export default class TodoList extends React.Component{ + + state = { + todos :[] + } + + addTodo = (todo) =>{ + + this.setState({ + + todos: [todo ,...this.state.todos] + }); + } + + render(){ + return + } +} + + \ No newline at end of file diff --git a/2week/class/yarn.lock b/2week/class/yarn.lock index b5a104a59..31eee6f7d 100644 --- a/2week/class/yarn.lock +++ b/2week/class/yarn.lock @@ -5170,6 +5170,11 @@ map-visit@^1.0.0: dependencies: object-visit "^1.0.0" +materialize-css@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/materialize-css/-/materialize-css-1.0.0.tgz#8d5db1c4a81c6d65f3b2e2ca83a8e08daa24d1be" + integrity sha512-4/oecXl8y/1i8RDZvyvwAICyqwNoKU4or5uf8uoAd74k76KzZ0Llym4zhJ5lLNUskcqjO0AuMcvNyDkpz8Z6zw== + math-random@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/math-random/-/math-random-1.0.1.tgz#8b3aac588b8a66e4975e3cdea67f7bb329601fac" @@ -6859,14 +6864,15 @@ react-dev-utils@^7.0.1: strip-ansi "4.0.0" text-table "0.2.0" -react-dom@16.7.0: - version "16.7.0" - resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.7.0.tgz#a17b2a7ca89ee7390bc1ed5eb81783c7461748b8" +react-dom@^16.7.0: + version "16.11.0" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.11.0.tgz#7e7c4a5a85a569d565c2462f5d345da2dd849af5" + integrity sha512-nrRyIUE1e7j8PaXSPtyRKtz+2y9ubW/ghNgqKFHHAHaeP0fpF5uXR+sq8IMRHC+ZUxw7W9NyCDTBtwWxvkb0iA== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" prop-types "^15.6.2" - scheduler "^0.12.0" + scheduler "^0.17.0" react-error-overlay@^5.1.2: version "5.1.2" @@ -6926,14 +6932,14 @@ react-scripts@2.1.3: optionalDependencies: fsevents "1.2.4" -react@16.7.0: - version "16.7.0" - resolved "https://registry.yarnpkg.com/react/-/react-16.7.0.tgz#b674ec396b0a5715873b350446f7ea0802ab6381" +react@^16.7.0: + version "16.11.0" + resolved "https://registry.yarnpkg.com/react/-/react-16.11.0.tgz#d294545fe62299ccee83363599bf904e4a07fdbb" + integrity sha512-M5Y8yITaLmU0ynd0r1Yvfq98Rmll6q8AxaEe88c8e7LxO8fZ2cNgmFt0aGAS9wzf1Ao32NKXtCl+/tVVtkxq6g== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" prop-types "^15.6.2" - scheduler "^0.12.0" read-pkg-up@^1.0.1: version "1.0.1" @@ -7327,9 +7333,10 @@ saxes@^3.1.3: dependencies: xmlchars "^1.3.1" -scheduler@^0.12.0: - version "0.12.0" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.12.0.tgz#8ab17699939c0aedc5a196a657743c496538647b" +scheduler@^0.17.0: + version "0.17.0" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.17.0.tgz#7c9c673e4ec781fac853927916d1c426b6f3ddfe" + integrity sha512-7rro8Io3tnCPuY4la/NuI5F2yfESpnfZyT6TtkXnSWVkcu0BCDJ+8gk5ozUaFaxpIyNuWAPXrH0yFcSi28fnDA== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1"