diff --git a/.github/workflows/typecheck.yml b/.github/workflows/typecheck.yml new file mode 100644 index 0000000..3b7f581 --- /dev/null +++ b/.github/workflows/typecheck.yml @@ -0,0 +1,31 @@ +name: Typecheck + +on: + push: + branches: + - main + - master + pull_request: + +permissions: + contents: read + +jobs: + typecheck: + name: Typecheck + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Run TypeScript typecheck + run: npx tsc -p tsconfig.json diff --git a/package.json b/package.json index 6ad8802..ec403de 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "@workadventure/map-starter-kit-core", "version": "1.1.0", "description": "Core app, HTML pages and static assets for the WorkAdventure Map Starter Kit. Update this package to get new UI and server features without touching your maps or config.", + "type": "module", "main": "dist/server.js", "types": "dist/server.d.ts", "scripts": { @@ -35,13 +36,11 @@ "exports": { ".": { "types": "./dist/server.d.ts", - "import": "./dist/server.js", - "require": "./dist/server.js" + "import": "./dist/server.js" }, "./dist/server.js": { "types": "./dist/server.d.ts", - "import": "./dist/server.js", - "require": "./dist/server.js" + "import": "./dist/server.js" } }, "dependencies": { diff --git a/public/assets/js/index.js b/public/assets/js/index.js index cf6c999..190d7d1 100644 --- a/public/assets/js/index.js +++ b/public/assets/js/index.js @@ -162,4 +162,71 @@ async function loadTMJ() { } } -export { getMapsList, getImagesList, createBackgroundImageFade, loadTMJ }; +async function setupPublishingActions() { + const publishButton = document.getElementById('publishNowButton'); + if (!publishButton) return; + const isInitiallyEnabled = !publishButton.disabled; + + publishButton.addEventListener('click', async () => { + if (publishButton.disabled) { + return; + } + const defaultLabel = publishButton.textContent; + publishButton.disabled = true; + publishButton.setAttribute('aria-disabled', 'true'); + publishButton.setAttribute('aria-busy', 'true'); + publishButton.textContent = 'Publishing...'; + const startTime = Date.now(); + const minDuration = 2000; + const mapStorageInput = document.getElementById('mapStorageURL'); + const mapStorageUrl = mapStorageInput && 'value' in mapStorageInput + ? mapStorageInput.value + : ''; + + if (typeof window.showLoadingOverlay === 'function') { + window.showLoadingOverlay('Publishing your map...'); + } + + try { + const response = await fetch('/uploader/upload', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + } + }); + + if (!response.ok) { + const errorData = await response.json().catch(() => ({})); + const errorMessage = errorData.message || errorData.error || 'Failed to publish maps. Please try again.'; + throw new Error(errorMessage); + } + + const elapsed = Date.now() - startTime; + if (elapsed < minDuration) { + await new Promise(resolve => setTimeout(resolve, minDuration - elapsed)); + } + + const redirectUrl = typeof window.getPostPublishRedirect === 'function' + ? window.getPostPublishRedirect(mapStorageUrl) + : '/step4-validated'; + window.location.href = redirectUrl; + } catch (error) { + console.error('Error publishing maps:', error); + if (typeof window.hideLoadingOverlay === 'function') { + window.hideLoadingOverlay(); + } + const errorMessage = error instanceof Error ? error.message : 'An error occurred while publishing maps.'; + if (typeof window.showErrorPopup === 'function') { + window.showErrorPopup(errorMessage); + } else { + window.alert(errorMessage); + } + publishButton.textContent = defaultLabel; + publishButton.removeAttribute('aria-busy'); + publishButton.disabled = !isInitiallyEnabled; + publishButton.setAttribute('aria-disabled', String(!isInitiallyEnabled)); + } + }); +} + +export { getMapsList, getImagesList, createBackgroundImageFade, loadTMJ, setupPublishingActions }; diff --git a/public/assets/views/index.html b/public/assets/views/index.html index 188781b..f551e05 100644 --- a/public/assets/views/index.html +++ b/public/assets/views/index.html @@ -1,71 +1,29 @@ -
- - - - - - - - -