Skip to content

Commit be6f9d9

Browse files
committed
[FIX] Replace closeAndReload method with direct close event dispatch for improved modal handling
1 parent 2c87040 commit be6f9d9

2 files changed

Lines changed: 3 additions & 16 deletions

File tree

  • Build/Sources/TypeScript/friendsoftypo3/content-blocks-gui
  • Resources/Public/JavaScript/content-blocks-gui

Build/Sources/TypeScript/friendsoftypo3/content-blocks-gui/upload.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export class ContentBlockUpload extends LitElement {
288288
</button>
289289
<button
290290
class="btn btn-primary ms-2"
291-
@click="${() => this.closeAndReload()}"
291+
@click="${() => this.dispatchEvent(new CustomEvent('close'))}"
292292
>
293293
Close
294294
</button>
@@ -509,19 +509,6 @@ export class ContentBlockUpload extends LitElement {
509509
return count;
510510
}
511511

512-
/**
513-
* Close modal and reload page to show updated content blocks
514-
*/
515-
protected closeAndReload(): void {
516-
// Dispatch close event to close the modal
517-
this.dispatchEvent(new CustomEvent('close'));
518-
519-
// Reload page after a short delay to ensure modal closes first
520-
setTimeout(() => {
521-
window.location.reload();
522-
}, 100);
523-
}
524-
525512
/**
526513
* Reset to upload step
527514
*/

Resources/Public/JavaScript/content-blocks-gui/upload.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ import{LitElement as m,html as i,nothing as h}from"lit";import{state as c,custom
173173
</button>
174174
<button
175175
class="btn btn-primary ms-2"
176-
@click="${()=>this.closeAndReload()}"
176+
@click="${()=>this.dispatchEvent(new CustomEvent("close"))}"
177177
>
178178
Close
179179
</button>
@@ -245,7 +245,7 @@ import{LitElement as m,html as i,nothing as h}from"lit";import{state as c,custom
245245
</div>
246246
</div>
247247
</div>
248-
`}handleFileSelect(e){const t=e.target;this.uploadedFile=t.files?.[0]||null,this.error=null}async handleAnalyze(){if(this.uploadedFile){this.isUploading=!0,this.error=null;try{const e=new FormData;e.append("file",this.uploadedFile),e.append("targetExtension",this.targetExtension);const s=await(await new u(TYPO3.settings.ajaxUrls.content_blocks_gui_upload).post(e)).resolve();s.success?(this.analysis=s.analysis,this.step="analysis",this.conflicts.clear(),s.analysis.blocks.forEach(r=>{r.conflict!==""&&this.conflicts.set(r.name,"skip")}),this.requestUpdate()):this.error=s.error||"Failed to analyze ZIP file"}catch(e){let t="Unknown error";if(e?.response)try{const s=await e.response.json();t=s.error||s.message||t}catch{t=e.response.statusText||t}else e instanceof Error?t=e.message:typeof e=="string"&&(t=e);this.error=t}finally{this.isUploading=!1}}}async handleImport(){if(this.analysis){this.step="import";try{const e={};this.conflicts.forEach((r,n)=>{e[n]=r});const s=await(await new u(TYPO3.settings.ajaxUrls.content_blocks_gui_import).post({analysis:this.analysis,targetExtension:this.targetExtension,conflicts:e})).resolve();s.success?(this.result=s.result,this.step="result"):(this.error=s.error||"Failed to import content blocks",this.step="upload")}catch(e){const t=e instanceof Error?e.message:"Unknown error";this.error=`Failed to import: ${t}`,this.step="upload"}}}setConflictResolution(e,t){this.conflicts.set(e,t),this.requestUpdate()}getImportCount(){if(!this.analysis)return 0;let e=0;return this.analysis.blocks.forEach(t=>{(t.conflict===""||this.conflicts.get(t.name)==="overwrite")&&e++}),e}closeAndReload(){this.dispatchEvent(new CustomEvent("close")),setTimeout(()=>{window.location.reload()},100)}resetToUpload(){this.step="upload",this.uploadedFile=null,this.analysis=null,this.result=null,this.error=null,this.conflicts.clear();const e=this.querySelector("#zipFile");e&&(e.value="")}renderBlocksByType(e,t,s){if(e.length===0)return h;const r=this.groupByType(e);return i`
248+
`}handleFileSelect(e){const t=e.target;this.uploadedFile=t.files?.[0]||null,this.error=null}async handleAnalyze(){if(this.uploadedFile){this.isUploading=!0,this.error=null;try{const e=new FormData;e.append("file",this.uploadedFile),e.append("targetExtension",this.targetExtension);const s=await(await new u(TYPO3.settings.ajaxUrls.content_blocks_gui_upload).post(e)).resolve();s.success?(this.analysis=s.analysis,this.step="analysis",this.conflicts.clear(),s.analysis.blocks.forEach(r=>{r.conflict!==""&&this.conflicts.set(r.name,"skip")}),this.requestUpdate()):this.error=s.error||"Failed to analyze ZIP file"}catch(e){let t="Unknown error";if(e?.response)try{const s=await e.response.json();t=s.error||s.message||t}catch{t=e.response.statusText||t}else e instanceof Error?t=e.message:typeof e=="string"&&(t=e);this.error=t}finally{this.isUploading=!1}}}async handleImport(){if(this.analysis){this.step="import";try{const e={};this.conflicts.forEach((r,n)=>{e[n]=r});const s=await(await new u(TYPO3.settings.ajaxUrls.content_blocks_gui_import).post({analysis:this.analysis,targetExtension:this.targetExtension,conflicts:e})).resolve();s.success?(this.result=s.result,this.step="result"):(this.error=s.error||"Failed to import content blocks",this.step="upload")}catch(e){const t=e instanceof Error?e.message:"Unknown error";this.error=`Failed to import: ${t}`,this.step="upload"}}}setConflictResolution(e,t){this.conflicts.set(e,t),this.requestUpdate()}getImportCount(){if(!this.analysis)return 0;let e=0;return this.analysis.blocks.forEach(t=>{(t.conflict===""||this.conflicts.get(t.name)==="overwrite")&&e++}),e}resetToUpload(){this.step="upload",this.uploadedFile=null,this.analysis=null,this.result=null,this.error=null,this.conflicts.clear();const e=this.querySelector("#zipFile");e&&(e.value="")}renderBlocksByType(e,t,s){if(e.length===0)return h;const r=this.groupByType(e);return i`
249249
<h4 class="mt-3">${t} (${e.length})</h4>
250250
${r.map(([n,o])=>i`
251251
<h5 class="mt-2 text-muted">${this.getTypeLabel(n)}s (${o.length})</h5>

0 commit comments

Comments
 (0)