commit e7f2e3235dbb4c7d149301e029493f58e56fc565
parent a668d45d1ebc87b4570796d186ebfc5669428b86
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Fri, 11 Oct 2024 14:03:06 -0700
Use handle_wrap in all pages
Also display error in floorplans fetch (for example, if the user
is unsubscribed).
Diffstat:
10 files changed, 42 insertions(+), 41 deletions(-)
diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js
@@ -23,6 +23,26 @@ const params = {
const panBit = 1
const zoomBit = 2
+const modes = {
+ None: {
+ handlers: {
+ contextmenu: preventDefaultHandler
+ }
+ },
+ Precise: {
+ points: true,
+ handlers: {
+ contextmenu: preventDefaultHandler,
+ pointerdown: [selectionHandler, precisePointHandler, precisePointMapHandler, furnitureHandler],
+ pointermove: [precisePointHandler, furnitureHandler],
+ pointerup: [precisePointHandler, precisePointMapHandler, furnitureHandler],
+ keydown: [controlKeyHandler, zoomKeysHandler, undoRedoHandler],
+ dblclick: [precisePointMapHandler, furnitureHandler],
+ select: selectHandler
+ }
+ }
+}
+
let State = {
panZoom: 0,
pointOp: 'Create',
@@ -32,6 +52,8 @@ let State = {
// turn off bubbling
const escapeEvent = new Event("escape")
+etc.handle_wrap(init)
+
function init() {
// Just to get stuff out of the way for now
let debug = (new URLSearchParams(new URL(document.URL).search)).get("debug") != undefined
@@ -356,26 +378,6 @@ function selector(things, select, options) {
return form
}
-let modes = {
- None: {
- handlers: {
- contextmenu: preventDefaultHandler
- }
- },
- Precise: {
- points: true,
- handlers: {
- contextmenu: preventDefaultHandler,
- pointerdown: [selectionHandler, precisePointHandler, precisePointMapHandler, furnitureHandler],
- pointermove: [precisePointHandler, furnitureHandler],
- pointerup: [precisePointHandler, precisePointMapHandler, furnitureHandler],
- keydown: [controlKeyHandler, zoomKeysHandler, undoRedoHandler],
- dblclick: [precisePointMapHandler, furnitureHandler],
- select: selectHandler
- }
- }
-}
-
// pointerdown
function selectionHandler(event, editor) {
if (event.pointerType === "mouse" && event.button === buttons.right) {
@@ -1295,5 +1297,3 @@ function precision(a) {
}
return p
}
-
-window.onload = init
diff --git a/files/floorplans/main.js b/files/floorplans/main.js
@@ -5,6 +5,8 @@ import * as ui from "/lib/ui.js"
// These are in the order they should appear
const editables = [ "name", "address", "synopsis" ]
+etc.handle_wrap(init)
+
function init() {
etc.authorize()
etc.bar()
@@ -26,6 +28,7 @@ function init() {
api.fetch("GET", "floorplans/:user")
.then(show_floorplans)
+ .catch(etc.error)
}
function listview() {
@@ -291,5 +294,3 @@ function show_floorplans(floorplans) {
list.append(create_floorplan_item(floorplans[i]))
}
}
-
-window.onload = etc.handle_wrap(init)
diff --git a/files/login/main.js b/files/login/main.js
@@ -14,4 +14,4 @@ function init() {
document.body.appendChild(ui.login({ callback: function() { window.location.href = default_page } }))
}
-window.onload = etc.handle_wrap(init)
+etc.handle_wrap(init)
diff --git a/files/logout/main.js b/files/logout/main.js
@@ -1,11 +1,11 @@
-let default_page = "/"
-
import * as api from "/lib/api.js"
import * as etc from "/lib/etc.js"
+let default_page = "/"
+
+etc.handle_wrap(init)
+
function init() {
api.update_token(null)
window.location.href = default_page
}
-
-window.onload = etc.handle_wrap(init)
diff --git a/files/main.js b/files/main.js
@@ -1,7 +1,7 @@
import * as etc from "/lib/etc.js"
+etc.handle_wrap(main)
+
function main() {
etc.bar()
}
-
-main()
diff --git a/files/register/main.js b/files/register/main.js
@@ -2,6 +2,8 @@ import * as api from "/lib/api.js"
import * as etc from "/lib/etc.js"
import * as ui from "/lib/ui.js"
+etc.handle_wrap(init)
+
function init() {
if (api.authorized()) {
// Maybe don't do this?
@@ -47,5 +49,3 @@ function init() {
})
})
}
-
-window.onload = etc.handle_wrap(init)
diff --git a/files/services/main.js b/files/services/main.js
@@ -1,6 +1,8 @@
import * as etc from "/lib/etc.js"
import * as api from "/lib/api.js"
+etc.handle_wrap(main)
+
function main() {
let wait = document.body.appendChild(document.createElement("p"))
wait.appendChild(document.createTextNode("Please wait..."))
@@ -97,5 +99,3 @@ function durationString(price) {
}
return String(price.intervalCount) + "mo"
}
-
-main()
diff --git a/files/settings/billing/main.js b/files/settings/billing/main.js
@@ -1,6 +1,8 @@
import * as etc from "/lib/etc.js"
import * as api from "/lib/api.js"
+etc.handle_wrap(main)
+
function main() {
if (!api.authorized()) {
window.location.href = "/login"
@@ -15,5 +17,3 @@ function main() {
etc.error("There was an unexpected error.")
})
}
-
-main()
diff --git a/files/settings/main.js b/files/settings/main.js
@@ -2,6 +2,8 @@ import * as api from "/lib/api.js"
import * as etc from "/lib/etc.js"
import * as ui from "/lib/ui.js"
+etc.handle_wrap(init)
+
function init() {
etc.authorize()
etc.bar()
@@ -232,5 +234,3 @@ function get_info_element(key) {
return undefined
}
-
-window.onload = etc.handle_wrap(init)
diff --git a/files/settings/verify-email/main.js b/files/settings/verify-email/main.js
@@ -1,6 +1,8 @@
import * as api from "/lib/api.js"
import * as etc from "/lib/etc.js"
+etc.handle_wrap(main)
+
function main() {
api.fetch("GET", "users/:user/email/code")
.then(function() {
@@ -111,5 +113,3 @@ function resendForm() {
return form
}
-
-main()