moved task is highlighted (drag and drop)

This commit is contained in:
Chneemann 2024-05-22 10:04:19 +02:00
parent a2bc51ff48
commit 5db44ead15
6 changed files with 55 additions and 16 deletions

View file

@ -54,10 +54,10 @@
<div id="todo" class="details"> <div id="todo" class="details">
@for(task of getTaskStatus("todo"); track task) { @for(task of getTaskStatus("todo"); track task) {
<app-task [task]="task"></app-task> <app-task [task]="task"></app-task>
@if(taskMovedTo === "todo") { } @empty {
<app-task-highlighted></app-task-highlighted>
} } @empty {
<app-task-empty>{{ "board.noTasks" | translate }}</app-task-empty> <app-task-empty>{{ "board.noTasks" | translate }}</app-task-empty>
} @if(taskMovedTo === "todo" && taskMovedFrom !== "todo") {
<app-task-highlighted></app-task-highlighted>
} }
</div> </div>
</div> </div>
@ -79,6 +79,9 @@
<app-task [task]="task"></app-task> <app-task [task]="task"></app-task>
} @empty { } @empty {
<app-task-empty>{{ "board.noTasks" | translate }}</app-task-empty> <app-task-empty>{{ "board.noTasks" | translate }}</app-task-empty>
} @if(taskMovedTo === "inprogress" && taskMovedFrom !== "inprogress")
{
<app-task-highlighted></app-task-highlighted>
} }
</div> </div>
</div> </div>
@ -97,9 +100,11 @@
</div> </div>
<div id="awaitfeedback" class="details"> <div id="awaitfeedback" class="details">
@for(task of getTaskStatus("awaitfeedback"); track task) { @for(task of getTaskStatus("awaitfeedback"); track task) {
<app-task [task]="task"></app-task> <app-task [task]="task"></app-task> } @empty {
} @empty {
<app-task-empty>{{ "board.noTasks" | translate }}</app-task-empty> <app-task-empty>{{ "board.noTasks" | translate }}</app-task-empty>
} @if(taskMovedTo === "awaitfeedback" && taskMovedFrom !==
"awaitfeedback") {
<app-task-highlighted></app-task-highlighted>
} }
</div> </div>
</div> </div>
@ -121,6 +126,8 @@
<app-task [task]="task"></app-task> <app-task [task]="task"></app-task>
} @empty { } @empty {
<app-task-empty>{{ "board.noTasks" | translate }}</app-task-empty> <app-task-empty>{{ "board.noTasks" | translate }}</app-task-empty>
} @if(taskMovedTo === "done" && taskMovedFrom !== "done") {
<app-task-highlighted></app-task-highlighted>
} }
</div> </div>
</div> </div>

View file

@ -36,13 +36,18 @@ export class BoardComponent {
searchValue: string = ''; searchValue: string = '';
searchInput: boolean = false; searchInput: boolean = false;
taskMovedTo: string = ''; taskMovedTo: string = '';
taskMovedFrom: string = '';
taskDropped: boolean = false;
ngOnInit() { ngOnInit() {
this.dragDropService.itemDropped.subscribe(({ id, status }) => { this.dragDropService.itemDropped.subscribe(({ id, status }) => {
this.handleItemDropped(id, status); this.handleItemDropped(id, status);
}); });
this.dragDropService.itemMoved.subscribe(({ status }) => { this.dragDropService.itemMovedTo.subscribe(({ status }) => {
this.handleItemMoved(status); this.taskMovedTo = status;
});
this.dragDropService.itemMovedFrom.subscribe(({ status }) => {
this.taskMovedFrom = status;
}); });
} }
@ -64,10 +69,6 @@ export class BoardComponent {
} }
} }
handleItemMoved(status: string) {
this.taskMovedTo = status;
}
handleItemDropped(id: string, status: string): void { handleItemDropped(id: string, status: string): void {
const index = this.firebaseService.allTasks.findIndex( const index = this.firebaseService.allTasks.findIndex(
(task) => task.id === id (task) => task.id === id

View file

@ -1 +1 @@
<p>task-highlighted works!</p> <div class="highlighted"><p>Drop here</p></div>

View file

@ -0,0 +1,27 @@
.highlighted {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
max-width: 268px;
height: 168px;
border-radius: 10px;
border: 2px dashed var(--light-blue);
background-color: var(--very-light-gray2);
box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.16);
font-size: 16px;
font-weight: 400;
color: var(--gray);
margin: 15.5px 0;
p {
font-size: 21px;
font-weight: 500;
}
}
@media screen and (max-width: 667px) {
.highlighted {
width: 100%;
max-width: 100%;
}
}

View file

@ -4,7 +4,7 @@
<div <div
class="content" class="content"
draggable="true" draggable="true"
(dragstart)="dragDropService.startDragging($event, task.id)" (dragstart)="dragDropService.startDragging($event, task.id, task.status)"
> >
<div class="header"> <div class="header">
<div <div

View file

@ -5,13 +5,15 @@ import { Injectable, EventEmitter } from '@angular/core';
}) })
export class DragDropService { export class DragDropService {
itemDropped = new EventEmitter<{ id: string; status: string }>(); itemDropped = new EventEmitter<{ id: string; status: string }>();
itemMoved = new EventEmitter<{ status: string }>(); itemMovedFrom = new EventEmitter<{ status: string }>();
itemMovedTo = new EventEmitter<{ status: string }>();
constructor() {} constructor() {}
startDragging(event: DragEvent, id: string | undefined) { startDragging(event: DragEvent, id: string | undefined, status: string) {
if (id !== undefined) { if (id !== undefined) {
event.dataTransfer?.setData('text/plain', id); event.dataTransfer?.setData('text/plain', id);
this.itemMovedFrom.emit({ status });
} }
} }
@ -19,7 +21,7 @@ export class DragDropService {
event.preventDefault(); event.preventDefault();
const dataTransfer = event.dataTransfer; const dataTransfer = event.dataTransfer;
if (dataTransfer) { if (dataTransfer) {
this.itemMoved.emit({ status }); this.itemMovedTo.emit({ status });
} }
} }
@ -30,6 +32,8 @@ export class DragDropService {
const id = dataTransfer.getData('text/plain'); const id = dataTransfer.getData('text/plain');
if (id) { if (id) {
this.itemDropped.emit({ id, status }); this.itemDropped.emit({ id, status });
status = '';
this.itemMovedTo.emit({ status });
} }
} }
} }