Skip to content
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

9회차 과제 - 조민서 #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JO-MINSEO
Copy link

UI

Page Home
image
Page Info
image
Page Notice
image
Page Login
image

1. 내가 개발한 기능

  const addNotice = () => {
    const newNoticeObj = {
      id: Date.now().toString(),
      title: newTitle,
      body: newBody,
    };
    const updatedNotices = [...notices, newNoticeObj];
    setNotices(updatedNotices);
    saveNoticesToCookie(updatedNotices);
    setNewTitle('');
    setNewBody('');
  };

새로운 공지사항 제목, 내용을 적고 Add Notice 버튼을 클릭하면 공지사항 목록에 추가하는 함수

  const updateNotice = (id) => {
    const updatedNotices = notices.map(notice =>
      notice.id === id ? { ...notice, title: editingTitle, body: editingBody } : notice
    );
    setNotices(updatedNotices);
    saveNoticesToCookie(updatedNotices);
    setEditingId(null);
    setEditingTitle('');
    setEditingBody('');
  };

Save 버튼 클릭 시 공지사항 목록을 업데이트하는 함수

  const deleteNotice = (id) => {
    const updatedNotices = notices.filter(notice => notice.id !== id);
    setNotices(updatedNotices);
    saveNoticesToCookie(updatedNotices);
  };

Delete 버튼 클릭 시 공지사항 목록에서 제외하는 함수

.2. 내가 개발할 때 유의깊게 개발한 기능

const setCookie = (name, value, days) => {
  const expires = new Date(Date.now() + days * 864e5).toUTCString();
  document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`;
};

const getCookie = (name) => {
  return document.cookie.split('; ').reduce((r, v) => {
    const parts = v.split('=');
    return parts[0] === name ? decodeURIComponent(parts[1]) : r
  }, '');
};

쿠키를 설정하는 함수인 setCookie, 쿠키를 읽어오는 함수인 getCookie를 구현함

3. 내가 개발하면서 들었던 의문 사항
Notice.jsfmf 컴포넌트로 분리하려고 했으나 props가 너무 많아져 더 복잡해 보였음. 코드를 더 가독성 좋고 간결하게 짤 수 있는 방법에 대하여 고민해봐야 할 것 같음.

Copy link

@immms immms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저와 다르게 ui를 잘 구현하셨고, 쿠키를 사용한 방식 잘 보았습니다!! 저도 추후에는 제목과 본문을 같이 업데이트 하는 식으로도 구현해봐야겠습니다. 과제하시느라 수고하셨습니당~~ : )

Comment on lines +9 to +27
const moveToHome = (e) => {
e.preventDefault();
navigate("")
}

const moveToInfo = (e) => {
e.preventDefault();
navigate("/info")
}

const moveToNotice = (e) => {
e.preventDefault();
navigate("/notice")
}

const moveToLogin = (e) => {
e.preventDefault();
navigate("/login")
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

클릭하여 navigate하는 기능의 함수를 만들어 한꺼번에 관리를 하는 것이 좋을 것 같습니다!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 한꺼번에 관리를 하면 코드가 더 간결해질 것 같습니다~!

Comment on lines +17 to +23
const [notices, setNotices] = useState([]);
const [newTitle, setNewTitle] = useState('');
const [newBody, setNewBody] = useState('');
const [editingId, setEditingId] = useState(null);
const [editingTitle, setEditingTitle] = useState('');
const [editingBody, setEditingBody] = useState('');
const [expandedId, setExpandedId] = useState(null);
Copy link

@immms immms May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useState({ title: '', body: '' }); 이런식으로 title과 body를 한꺼번에 관리해주면 가독성 면에서도 좋을것같습니다~~!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

말씀한대로 한다면 가독성이 더 좋을 것 같습니다. 감사합니다!

Comment on lines +4 to +14
const setCookie = (name, value, days) => {
const expires = new Date(Date.now() + days * 864e5).toUTCString();
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`;
};

const getCookie = (name) => {
return document.cookie.split('; ').reduce((r, v) => {
const parts = v.split('=');
return parts[0] === name ? decodeURIComponent(parts[1]) : r
}, '');
};
Copy link

@immms immms May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저와 다르게 쿠키를 사용하셨네요! 저도 쿠키에 대해 더 공부해봐야겠습니당

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 성임님이 쓰신 방법을 더 공부해봐야겠습니당!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants