From f4ba84753bb8ae1086aa1b53e5f0242587e77434 Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Fri, 5 Apr 2024 13:35:15 +0200 Subject: [PATCH] Check for locked status correctly - always check on boolean property instead of array length --- app/src/lib/components/BranchCard.svelte | 2 +- app/src/lib/components/FileListItem.svelte | 8 ++++---- app/src/lib/components/NewBranchDropZone.svelte | 2 +- app/src/lib/vbranches/types.ts | 10 ++++++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/lib/components/BranchCard.svelte b/app/src/lib/components/BranchCard.svelte index d0b2d44fe..bb9d02aa9 100644 --- a/app/src/lib/components/BranchCard.svelte +++ b/app/src/lib/components/BranchCard.svelte @@ -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; } diff --git a/app/src/lib/components/FileListItem.svelte b/app/src/lib/components/FileListItem.svelte index 65ee40709..1a3fbe256 100644 --- a/app/src/lib/components/FileListItem.svelte +++ b/app/src/lib/components/FileListItem.svelte @@ -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'); } }} diff --git a/app/src/lib/components/NewBranchDropZone.svelte b/app/src/lib/components/NewBranchDropZone.svelte index b1c246570..9739dce12 100644 --- a/app/src/lib/components/NewBranchDropZone.svelte +++ b/app/src/lib/components/NewBranchDropZone.svelte @@ -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; } diff --git a/app/src/lib/vbranches/types.ts b/app/src/lib/vbranches/types.ts index feb368a38..af33afcf4 100644 --- a/app/src/lib/vbranches/types.ts +++ b/app/src/lib/vbranches/types.ts @@ -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 {