-
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
Issue 02 - Criar Quadro Drag'n'drop #16
Changes from 7 commits
f8f3dea
8f47353
cba9f6f
6d0936a
32b930b
af06919
a555311
9ab4524
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* Responsive breakpoints */ | ||
$width-mobile-s: 320px; | ||
$width-mobile-m: 375px; | ||
$width-mobile-l: 425px; | ||
$width-tablet: 768px; | ||
$width-laptop: 1024px; | ||
|
||
/* Main colors*/ | ||
$main-text-color: #6d6d6d; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.container { | ||
background-color: #e2e2e2; | ||
display: flex; | ||
justify-content: space-around; | ||
width: 100%; | ||
overflow: hidden; | ||
height: 100%; | ||
} | ||
|
||
.boxTask { | ||
margin: 10px; | ||
padding: 10px; | ||
.boxContainer { | ||
height: 100%; | ||
overflow-y: auto; | ||
} | ||
} | ||
|
||
.border { | ||
border: 1px solid #c2c2c2; | ||
height: 18em; | ||
align-self: center; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import React, { useState } from 'react'; | ||
import { | ||
DragDropContext, | ||
Droppable, | ||
Draggable, | ||
DropResult, | ||
DraggableLocation, | ||
} from 'react-beautiful-dnd'; | ||
import faker, { fake } from 'faker'; | ||
|
||
import { TaskModel } from 'models/Task'; | ||
import TaskCard from 'components/TaskCard'; | ||
|
||
import styles from './ProjectBoard.module.scss'; | ||
|
||
const reorder = (list: any[], startIndex: number, endIndex: number) => { | ||
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. Seria bom documentar essas funções. Exemplo: /**
* Return the sum of two numbers.
* @param a1: number
* @param a2: number
* Return the number, sum of two numbers.
*/
const soma = (a1: number, a2: number): number {
return a1 + a2;
} 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. Solved. |
||
const result = Array.from(list); | ||
const [removed] = result.splice(startIndex, 1); | ||
result.splice(endIndex, 0, removed); | ||
|
||
return result; | ||
}; | ||
|
||
const move = ( | ||
sourceList: any[], | ||
destinationList: any[], | ||
source: DraggableLocation, | ||
destination: DraggableLocation, | ||
) => { | ||
const sourceClone = Array.from(sourceList); | ||
const destClone = Array.from(destinationList); | ||
const [removed] = sourceClone.splice(source.index, 1); | ||
|
||
destClone.splice(destination.index, 0, removed); | ||
|
||
const result: any = {}; | ||
result[source.droppableId] = sourceClone; | ||
result[destination.droppableId] = destClone; | ||
|
||
return result; | ||
}; | ||
|
||
const generateTask = (): TaskModel => { | ||
return { | ||
id: faker.random.alphaNumeric(5), | ||
name: faker.lorem.words(2), | ||
description: faker.lorem.paragraph(1), | ||
clientId: faker.random.number(), | ||
startDate: faker.date.recent(), | ||
endDate: faker.date.future(), | ||
projectName: `Projeto ${faker.name.firstName()}`, | ||
responsible: faker.name.findName(), | ||
}; | ||
}; | ||
|
||
const ProjectBoard: React.FC = () => { | ||
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. Em telas menores algumas informações são escondidas. Como por exemplo o nome da raia "A fazer". 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. Esse problema é o mesmo da issue #15. Vou resolver depois. |
||
const [tasksTodo, setTasksTodo] = useState<TaskModel[]>([ | ||
generateTask(), | ||
generateTask(), | ||
]); | ||
const [tasksDoing, setTasksDoing] = useState([ | ||
generateTask(), | ||
generateTask(), | ||
]); | ||
const [tasksDone, setTasksDone] = useState([generateTask(), generateTask()]); | ||
|
||
const boxSetList: any = { | ||
todo: { tasks: tasksTodo, setTasks: setTasksTodo }, | ||
doing: { tasks: tasksDoing, setTasks: setTasksDoing }, | ||
done: { tasks: tasksDone, setTasks: setTasksDone }, | ||
}; | ||
|
||
const onDragEnd = (result: DropResult) => { | ||
const { source, destination } = result; | ||
if (!destination) { | ||
return; | ||
} | ||
|
||
if (source.droppableId === destination.droppableId) { | ||
const { tasks, setTasks } = boxSetList[destination.droppableId]; | ||
|
||
const newItems = reorder(tasks, source.index, destination.index); | ||
|
||
setTasks(newItems); | ||
} else { | ||
const { tasks: tasksSource, setTasks: setTasksSource } = boxSetList[ | ||
source.droppableId | ||
]; | ||
const { | ||
tasks: tasksDestination, | ||
setTasks: setTasksDestination, | ||
} = boxSetList[destination.droppableId]; | ||
|
||
const resultObject = move( | ||
tasksSource, | ||
tasksDestination, | ||
source, | ||
destination, | ||
); | ||
|
||
setTasksSource(resultObject[source.droppableId]); | ||
setTasksDestination(resultObject[destination.droppableId]); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<DragDropContext onDragEnd={onDragEnd}> | ||
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. Quando tem mais de duas tasks em uma mesma raia aparece uma seta de rolagem, mas fica muito colado no card da task e também fica confuso, pois já tem um "traço" para separar as raias. Não sei se seria possível melhorar isso, mas seria bom. A gente pode optar para deixar isso mais pra frente, visto que é detalhes de design. 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. Creio que seja melhor a gente focar em colocar a aplicação para funcionar. Vou criar uma issue para não passar batido. |
||
<Droppable droppableId="todo"> | ||
{(provided, snapshot) => ( | ||
<div | ||
className={styles.boxTask} | ||
{...provided.droppableProps} | ||
ref={provided.innerRef} | ||
> | ||
<span className={styles.title}>A fazer</span> | ||
<div className={styles.boxContainer}> | ||
{tasksTodo.map((task, index) => ( | ||
<TaskCard task={task} index={index} /> | ||
))} | ||
</div> | ||
</div> | ||
)} | ||
</Droppable> | ||
<hr className={styles.border} /> | ||
<Droppable droppableId="doing"> | ||
{(provided, snapshot) => ( | ||
<div | ||
className={styles.boxTask} | ||
{...provided.droppableProps} | ||
ref={provided.innerRef} | ||
> | ||
<span className={styles.title}>Em execução</span> | ||
<div className={styles.boxContainer}> | ||
{tasksDoing.map((task, index) => ( | ||
<TaskCard task={task} index={index} /> | ||
))} | ||
</div> | ||
</div> | ||
)} | ||
</Droppable> | ||
<hr className={styles.border} /> | ||
<Droppable droppableId="done"> | ||
{(provided, snapshot) => ( | ||
<div | ||
className={styles.boxTask} | ||
{...provided.droppableProps} | ||
ref={provided.innerRef} | ||
> | ||
<span className={styles.title}>Feito</span> | ||
<div className={styles.boxContainer}> | ||
{tasksDone.map((task, index) => ( | ||
<TaskCard task={task} index={index} /> | ||
))} | ||
</div> | ||
</div> | ||
)} | ||
</Droppable> | ||
</DragDropContext> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProjectBoard; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
@mixin boxWithIcon { | ||
display: flex; | ||
align-items: center; | ||
margin: 7px 0; | ||
} | ||
|
||
.container { | ||
background-color: #ffffff; | ||
border-radius: 15px; | ||
height: 140px; | ||
width: 225px; | ||
margin: 10px 0; | ||
padding: 15px; | ||
font-size: 14px; | ||
font-weight: 300; | ||
|
||
.title { | ||
font-size: 16px; | ||
font-weight: 500; | ||
padding-bottom: 5px; | ||
border-bottom: 1px solid #dddddd; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
} | ||
|
||
.details { | ||
padding: 3px 0; | ||
border-bottom: 1px solid #dddddd; | ||
.clientName { | ||
@include boxWithIcon(); | ||
} | ||
.date { | ||
@include boxWithIcon(); | ||
} | ||
} | ||
|
||
.footer { | ||
.people { | ||
@include boxWithIcon(); | ||
} | ||
} | ||
} | ||
|
||
.icon { | ||
color: #6d6d6d; | ||
font-size: 16px; | ||
margin-right: 5px; | ||
} |
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.
Componente
fake
eDraggable
não estão sendo utilizados.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.
Solved.