Skip to content

Commit

Permalink
feat: 질문추가 로직 구상중 (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lavegaa committed Dec 3, 2020
1 parent 38233da commit 04cce51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
17 changes: 7 additions & 10 deletions src/components/Question/QuestionList/QuestionList.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import React, { useState, useCallback, useEffect } from 'react';
import React, { useCallback } from 'react';
import update from 'immutability-helper';
import PropTypes from 'prop-types';
import QuestionItem from '../QuestionItem';

export default function QuestionList({ questions }) {
const [cards, setCards] = useState([]);
useEffect(() => {
setCards(questions);
}, []);
export default function QuestionList({ questions, setQuestions }) {
const moveCard = useCallback((dragIndex, hoverIndex) => {
const dragCard = cards[dragIndex];
setCards(update(cards, {
const dragCard = questions[dragIndex];
setQuestions(update(questions, {
$splice: [
[dragIndex, 1],
[hoverIndex, 0, dragCard],
],
}));
}, [cards]);
}, [questions]);
const renderCard = (card, index) => (
<QuestionItem
key={card.id}
Expand All @@ -29,13 +25,14 @@ export default function QuestionList({ questions }) {
);
return (
<>
<div>{cards.map((card, i) => renderCard(card, i))}</div>
<div>{questions.map((card, i) => renderCard(card, i))}</div>
</>
);
}

QuestionList.propTypes = {
questions: PropTypes.array,
setQuestions: PropTypes.func,
};

QuestionList.defaultProp = {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/QuestionPage/QuestionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const InputQuestion = styled.input`
width: 1070px;
height: 26px;
font-size: 24px;
padding: 17px 30px 17px 5px;
padding: 17px 30px 17px 17px;
border: none;
outline: none;
border-radius: 10px;
Expand All @@ -72,7 +72,7 @@ const InputQuestion = styled.input`
const IconWrapper = styled.span`
width: 63px;
height: 63px;
transform:translate(-12px, -2px);
transform:translate(-17px, -2px);
`;

const Text = styled.div`
Expand Down Expand Up @@ -165,13 +165,13 @@ export default function QuestionPage({ match }) {
<ListWrapper>
<Scroll>
<DndProvider backend={HTML5Backend}>
<QuestionList questions={questions} />
<QuestionList questions={questions} setQuestions={setQuestions} />
</DndProvider>
</Scroll>
</ListWrapper>
)}
<ButtonWrapper onClick={handleMakeQuestion}>
<Button text="완료" theme="blue" />
<Button text={id === 'new' ? '저장' : '완료'} theme="blue" />
</ButtonWrapper>
</>
)}
Expand Down

0 comments on commit 04cce51

Please sign in to comment.