|
54 | 54 | let searchLoading = $state(false); |
55 | 55 | let searchDebounceTimer: ReturnType<typeof setTimeout> | null = null; |
56 | 56 |
|
| 57 | + let showImportModal = $state(false); |
| 58 | + let brewfileContent = $state(''); |
| 59 | + let importLoading = $state(false); |
| 60 | + let importError = $state(''); |
| 61 | +
|
57 | 62 | async function searchHomebrew(query: string) { |
58 | 63 | if (query.length < 2) { |
59 | 64 | searchResults = []; |
|
281 | 286 | } |
282 | 287 | return `openboot.dev/${$auth.user?.username}/${config.slug}/install`; |
283 | 288 | } |
| 289 | +
|
| 290 | + async function importBrewfile() { |
| 291 | + if (!brewfileContent.trim()) { |
| 292 | + importError = 'Please paste your Brewfile content'; |
| 293 | + return; |
| 294 | + } |
| 295 | +
|
| 296 | + importLoading = true; |
| 297 | + importError = ''; |
| 298 | +
|
| 299 | + try { |
| 300 | + const response = await fetch('/api/brewfile/parse', { |
| 301 | + method: 'POST', |
| 302 | + headers: { 'Content-Type': 'application/json' }, |
| 303 | + body: JSON.stringify({ content: brewfileContent }) |
| 304 | + }); |
| 305 | +
|
| 306 | + const data = await response.json(); |
| 307 | +
|
| 308 | + if (!response.ok) { |
| 309 | + importError = data.error || 'Failed to parse Brewfile'; |
| 310 | + return; |
| 311 | + } |
| 312 | +
|
| 313 | + if (data.packages.length === 0) { |
| 314 | + importError = 'No packages found in Brewfile'; |
| 315 | + return; |
| 316 | + } |
| 317 | +
|
| 318 | + showImportModal = false; |
| 319 | + brewfileContent = ''; |
| 320 | +
|
| 321 | + formData = { |
| 322 | + name: 'Imported Config', |
| 323 | + description: `Imported from Brewfile (${data.packages.length} packages)`, |
| 324 | + base_preset: 'minimal', |
| 325 | + is_public: true, |
| 326 | + alias: '', |
| 327 | + packages: data.packages, |
| 328 | + custom_script: '', |
| 329 | + dotfiles_repo: '' |
| 330 | + }; |
| 331 | + selectedPackages = new Set(data.packages); |
| 332 | + showModal = true; |
| 333 | + } catch (e) { |
| 334 | + importError = 'Failed to parse Brewfile'; |
| 335 | + } finally { |
| 336 | + importLoading = false; |
| 337 | + } |
| 338 | + } |
284 | 339 | </script> |
285 | 340 |
|
286 | 341 | <svelte:head> |
|
305 | 360 | <h1 class="page-title">My Configurations</h1> |
306 | 361 | <p class="page-subtitle">Create custom install configs for different teams or projects</p> |
307 | 362 | </div> |
308 | | - <Button variant="primary" onclick={() => openModal()}>+ New Config</Button> |
| 363 | + <div class="header-actions"> |
| 364 | + <Button variant="secondary" onclick={() => showImportModal = true}>Import Brewfile</Button> |
| 365 | + <Button variant="primary" onclick={() => openModal()}>+ New Config</Button> |
| 366 | + </div> |
309 | 367 | </div> |
310 | 368 |
|
311 | 369 | {#if configs.length === 0} |
|
499 | 557 | </div> |
500 | 558 | {/if} |
501 | 559 |
|
| 560 | +{#if showImportModal} |
| 561 | + <div class="modal-overlay" onclick={() => showImportModal = false}> |
| 562 | + <div class="modal import-modal" onclick={(e) => e.stopPropagation()}> |
| 563 | + <div class="modal-header"> |
| 564 | + <h3 class="modal-title">Import Brewfile</h3> |
| 565 | + <button class="close-btn" onclick={() => showImportModal = false}>×</button> |
| 566 | + </div> |
| 567 | + <div class="modal-body"> |
| 568 | + {#if importError} |
| 569 | + <div class="error-message">{importError}</div> |
| 570 | + {/if} |
| 571 | + |
| 572 | + <div class="form-group"> |
| 573 | + <label class="form-label">Paste your Brewfile content</label> |
| 574 | + <textarea |
| 575 | + class="form-textarea brewfile-input" |
| 576 | + bind:value={brewfileContent} |
| 577 | + placeholder={'tap "homebrew/cask"\nbrew "git"\nbrew "node"\ncask "visual-studio-code"\ncask "docker"'} |
| 578 | + ></textarea> |
| 579 | + <p class="form-hint">Supports tap, brew, and cask entries</p> |
| 580 | + </div> |
| 581 | + </div> |
| 582 | + <div class="modal-footer"> |
| 583 | + <Button variant="secondary" onclick={() => showImportModal = false}>Cancel</Button> |
| 584 | + <Button variant="primary" onclick={importBrewfile}>{importLoading ? 'Parsing...' : 'Import'}</Button> |
| 585 | + </div> |
| 586 | + </div> |
| 587 | + </div> |
| 588 | +{/if} |
| 589 | + |
502 | 590 | <style> |
503 | 591 | .header { |
504 | 592 | background: var(--bg-secondary); |
|
558 | 646 | margin-top: 4px; |
559 | 647 | } |
560 | 648 |
|
| 649 | + .header-actions { |
| 650 | + display: flex; |
| 651 | + gap: 8px; |
| 652 | + } |
| 653 | +
|
| 654 | + .import-modal { |
| 655 | + max-width: 500px; |
| 656 | + } |
| 657 | +
|
| 658 | + .brewfile-input { |
| 659 | + min-height: 200px; |
| 660 | + font-family: 'JetBrains Mono', monospace; |
| 661 | + font-size: 0.85rem; |
| 662 | + } |
| 663 | +
|
561 | 664 | .empty-state { |
562 | 665 | text-align: center; |
563 | 666 | padding: 60px 20px; |
|
0 commit comments