import { Controller } from "@hotwired/stimulus" import {showToast} from "../services/toast"; export default class ShowUploadController extends Controller { static values = { copySnippet: String, siteId: Number, uploadId: Number, }; async copy(ev) { ev.preventDefault(); await navigator.clipboard.writeText(this.copySnippetValue); showToast({ title: "️📋 HTML Snippet", body: "Copied to clipboard.", }); } async delete(ev) { ev.preventDefault(); if (!confirm("Are you sure you want to delete this upload?")) { return; } await this._doDelete(); window.location = `/sites/${this.siteIdValue}/uploads/`; } async _doDelete() { const url = `/sites/${this.siteIdValue}/uploads/${this.uploadIdValue}` await fetch(url, { method: 'DELETE', headers: { 'Accept': 'application/json' } }) } }