Skip to content

Commit

Permalink
feat: upgrade to htmx 1.9.12
Browse files Browse the repository at this point in the history
  • Loading branch information
jdevries3133 committed Jun 3, 2024
1 parent bd47217 commit 460efcc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ build: setup
cargo build --release

setup:
[[ ! -f ./src/htmx-1.9.10.vendor.js ]] \
&& curl -L https://unpkg.com/htmx.org@1.9.10 > src/htmx-1.9.10.vendor.js \
[[ ! -f ./src/htmx-1.9.12.vendor.js ]] \
&& curl -L https://unpkg.com/htmx.org@1.9.12 > src/htmx-1.9.12.vendor.js \
|| true
ifdef CI
npm i -g pnpm
Expand Down
2 changes: 1 addition & 1 deletion src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const LIVE_RELOAD_SCRIPT: &str = r#"<script>
// At some point, a compiler error may be preventing
// the server from coming back
el.innerText = "Reload taking longer than usual; check for a compiler error";
}, 2000);
}, 5000);
// Now the server is down, we'll fast-poll it (trying to
// get an immediate response), and reload the page when it
// comes back
Expand Down
1 change: 1 addition & 0 deletions src/htmx-1.9.12.vendor.js

Large diffs are not rendered by default.

21 changes: 7 additions & 14 deletions src/htmx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ mod test {
}
}

pub fn get_client_script() -> String {
let post_htmx = r#"
pub const fn get_client_script() -> &'static str {
concat!(
include_str!("./htmx-1.9.12.vendor.js"),
r#"
function makeId(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
Expand All @@ -92,31 +94,22 @@ pub fn get_client_script() -> String {
const el = document.createElement('p');
const id = makeId(20);
el.id = id;
el.innerText = "An error occurred. The app developer has been notified, and will look into the issue ASAP. Sorry for the inconvenience! (click to dismiss)";
el.innerText = "An error occurred; sorry for the inconvenience! (click to dismiss)";
el.classList.add("bg-red-100");
el.classList.add("p-2");
el.classList.add("rounded");
el.classList.add("w-full");
el.classList.add("sticky");
el.classList.add("top-0");
el.classList.add("dark:text-black");
el.classList.add("cursor-pointer");
document.body.insertBefore(el, document.body.firstChild);
el.addEventListener('click', () => {
document.getElementById(id).remove();
});
});
htmx.config.defaultSwapStyle = "outerHTML";
"#;

let htmx_vendor = include_str!("./htmx-1.9.10.vendor.js");

format!(
r#"if (!window?.htmx) {{
{htmx_vendor}
{post_htmx}
}} else {{
console.log("Skipping HTMX re-init");
}}"#
"#
)
}
2 changes: 1 addition & 1 deletion src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Route {
Self::Favicon => "/favicon.ico".into(),
Self::GotoStripePortal => "/stripe-portal".into(),
Self::HandleChat => "/chat".into(),
Self::Htmx => "/generated/htmx-1.9.10".into(),
Self::Htmx => "/generated/htmx-1.9.12".into(),
Self::InitAnon => "/authentication/init-anon".into(),
Self::ListMeals => "/list-meals".into(),
Self::Login => "/authentication/login".into(),
Expand Down

0 comments on commit 460efcc

Please sign in to comment.