diff --git a/package.json b/package.json index d0c643b..83cbae9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "protest-comms", - "version": "0.2.0", + "version": "0.3.0", "description": "Coordinate slogans, moving, and communicate the needs of your group", "source": "src/index.pug", "author": "Pigeon", diff --git a/src/layouts/settings.pug b/src/layouts/settings.pug index b795af6..ea2a854 100644 --- a/src/layouts/settings.pug +++ b/src/layouts/settings.pug @@ -8,7 +8,7 @@ mixin select(label, options) mixin settings() section#send-signal - form + form(action="POST") h3 Send signal h4 Quick select +select("Urgency", ["Incoming", "When possible", "Urgent", "Life-threatening" ]) diff --git a/src/pocketbase.ts b/src/pocketbase.ts index fdc60f0..4c5cdda 100644 --- a/src/pocketbase.ts +++ b/src/pocketbase.ts @@ -75,8 +75,30 @@ async function loggedIn() { pb.collection("ping").subscribe("*", function(data) { if (data.action == "update") { - $(".current-slogan").removeClass("current-slogan"); - $("#" + data.record.currentslogan).addClass("current-slogan") + const currentSlogan = data.record.currentslogan; + const message = data.record.message; + if (currentSlogan) { + $(".current-slogan").removeClass("current-slogan"); + $("#" + currentSlogan).addClass("current-slogan") + } + if (message) { + let urgency = message.toLowerCase().split(" ")[0].replace(":", "") + switch (urgency) { + case "incoming": + success(message); + break; + case "when": + warning(message); + break; + case "urgent": + error(message); + break; + default: + console.log("Couldn't determine urgency, send as warning") + warning(message) + break; + } + } } }) } catch (err) { diff --git a/src/settings.ts b/src/settings.ts index 716c973..35df9b0 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,5 +1,6 @@ import PocketBase from "pocketbase"; import init from "./pocketbase"; +import { reportError } from "./notify"; let pb: PocketBase; @@ -71,10 +72,21 @@ async function editSlogan(e) { $("#slogans ol").html(oldSlogansListInner) } -function sendSignal(e) { +async function sendSignal(e) { e.preventDefault(); const form = $(e.target); + const ping = (await pb.collection("ping").getList(1, 1)).items[0]; + console.log(ping) + try { + const data = await pb.collection("ping").update(ping.id, { + message: form.children("#signal").val() + }) + console.log(data) + } + catch (err) { + reportError(err); + } }