Check for locked status correctly

- always check on boolean property instead of array length
This commit is contained in:
Mattias Granlund 2024-04-05 13:35:15 +02:00
parent 04fb7848ce
commit f4ba84753b
4 changed files with 16 additions and 6 deletions

View File

@ -120,7 +120,7 @@
if (data instanceof DraggableHunk && data.branchId != branch.id) {
return !data.hunk.locked;
} else if (data instanceof DraggableFile && data.branchId && data.branchId != branch.id) {
return !data.files.some((f) => !!f.lockedIds);
return !data.files.some((f) => f.locked);
} else {
return false;
}

View File

@ -78,7 +78,7 @@
class="file-list-item"
class:selected-draggable={selected}
id={`file-${file.id}`}
data-locked={file.lockedIds.length > 0}
data-locked={file.locked}
on:click
on:keydown
on:dragstart={() => {
@ -90,7 +90,7 @@
if ($selectedFiles.length > 0) {
$selectedFiles.forEach((f) => {
if (f.lockedIds.length > 0) {
if (f.locked) {
const lockedElement = document.getElementById(`file-${f.id}`);
if (lockedElement) {
@ -99,13 +99,13 @@
}
}
});
} else if (file.lockedIds.length > 0) {
} else if (file.locked) {
draggableElt.classList.add('locked-file-animation');
}
}}
on:animationend={() => {
// remove the class after the animation ends
if (file.lockedIds.length > 0) {
if (file.locked) {
draggableElt.classList.remove('locked-file-animation');
}
}}

View File

@ -15,7 +15,7 @@
const branchController = getContext(BranchController);
function accepts(data: any) {
if (data instanceof DraggableFile) return !data.files.some((f) => !!f.lockedIds);
if (data instanceof DraggableFile) return !data.files.some((f) => f.locked);
if (data instanceof DraggableHunk) return !data.hunk.locked;
return false;
}

View File

@ -56,6 +56,12 @@ export class LocalFile {
return this.hunks.map((h) => h.id);
}
get locked(): boolean {
return this.hunks
? this.hunks.map((hunk) => hunk.lockedTo).reduce((a, b) => !!(a || b), false)
: false;
}
get lockedIds(): string[] {
return this.hunks
.map((hunk) => hunk.lockedTo)
@ -239,6 +245,10 @@ export class RemoteFile {
get lockedIds(): string[] {
return [];
}
get locked(): boolean {
return false;
}
}
export interface Author {