[Feat] 롤링페이퍼 POST 데이터에 따라 자동으로 스타일 객체 반환하는 함수 제작 #94
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.
✨ 작업 내용
💡작업 내용을 이해하기 위해 알아야 할 내용
변경사항 설명에 앞서, 현재 롤링페이퍼 POST Request 구조에 대해 설명합니다.
파일을 직접 사용하는 방법만 보고 싶으신 분들은
파일 사용 방법란으로 이동하세요.❔기존:
backgroundColor는

beige,purple,blue,green이라는 고유의 key 값만 저장이 가능했습니다.backgroundURL은

유효한 url 주소만 입력 ornull값만 입력이 가능합니다.따라서,
기존에 컬러를 선택했을 경우에는 backgroundURL은
null로 처리backgroundColor는
4가지 key 중 한개를 선택하여 request를 보냈습니다.기존에 이미지를 선택했을 경우에는 서버에서 실제 저장된 이미지만 이용했기 때문에 선택한 imageUrl을 그대로 request 보냅니다.
❗변경:
기본 색상 말고 커스텀 색상을 선택할 수 있는 기능을 구현하기 위해서는 backgroundColor 필드에 request를 보내는 방식을 이용할 수 없었기 때문에
색상 자체를 이미지로 변환하여 cloudinary에 저장하고, backgroundImageURL에 색상이미지 경로를 넣어 request를 보내는 방식으로 구현했습니다.
로컬에서 직접 이미지를 선택해 등록하는 기능을 구현하기 위해서는 backgroundImageURL 필드에 파일 객체를 바로 request 보내 등록하는 방식을 이용할 수 없었기 때문에
로컬에서 선택한 이미지 객체를 cloudinary이 저장하여 웹 주소를 return 받고, 이 주소를 backgroundImageURL에 이미지 경로를 넣어 REQUEST를 보내는 방식으로 구현했습니다.
❓그래서?
이제 post 데이터를 가지고 실제 list 페이지와 post/{id} 페이지에 색상/이미지를 표현해 줄 때, 경우의 수가 이렇게 나뉩니다.
1. backgroundImageURL이 null 일때
2. backgroundImageURL이 일반 이미지일때
3. backgroundImageURL이 Cloudinary에 저장된 Color형태의 이미지일때
4. backgroundImageURL이 Cloudinary에 저장된 Image형태의 이미지일때
💡 getBackgroundStylesFromPostData.js
getBackgroundStylesFromPostData는 배경이미지 자체에 지정할 스타일을 정해 return 해주는 함수입니다.
💡getBackgroundStylesFromPostData.js 사용 방법
list 페이지의 경우
ItemCard.jsxpost/{id} 페이지의 경우
RollingPaperItemPage.jsx기존 코드에서 아래처럼 변경만 해주시면 됩니다. (주석이 기존코드)
💡getIsDark.js
getIsDark는 이미지 hex값(ex.
#FFFFFF)가 어두운 색인지, 밝은 색인지 계산하여 return 해주는 함수입니다.이 함수의 필요성은 getContentStylesFromPostData.js 에서 설명하겠습니다.
💡getContentStylesFromPostData.js
getContentStylesFromPostData.js 는 List 페이지의 카드의 스타일을 지정해주는 함수입니다.
지정해야 할 스타일은 3가지로 나뉩니다.
getContentStylesFromPostData.js는 스타일을 이렇게 3가지로 나누고, 각 유형에 맞는 스타일을 return 해줍니다.
기본적인 검증 방식은 getBackgroundStylesFromPostData.js와 동일합니다.
💡getContentStylesFromPostData.js 사용방법
List페이지의 경우 (ItemCard.jsx)
💡 최종적으로 프로젝트에 적용하는 방법
아래 내용만 보고 그대로 적용하셔도 됩니다.
ItemCard.jsx
RollingPaperItemPage.jsx
🔗 관련 이슈
Fixes #95