Skip to content

Commit

Permalink
[FEAT] #1 : 패턴 만들기
Browse files Browse the repository at this point in the history
- 설정 컴포넌트들 분리
- 캔버스 사이즈: 최소값, 전체화면 리사이즈 시 처리 적용
- 패턴 영역: 캔버스 사이즈에 맞게 클립 적용

- #2 : 설정 컴포넌트들, 스타일 분리
  • Loading branch information
danbiilee committed Feb 2, 2021
1 parent 6bb610c commit 361f63b
Show file tree
Hide file tree
Showing 17 changed files with 565 additions and 393 deletions.
6 changes: 3 additions & 3 deletions src/components/container/CanvasContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const CanvasContainer = () => {
type: canvasMode,
src: myCanvas.drawnImgSrc,
};
if (myCanvas.drawnImgTitle) {
payload.title = myCanvas.drawnImgTitle;
}
// if (myCanvas.drawnImgTitle) {
// payload.title = myCanvas.drawnImgTitle;
// }
dispatch(addPicture(payload));
};

Expand Down
35 changes: 18 additions & 17 deletions src/components/container/ImagesContainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useMemo } from 'react';
import React, { useState, useEffect, useMemo, useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
getPictures,
Expand Down Expand Up @@ -31,7 +31,7 @@ const addTypeList = (pictures, typeList) => {
}

for (let pic of pictures) {
// canvasMode: origin, crop, pattern
// type: origin, crop, pattern
let optionName = '';
if (pic.type === 'crop') optionName = '크롭';
else if (pic.type === 'pattern') optionName = '패턴';
Expand All @@ -45,6 +45,7 @@ const addTypeList = (pictures, typeList) => {
};

const ImagesContainer = () => {
//console.log('ImagesContainer');
const dispatch = useDispatch();
const { pictures, drawnPicture } = useSelector(state => state.pictures);

Expand All @@ -58,8 +59,6 @@ const ImagesContainer = () => {
// pictures가 바뀌었을 때만 실행
typeList = useMemo(() => addTypeList(pictures, typeList), [pictures]);

//console.log('ImagesContainer', pictures, typeList);

// 첫 마운트 후 indexedDB 값 리덕스 스토어에 셋팅
useEffect(() => {
if (!pictures || !pictures.length) {
Expand All @@ -73,17 +72,18 @@ const ImagesContainer = () => {

// 선택 이미지 리스트(삭제용) 관리
const [selectedList, setSelectedList] = useState([]);
const onToggle = id => {
if (selectedList.includes(id)) {
setSelectedList(selectedList.filter(item => item !== id));
dispatch(deleteSelectedPictures(id));
} else {
setSelectedList(selectedList.concat(id));
dispatch(addSelectedPictures(id));
}
dispatch(changeDrawnPicture(id));
dispatch(changeCanvasMode(null));
};
const onToggle = useCallback(
id => {
if (selectedList.includes(id)) {
setSelectedList(selectedList.filter(item => item !== id));
dispatch(deleteSelectedPictures(id));
} else {
setSelectedList(selectedList.concat(id));
dispatch(addSelectedPictures(id));
}
},
[selectedList, dispatch],
);

const onDelete = () => {
dispatch(deletePicture(selectedList));
Expand All @@ -98,10 +98,11 @@ const ImagesContainer = () => {
};

const onCrop = () => {
if (!drawnPicture) {
alert('⚠ 이미지를 선택해주세요 ⚠');
if (selectedList.length > 1) {
alert('⚠ 하나의 이미지만 크롭할 수 있습니다 ⚠');
return;
}
dispatch(changeDrawnPicture(selectedList[0]));
dispatch(changeCanvasMode('crop'));
};

Expand Down
Loading

0 comments on commit 361f63b

Please sign in to comment.