Skip to content

Commit 19d8c32

Browse files
authored
import manifest from query (#522)
* Update index.js * Support multiple manifest URLs via query params Add support for multiple manifest query parameters by storing them in a private queue (#manifestQueue) with a current index (#manifestIndex). Update prefill logic to load the first manifest, show contextual loading feedback, and keep the form ready for subsequent submissions. Introduce #advanceQueue() to load the next manifest into the input and append a progress note after each import attempt; call it from the import finally block. Also avoid clearing feedback in setLoadingState when toggling loading off so progress messages persist.
1 parent c9febbd commit 19d8c32

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

components/import-project/index.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { CleanupRegistry } from '../../utilities/CleanupRegistry.js'
88
class ProjectImporter extends HTMLElement {
99
/** @type {CleanupRegistry} Registry for cleanup handlers */
1010
cleanup = new CleanupRegistry()
11+
/** @type {string[]} Ordered list of manifest URLs provided via query params */
12+
#manifestQueue = []
13+
/** @type {number} Current position in the manifest queue */
14+
#manifestIndex = 0
1115

1216
constructor() {
1317
super()
@@ -33,6 +37,17 @@ class ProjectImporter extends HTMLElement {
3337
gap: 10px;
3438
max-width: 400px;
3539
}
40+
.hint {
41+
margin: 0;
42+
color: #4a4a4a;
43+
font-size: 0.95rem;
44+
line-height: 1.4;
45+
}
46+
.hint code {
47+
background: #f1f1f1;
48+
padding: 2px 4px;
49+
border-radius: 4px;
50+
}
3651
input, button {
3752
padding: 10px;
3853
font-size: 1rem;
@@ -76,6 +91,7 @@ class ProjectImporter extends HTMLElement {
7691
</style>
7792
<div class="importer-container">
7893
<h3>Create Project from Manifest URL</h3>
94+
<p class="hint">Tip: this page supports direct links like <code>/project/import?manifest=https://example.com/manifest.json</code>.</p>
7995
<label for="url">Manifest URL:</label>
8096
<input type="url" id="url" placeholder="Enter manifest URL..." />
8197
<button id="submit">Import Project</button>
@@ -95,16 +111,56 @@ class ProjectImporter extends HTMLElement {
95111
this.feedback = this.shadowRoot.querySelector('#feedback')
96112
this.projectInfoContainer = this.shadowRoot.querySelector('#project-info-container')
97113

114+
this.#prefillManifestFromQuery()
115+
98116
const importHandler = this.handleImport.bind(this)
99117
this.cleanup.onElement(this.submitButton, 'click', importHandler)
100118
}
119+
120+
/**
121+
* Prefill the manifest URL input from inbound query params.
122+
* Supports links like /project/import?manifest=https://example.com/manifest.json
123+
* When multiple manifest values are provided, stores them as a queue and
124+
* prompts the user to submit repeatedly to iterate through the list.
125+
*/
126+
#prefillManifestFromQuery() {
127+
const params = new URLSearchParams(window.location.search)
128+
this.#manifestQueue = params.getAll('manifest').map(value => value?.trim()).filter(Boolean)
129+
130+
if (this.#manifestQueue.length === 0) return
131+
132+
this.#manifestIndex = 0
133+
this.urlInput.value = this.#manifestQueue[0]
134+
135+
this.feedback.className = 'loading'
136+
if (this.#manifestQueue.length > 1) {
137+
this.feedback.textContent = `Manifest 1 of ${this.#manifestQueue.length} loaded. Submit to import, then submit again to iterate through your list.`
138+
} else {
139+
this.feedback.textContent = 'Manifest URL loaded from link. Review it and click Import Project when ready.'
140+
}
141+
}
142+
143+
/**
144+
* Advances to the next manifest in the queue after a successful or failed import.
145+
* Loads the next URL into the input and appends a progress note to the current feedback.
146+
*/
147+
#advanceQueue() {
148+
const nextIndex = this.#manifestIndex + 1
149+
if (nextIndex >= this.#manifestQueue.length) return
150+
151+
this.#manifestIndex = nextIndex
152+
this.urlInput.value = this.#manifestQueue[nextIndex]
153+
154+
const progressNote = document.createElement('small')
155+
progressNote.textContent = ` — Manifest ${nextIndex + 1} of ${this.#manifestQueue.length} ready. Submit again to continue.`
156+
this.feedback.appendChild(progressNote)
157+
}
101158
setLoadingState(isLoading) {
102159
if (isLoading) {
103160
this.feedback.textContent = 'Importing project, please wait...'
104161
this.feedback.className = 'loading'
105162
this.submitButton.disabled = true
106163
} else {
107-
this.feedback.textContent = ''
108164
this.submitButton.disabled = false
109165
}
110166
}
@@ -150,6 +206,7 @@ class ProjectImporter extends HTMLElement {
150206
this.feedback.className = 'error'
151207
} finally {
152208
this.setLoadingState(false)
209+
this.#advanceQueue()
153210
}
154211
}
155212

0 commit comments

Comments
 (0)