diff --git a/apps/desktop/src/lib/pr/PrDetailsModal.svelte b/apps/desktop/src/lib/pr/PrDetailsModal.svelte index e6c73231e..db52af2db 100644 --- a/apps/desktop/src/lib/pr/PrDetailsModal.svelte +++ b/apps/desktop/src/lib/pr/PrDetailsModal.svelte @@ -87,7 +87,7 @@ props.type === 'preview-series' ? props.currentSeries.name : branch.upstreamName ); const baseBranchName = $derived($baseBranch.shortName); - const currentSeries = props.type === 'preview-series' ? props.currentSeries : undefined; + const currentSeries = $derived(props.type === 'preview-series' ? props.currentSeries : undefined); let createPrDropDown = $state>(); const createDraft = persisted(false, 'createDraftPr'); @@ -169,6 +169,9 @@ return; } + // All ids that existed prior to creating a new one (including archived). + const priorIds = branch.series.map((series) => series.prNumber).filter(isDefined); + isLoading = true; try { let upstreamBranchName = upstreamName; @@ -202,9 +205,6 @@ return; } - // All ids that existed prior to creating a new one (including archived). - const priorIds = branch.series.map((series) => series.prNumber).filter(isDefined); - // Find the index of the current branch so we know where we want to point the pr. const branches = branch.series; const currentIndex = branches.findIndex((b) => b.name === currentSeries.name); diff --git a/apps/desktop/src/lib/vbranches/types.ts b/apps/desktop/src/lib/vbranches/types.ts index c58a07a4c..c60a41357 100644 --- a/apps/desktop/src/lib/vbranches/types.ts +++ b/apps/desktop/src/lib/vbranches/types.ts @@ -2,7 +2,7 @@ import 'reflect-metadata'; import { emptyConflictEntryPresence, type ConflictEntryPresence } from '$lib/conflictEntryPresence'; import { splitMessage } from '$lib/utils/commitMessage'; import { hashCode } from '@gitbutler/ui/utils/string'; -import { isDefined, notNull } from '@gitbutler/ui/utils/typeguards'; +import { isDefined } from '@gitbutler/ui/utils/typeguards'; import { Type, Transform } from 'class-transformer'; import type { PullRequest } from '$lib/forge/interface/types'; @@ -80,10 +80,7 @@ export class LocalFile { } get lockedIds(): HunkLock[] { - return this.hunks - .flatMap((hunk) => hunk.lockedTo) - .filter(notNull) - .filter(isDefined); + return this.hunks.flatMap((hunk) => hunk.lockedTo).filter(isDefined); } } diff --git a/packages/ui/src/lib/utils/typeguards.ts b/packages/ui/src/lib/utils/typeguards.ts index 90132d3d2..472b93966 100644 --- a/packages/ui/src/lib/utils/typeguards.ts +++ b/packages/ui/src/lib/utils/typeguards.ts @@ -1,9 +1,9 @@ +/** + * Not undefined and not null. This is less prone for errors than checking undefined + * and not null separately. + */ export function isDefined(file: T | undefined | null): file is T { - return file !== undefined; -} - -export function notNull(file: T | undefined | null): file is T { - return file !== null; + return file !== undefined && file !== null; } export type UnknownObject = Record;