Skip to content

Commit 5b516c1

Browse files
committed
Add patch_url param
1 parent 8b7c9a9 commit 5b516c1

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

web/src/routes/OpenDiffDialog.svelte

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { goto } from "$app/navigation";
77
import { makeImageDetails, makeTextDetails, MultiFileDiffViewerState } from "$lib/diff-viewer-multi-file.svelte";
88
import { binaryFileDummyDetails, bytesEqual, isBinaryFile, isImageFile, parseMultiFilePatch } from "$lib/util";
9-
import { onMount } from "svelte";
9+
import { onMount, tick } from "svelte";
1010
import { createTwoFilesPatch } from "diff";
1111
import DirectorySelect from "$lib/components/files/DirectorySelect.svelte";
1212
import { DirectoryEntry, FileEntry, MultimodalFileInputState, type MultimodalFileInputValueMetadata } from "$lib/components/files/index.svelte";
@@ -49,11 +49,24 @@
4949
dirBlacklistInput = "";
5050
}
5151
52+
const PATCH_URL_PARAM = "patch_url";
53+
5254
onMount(async () => {
53-
const url = page.url.searchParams.get(GITHUB_URL_PARAM);
54-
if (url !== null) {
55-
githubUrl = url;
55+
const githubUrlParam = page.url.searchParams.get(GITHUB_URL_PARAM);
56+
const patchUrlParam = page.url.searchParams.get(PATCH_URL_PARAM);
57+
58+
if (githubUrlParam !== null) {
59+
githubUrl = githubUrlParam;
5660
await handleGithubUrl();
61+
} else if (patchUrlParam !== null) {
62+
modalOpen = true;
63+
await tick();
64+
if (patchFile) {
65+
patchFile.reset();
66+
patchFile.mode = "url";
67+
patchFile.url = patchUrlParam;
68+
await handlePatchFile();
69+
}
5770
} else {
5871
modalOpen = true;
5972
}
@@ -293,7 +306,11 @@
293306
modalOpen = true;
294307
return;
295308
}
296-
await updateUrlParams();
309+
let patchUrl: string | undefined;
310+
if (patchFile.mode === "url") {
311+
patchUrl = patchFile.url;
312+
}
313+
await updateUrlParams({ patchUrl });
297314
}
298315
299316
async function handleGithubUrl() {
@@ -319,13 +336,18 @@
319336
modalOpen = true;
320337
}
321338
322-
async function updateUrlParams(opts: { githubUrl?: string } = {}) {
339+
async function updateUrlParams(opts: { githubUrl?: string; patchUrl?: string } = {}) {
323340
const newUrl = new URL(page.url);
324341
if (opts.githubUrl) {
325342
newUrl.searchParams.set(GITHUB_URL_PARAM, opts.githubUrl);
326343
} else {
327344
newUrl.searchParams.delete(GITHUB_URL_PARAM);
328345
}
346+
if (opts.patchUrl) {
347+
newUrl.searchParams.set(PATCH_URL_PARAM, opts.patchUrl);
348+
} else {
349+
newUrl.searchParams.delete(PATCH_URL_PARAM);
350+
}
329351
await goto(`?${newUrl.searchParams}`);
330352
}
331353
</script>

0 commit comments

Comments
 (0)