|
1 | 1 | <script lang="ts"> |
2 | | - import { onMount } from "svelte"; |
| 2 | + import { onMount, type Component } from "svelte"; |
3 | 3 | import WorktreeList from "./lib/WorktreeList.svelte"; |
4 | 4 | import TopBar from "./lib/TopBar.svelte"; |
5 | 5 | import Terminal from "./lib/Terminal.svelte"; |
|
8 | 8 | import SettingsDialog from "./lib/SettingsDialog.svelte"; |
9 | 9 | import CiDetailsDialog from "./lib/CiDetailsDialog.svelte"; |
10 | 10 | import CommentReviewDialog from "./lib/CommentReviewDialog.svelte"; |
11 | | - import DiffDialog from "./lib/DiffDialog.svelte"; |
12 | 11 | import PaneBar from "./lib/PaneBar.svelte"; |
13 | 12 | import ToastStack from "./lib/ToastStack.svelte"; |
14 | 13 | import LinearPanel from "./lib/LinearPanel.svelte"; |
|
20 | 19 | AppConfig, |
21 | 20 | AppNotification, |
22 | 21 | CreateWorktreeRequest, |
| 22 | + DiffDialogProps, |
23 | 23 | PrEntry, |
24 | 24 | LinearIssueAvailability, |
25 | 25 | LinearIssue, |
|
81 | 81 | let ciDetailsPr = $state<PrEntry | null>(null); |
82 | 82 | let commentReviewPr = $state<PrEntry | null>(null); |
83 | 83 | let showDiffDialog = $state(false); |
| 84 | + let DiffDialogComponent = $state<Component<DiffDialogProps> | null>(null); |
84 | 85 | let pullMainConfirm = $state(false); |
85 | 86 | let pullMainLoading = $state(false); |
86 | 87 | let pullMainError = $state(""); |
|
114 | 115 | let availableBranchRequests: Partial<Record<BranchCacheKey, Promise<AvailableBranch[]>>> = {}; |
115 | 116 | let baseBranchCache: AvailableBranch[] | null = null; |
116 | 117 | let baseBranchRequest: Promise<AvailableBranch[]> | null = null; |
| 118 | + let diffDialogLoad: Promise<void> | null = null; |
117 | 119 |
|
118 | 120 | // Linear integration |
119 | 121 | let linearIssues = $state<LinearIssue[]>([]); |
|
229 | 231 | }, AUTO_DISMISS_MS); |
230 | 232 | } |
231 | 233 |
|
| 234 | + function ensureDiffDialogLoaded(): Promise<void> { |
| 235 | + if (DiffDialogComponent) return Promise.resolve(); |
| 236 | + if (diffDialogLoad) return diffDialogLoad; |
| 237 | +
|
| 238 | + diffDialogLoad = import("./lib/DiffDialog.svelte") |
| 239 | + .then(({ default: component }) => { |
| 240 | + DiffDialogComponent = component; |
| 241 | + }) |
| 242 | + .finally(() => { |
| 243 | + diffDialogLoad = null; |
| 244 | + }); |
| 245 | +
|
| 246 | + return diffDialogLoad; |
| 247 | + } |
| 248 | +
|
| 249 | + async function openDiffDialog(): Promise<void> { |
| 250 | + try { |
| 251 | + await ensureDiffDialogLoaded(); |
| 252 | + showDiffDialog = true; |
| 253 | + } catch (err: unknown) { |
| 254 | + showToast({ |
| 255 | + tone: "error", |
| 256 | + message: "Failed to load changes view.", |
| 257 | + detail: errorMessage(err), |
| 258 | + }); |
| 259 | + } |
| 260 | + } |
| 261 | +
|
232 | 262 | function handleInitialNotification(n: AppNotification): void { |
233 | 263 | if (notificationHistory.some((x) => x.id === n.id)) return; |
234 | 264 | notificationHistory = [n, ...notificationHistory].slice(0, MAX_HISTORY); |
|
1068 | 1098 | if (selectedBranch) removeBranch = selectedBranch; |
1069 | 1099 | }} |
1070 | 1100 | onsettings={() => (showSettingsDialog = true)} |
1071 | | - ondirtyclick={() => (showDiffDialog = true)} |
| 1101 | + ondirtyclick={openDiffDialog} |
1072 | 1102 | onCiClick={(pr) => (ciDetailsPr = pr)} |
1073 | 1103 | onReviewsClick={(pr) => (commentReviewPr = pr)} |
1074 | 1104 | onbellopen={handleBellOpen} |
|
1240 | 1270 | /> |
1241 | 1271 | {/if} |
1242 | 1272 |
|
1243 | | -{#if showDiffDialog && selectedBranch} |
1244 | | - <DiffDialog |
| 1273 | +{#if showDiffDialog && selectedBranch && DiffDialogComponent} |
| 1274 | + <DiffDialogComponent |
1245 | 1275 | branch={selectedBranch} |
1246 | 1276 | cursorUrl={makeCursorUrl(selectedWorktree?.dir, sshHost)} |
1247 | 1277 | onclose={() => (showDiffDialog = false)} |
|
0 commit comments