Skip to content

Commit

Permalink
0.3.0: Implemented sending & receiving signals
Browse files Browse the repository at this point in the history
  • Loading branch information
Antifantwerp-Pigeon committed Sep 5, 2024
1 parent cc8b498 commit 20a59cd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/settings.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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" ])
Expand Down
26 changes: 24 additions & 2 deletions src/pocketbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PocketBase from "pocketbase";
import init from "./pocketbase";
import { reportError } from "./notify";

let pb: PocketBase;

Expand Down Expand Up @@ -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);
}

}

Expand Down

0 comments on commit 20a59cd

Please sign in to comment.