|
6 | 6 | import { goto } from "$app/navigation"; |
7 | 7 | import { makeImageDetails, makeTextDetails, MultiFileDiffViewerState } from "$lib/diff-viewer-multi-file.svelte"; |
8 | 8 | import { binaryFileDummyDetails, bytesEqual, isBinaryFile, isImageFile, parseMultiFilePatch } from "$lib/util"; |
9 | | - import { onMount } from "svelte"; |
| 9 | + import { onMount, tick } from "svelte"; |
10 | 10 | import { createTwoFilesPatch } from "diff"; |
11 | 11 | import DirectorySelect from "$lib/components/files/DirectorySelect.svelte"; |
12 | 12 | import { DirectoryEntry, FileEntry, MultimodalFileInputState, type MultimodalFileInputValueMetadata } from "$lib/components/files/index.svelte"; |
|
49 | 49 | dirBlacklistInput = ""; |
50 | 50 | } |
51 | 51 |
|
| 52 | + const PATCH_URL_PARAM = "patch_url"; |
| 53 | +
|
52 | 54 | 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; |
56 | 60 | 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 | + } |
57 | 70 | } else { |
58 | 71 | modalOpen = true; |
59 | 72 | } |
|
293 | 306 | modalOpen = true; |
294 | 307 | return; |
295 | 308 | } |
296 | | - await updateUrlParams(); |
| 309 | + let patchUrl: string | undefined; |
| 310 | + if (patchFile.mode === "url") { |
| 311 | + patchUrl = patchFile.url; |
| 312 | + } |
| 313 | + await updateUrlParams({ patchUrl }); |
297 | 314 | } |
298 | 315 |
|
299 | 316 | async function handleGithubUrl() { |
|
319 | 336 | modalOpen = true; |
320 | 337 | } |
321 | 338 |
|
322 | | - async function updateUrlParams(opts: { githubUrl?: string } = {}) { |
| 339 | + async function updateUrlParams(opts: { githubUrl?: string; patchUrl?: string } = {}) { |
323 | 340 | const newUrl = new URL(page.url); |
324 | 341 | if (opts.githubUrl) { |
325 | 342 | newUrl.searchParams.set(GITHUB_URL_PARAM, opts.githubUrl); |
326 | 343 | } else { |
327 | 344 | newUrl.searchParams.delete(GITHUB_URL_PARAM); |
328 | 345 | } |
| 346 | + if (opts.patchUrl) { |
| 347 | + newUrl.searchParams.set(PATCH_URL_PARAM, opts.patchUrl); |
| 348 | + } else { |
| 349 | + newUrl.searchParams.delete(PATCH_URL_PARAM); |
| 350 | + } |
329 | 351 | await goto(`?${newUrl.searchParams}`); |
330 | 352 | } |
331 | 353 | </script> |
|
0 commit comments