-
Notifications
You must be signed in to change notification settings - Fork 0
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
Pr kyeongseon #2
base: main
Are you sure you want to change the base?
Changes from all commits
bfc174d
8fc9257
01070c0
999a850
cba6c07
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 |
---|---|---|
|
@@ -3,41 +3,38 @@ import React from "react"; | |
export default function Form({ | ||
handleSubmitDiary, | ||
diaryText, | ||
dateText, | ||
diaryDate, | ||
setDiaryText, | ||
setDateText, | ||
setDiaryDate | ||
}) { | ||
const handleDiaryChange = (e) => { | ||
setDiaryText(e.target.value); | ||
}; | ||
|
||
const handleDateChange = (e) => { | ||
setDateText(e.target.value); | ||
setDiaryDate(e.target.value);; | ||
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. 여기 세미콜론 두개있어요~!! |
||
}; | ||
|
||
|
||
// * html 부분 | ||
return ( | ||
<form | ||
className="dataInputField" | ||
onSubmit={handleSubmitDiary}> | ||
<form className="dataInputField" onSubmit={handleSubmitDiary}> | ||
<input | ||
type="text" | ||
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. 날짜를 입력하는 input태그 type="date"를 사용하지 않으신 이유가 따로 있는걸까요? |
||
name="dateInput" | ||
className="dateDataInput" | ||
placeholder="xxxx-xx-xx" | ||
value={dateText} | ||
name="diaryDateInput" | ||
className="dairyDateInput" | ||
placeholder="한 줄 일기를 작성하세요." | ||
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. 이 input은 date가 들어간 것으로 보아 날짜를 입력하는 인풋태그인거 같은데 placeholder를 작성하신 이유가 있나요? |
||
value={diaryDate} | ||
onChange={handleDateChange} | ||
/> | ||
<input | ||
type="text" | ||
name="diaryInput" | ||
name="diaryValueInput" | ||
className="dairyDataInput" | ||
placeholder="한 줄 일기를 작성하세요." | ||
value={diaryText} | ||
onChange={handleDiaryChange} | ||
/> | ||
<input type="submit" value="입력" className="dataInputButton" | ||
/> | ||
<input type="submit" value="입력" className="dataInputButton" /> | ||
</form> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,25 @@ | ||
import React, { useState } from "react"; | ||
|
||
const List = ({ | ||
id, | ||
diaryValue, | ||
dateValue, | ||
diaryData, | ||
setDiaryData, | ||
dateData, | ||
setDateData, | ||
}) => { | ||
const [isEditing, setIsEditing] = useState(false); | ||
const [editedDateText, setEditedDateText] = useState(dateValue); | ||
const [editedDiaryText, setEditedDiaryText] = useState(diaryValue); | ||
|
||
// 업데이트 할 때 입력 받는 부분? | ||
const handleDateEditChange = (e) => { | ||
setEditedDateText(e.target.dateText); | ||
}; | ||
|
||
const handleDiaryEditChange = (e) => { | ||
setEditedDiaryText(e.target.diaryText); | ||
}; | ||
|
||
// * Update 기능 | ||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
|
||
let newDiaryData = diaryData.map((data) => { | ||
if (data.id === id) { | ||
data.title = editedDiaryText; | ||
} | ||
return data; | ||
}); | ||
setDiaryData(newDiaryData); | ||
localStorage.setItem("diaryData", JSON.stringify(newDiaryData)); | ||
|
||
let newDateData = dateData.map((data) => { | ||
if (data.id === id) { | ||
data.title = editedDateText; | ||
} | ||
return data; | ||
}); | ||
setDateData(newDateData); | ||
localStorage.setItem("dateData", JSON.stringify(newDateData)); | ||
|
||
setIsEditing(false); | ||
}; | ||
|
||
// * Delete 기능 | ||
const handleRemove = (id) => { | ||
let newDiaryData = diaryData.filter((data) => data.id !== id); | ||
setDiaryData(newDiaryData); | ||
localStorage.setItem("diaryData", JSON.stringify(newDiaryData)); | ||
|
||
let newDateData = dateData.filter((data) => data.id !== id); | ||
setDateData(newDateData); | ||
localStorage.setItem("dateData", JSON.stringify(newDateData)); | ||
}; | ||
|
||
// * html 부분 | ||
if (isEditing) { | ||
/* isEditing이 true 즉, 수정 중인 데이터 */ | ||
return ( | ||
<div> | ||
<form onSubmit={handleSubmit}> | ||
<input | ||
className="editDateText" | ||
value={editedDateText} | ||
onChange={handleDateEditChange} | ||
/> | ||
<input | ||
className="editDiaryText" | ||
value={editedDiaryText} | ||
onChange={handleDiaryEditChange} | ||
autoFocus /* 웹 페이지를 열었을 때 해당 요소에 자동으로 커서가 위치하여 사용자가 바로 입력을 시작할 수 있게 함 */ | ||
/> | ||
</form> | ||
|
||
<div className="isEditingButtons"> | ||
<button onClick={() => setIsEditing(false)} type="button"> | ||
X | ||
</button> | ||
<button onClick={handleSubmit} type="submit"> | ||
Save | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
} else { | ||
/* isEditing이 false 즉, 작성이 완료된 데이터 */ | ||
return ( | ||
<div> | ||
<span className="editedDate"> | ||
{dateValue} | ||
</span> | ||
<span className="editedDiary"> | ||
{diaryValue} | ||
</span> | ||
|
||
<div className="isEditedButtons"> | ||
<button onClick={() => handleRemove(id)} className="removeButton"> | ||
X | ||
</button> | ||
<button onClick={() => setIsEditing(true)} className="editButton"> | ||
Edit | ||
</button> | ||
import React from "react"; | ||
import ListItem from "./ListItem"; | ||
|
||
const List = ({ diaryData, setDiaryData }) => { | ||
return ( | ||
<div className="listItems"> | ||
<div style={{ display: "flex" }}> | ||
<div> | ||
{diaryData.map((data) => ( | ||
<ListItem | ||
key={data.key} | ||
id={data.id} | ||
diaryValue={data.diaryValue} | ||
diaryDate={data.diaryDate} | ||
diaryData={diaryData} | ||
setDiaryData={setDiaryData} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} | ||
</div> | ||
); | ||
}; | ||
|
||
export default List; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React, { useState } from "react"; | ||
|
||
const ListItem = ({ id, diaryValue, diaryDate, diaryData, setDiaryData }) => { | ||
const [isEditing, setIsEditing] = useState(false); | ||
const [editedDiaryValue, setEditedDiaryValue] = useState(diaryValue); // Edit 할 때 입력되어 있는 부분 | ||
const [editedDiaryDate, setEditedDiaryDate] = useState(diaryDate); | ||
|
||
|
||
// 업데이트 할 때 입력 받는 부분? | ||
const handleDiaryEditChange = (e) => { | ||
const { name, value } = e.target; | ||
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. 객체 구조 분해 할당을 적용해서 작성하신 걸까요?? 오! 이렇게도 할 수 있다는 것을 배워갑니당~! |
||
if (name === "diaryValue") { | ||
setEditedDiaryValue(e.target.value); | ||
} else if (name === "diaryDate") { | ||
setEditedDiaryDate(e.target.value); | ||
} | ||
}; | ||
|
||
// * Update 기능 (save 클릭했을 때 호출) | ||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
|
||
let newDiaryData = diaryData.map((data) => { | ||
if (data.id === id) { | ||
data.diaryValue = editedDiaryValue; | ||
data.diaryDate = editedDiaryDate; | ||
} | ||
return data; | ||
}); | ||
setDiaryData(newDiaryData); | ||
localStorage.setItem("diaryData", JSON.stringify(newDiaryData)); | ||
|
||
setIsEditing(false); | ||
}; | ||
|
||
// * Delete 기능 | ||
const handleRemove = (id) => { | ||
let newDiaryData = diaryData.filter((data) => data.id !== id); | ||
setDiaryData(newDiaryData); | ||
localStorage.setItem("diaryData", JSON.stringify(newDiaryData)); | ||
}; | ||
|
||
// * html 부분 | ||
if (isEditing) { | ||
/* isEditing이 true 즉, 수정 중인 데이터 */ | ||
return ( | ||
<div className="stateOfEditing"> | ||
<form onSubmit={handleSubmit}> | ||
<input | ||
className="editDiaryDate" | ||
name="diaryDate" | ||
value={editedDiaryDate} | ||
onChange={handleDiaryEditChange} | ||
/> | ||
<input | ||
className="editDiaryValue" | ||
name="diaryValue" | ||
value={editedDiaryValue} /* 저장된 텍스트 값 부분 */ | ||
onChange={handleDiaryEditChange} | ||
autoFocus /* 웹 페이지를 열었을 때 해당 요소에 자동으로 커서가 위치하여 사용자가 바로 입력을 시작할 수 있게 함 */ | ||
/> | ||
</form> | ||
|
||
<div className="isEditingButtons"> | ||
<button onClick={() => setIsEditing(false)} type="button"> | ||
X | ||
</button> | ||
<button onClick={handleSubmit} type="submit"> | ||
Save | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
} else { | ||
/* isEditing이 false 즉, 작성이 완료된 데이터 */ | ||
return ( | ||
<div style={{ display: "flex" }} key={id}> | ||
{" "} | ||
{/* 각 리스트들의 고유 key 가 필요함 */} | ||
<span className="editDate"> | ||
{diaryDate} | ||
</span> | ||
<span className="editDiary"> | ||
{diaryValue} | ||
</span> | ||
<div className="isEditedButtons"> | ||
<button onClick={() => handleRemove(id)} className="removeButton"> | ||
X | ||
</button> | ||
<button onClick={() => setIsEditing(true)} className="editButton"> | ||
Edit | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default ListItem; |
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.
새롭게 작성한 일기를 최상단으로 올라오도록 하기위해 이렇게 작성하신건가요?? 아이디어가 기가막히네요~!!