mirror of
https://github.com/RGBCube/GDUS
synced 2025-07-28 21:47:45 +00:00
Move JS to seperate file
This commit is contained in:
parent
aec4e27bb6
commit
718e4a7713
5 changed files with 68 additions and 37 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,6 +13,7 @@
|
|||
|
||||
!.gitignore
|
||||
|
||||
!*.js
|
||||
!*.md
|
||||
!*.py
|
||||
!*.rs
|
||||
|
|
24
server/Cargo.lock
generated
24
server/Cargo.lock
generated
|
@ -574,6 +574,24 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embed"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/RGBCube/embed-rs#7c41253f4f6006fcc2aad189c19132d2f0cccec2"
|
||||
dependencies = [
|
||||
"embed-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embed-macros"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/RGBCube/embed-rs#7c41253f4f6006fcc2aad189c19132d2f0cccec2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.43",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.33"
|
||||
|
@ -1327,6 +1345,7 @@ dependencies = [
|
|||
"actix-cors",
|
||||
"actix-web",
|
||||
"chrono",
|
||||
"embed",
|
||||
"maud",
|
||||
"serde",
|
||||
"sqlx",
|
||||
|
@ -2353,3 +2372,8 @@ dependencies = [
|
|||
"cc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[patch.unused]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.75"
|
||||
source = "git+https://github.com/RGBCube/proc-macro2#e1713f29a5488360d96178081ac0fca3d4abdb8a"
|
||||
|
|
|
@ -9,12 +9,16 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
actix-cors = "0.6.5"
|
||||
actix-web = "4.4.0"
|
||||
chrono = "0.4.31"
|
||||
maud = { version = "0.25.0", features = [ "actix-web" ] }
|
||||
serde = { version = "1.0.192", features = [ "derive" ] }
|
||||
sqlx = { version = "0.7.3", features = [ "chrono", "sqlite", "runtime-tokio" ] }
|
||||
tokio = { version = "1.34.0", features = [ "full" ] }
|
||||
actix-web = "4.4.0"
|
||||
chrono = "0.4.31"
|
||||
embed = { git = "https://github.com/RGBCube/embed-rs" }
|
||||
maud = { version = "0.25.0", features = [ "actix-web" ] }
|
||||
serde = { version = "1.0.192", features = [ "derive" ] }
|
||||
sqlx = { version = "0.7.3", features = [ "chrono", "sqlite", "runtime-tokio" ] }
|
||||
tokio = { version = "1.34.0", features = [ "full" ] }
|
||||
|
||||
[patch.crates-io]
|
||||
proc-macro2 = { git = "https://github.com/RGBCube/proc-macro2" }
|
||||
|
||||
[profile.dev]
|
||||
incremental = true
|
||||
|
|
30
server/src/alert.js
Normal file
30
server/src/alert.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
const alertIfTime = () => {
|
||||
const reminders = Array.from(
|
||||
document
|
||||
.querySelectorAll("li")
|
||||
)
|
||||
.map(item => {
|
||||
content: item.querySelector("p").textContent,
|
||||
timestamp: +item.getAttribute("data-timestamp"),
|
||||
led: +item.getAttribute("data-led"),
|
||||
});
|
||||
|
||||
const currentTime = Math.floor(Date.now() / 1000);
|
||||
|
||||
reminders.forEach(reminder => {
|
||||
const differenceSeconds = currentTime - reminder.timestamp;
|
||||
|
||||
if (differenceSeconds < 1 * 60) {
|
||||
if (reminder.led != 0) fetch("http://localhost:3000/led/toggle?" + new URLSearchParams({ number: reminder.led }).then(console.log);
|
||||
fetch("http://localhost:3000/speak?" + new URLSearchParams({ text: reminder.content })).then(console.log);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
alertIfTime();
|
||||
|
||||
setInterval(() => {
|
||||
location.reload();
|
||||
alertIfTime();
|
||||
}, 1 * 60 * 1000);
|
||||
|
|
@ -89,36 +89,8 @@ async fn view(data: Data<SqlitePool>) -> web::Result<Markup> {
|
|||
}
|
||||
}
|
||||
|
||||
script defer {(PreEscaped(r##"
|
||||
const alertIfTime = () => {
|
||||
const reminders = Array.from(
|
||||
document
|
||||
.querySelectorAll("li")
|
||||
)
|
||||
.map(item => ({
|
||||
content: item.querySelector("p").textContent,
|
||||
timestamp: +item.getAttribute("data-timestamp"),
|
||||
led: +item.getAttribute("data-led"),
|
||||
}));
|
||||
|
||||
const currentTime = Math.floor(Date.now() / 1000);
|
||||
|
||||
reminders.forEach(reminder => {
|
||||
const differenceSeconds = currentTime - reminder.timestamp;
|
||||
|
||||
if (differenceSeconds < 1 * 60) {
|
||||
if (reminder.led != 0) fetch("http://localhost:3000/led/toggle?" + new URLSearchParams({ number: reminder.led }).then(console.log);
|
||||
fetch("http://localhost:3000/speak?" + new URLSearchParams({ text: reminder.content })).then(console.log);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
alertIfTime();
|
||||
|
||||
setInterval(() => {
|
||||
location.reload();
|
||||
alertIfTime();
|
||||
}, 1 * 60 * 1000);
|
||||
"##))}
|
||||
script {
|
||||
(PreEscaped(embed::string!("alert.js")))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue