Skip to content

Commit baee246

Browse files
committed
Don't flash the open diff dialog when using patch_url param
1 parent dad57ee commit baee246

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

web/src/lib/components/files/index.svelte.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ReadableBoxedValues, type WritableBoxedValues } from "svelte-toolbelt";
1+
import { box, type ReadableBoxedValues, type WritableBoxedValues } from "svelte-toolbelt";
22
import { getExtensionForLanguage, lazyPromise } from "$lib/util";
33
import type { BundledLanguage, SpecialLanguage } from "shiki";
44
import type { Snippet } from "svelte";
@@ -236,6 +236,23 @@ export class MultimodalFileInputState {
236236
});
237237
dragActive = $state(false);
238238

239+
/**
240+
* For creating a state instance before the component is mounted.
241+
*
242+
* @returns new state instance
243+
*/
244+
static createInstance() {
245+
return new MultimodalFileInputState({
246+
state: undefined,
247+
248+
// These will be overridden by the component itself. Only the actual input state is inherited.
249+
label: box.with(() => ""),
250+
required: box.with(() => false),
251+
fileTypeOverride: box.with(() => false),
252+
defaultMode: box.with(() => "file"),
253+
});
254+
}
255+
239256
constructor(opts: MultimodalFileInputStateProps) {
240257
this.opts = opts;
241258
if (this.opts.state) {
@@ -317,5 +334,6 @@ export class MultimodalFileInputState {
317334
this.text = "";
318335
this.file = undefined;
319336
this.url = "";
337+
this.mode = this.opts.defaultMode.current;
320338
}
321339
}

web/src/lib/open-diff-dialog.svelte.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class OpenDiffDialogState {
2929

3030
githubUrl = $state("https://github.com/");
3131

32-
patchFile = $state<MultimodalFileInputState | undefined>();
32+
patchFile = $state(MultimodalFileInputState.createInstance());
3333

3434
fileOne = $state<MultimodalFileInputState | undefined>();
3535
fileTwo = $state<MultimodalFileInputState | undefined>();

web/src/routes/OpenDiffDialog.svelte

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@
2727
instance.githubUrl = githubUrlParam;
2828
await instance.handleGithubUrl();
2929
} else if (patchUrlParam !== null) {
30-
open = true;
31-
await tick();
32-
if (instance.patchFile) {
33-
instance.patchFile.reset();
34-
instance.patchFile.mode = "url";
35-
instance.patchFile.url = patchUrlParam;
36-
await instance.handlePatchFile();
37-
}
30+
instance.patchFile.reset();
31+
instance.patchFile.mode = "url";
32+
instance.patchFile.url = patchUrlParam;
33+
await instance.handlePatchFile();
3834
} else {
3935
open = true;
4036
}

0 commit comments

Comments
 (0)