Skip to content

Commit

Permalink
fixup: add LiveView support (#1772)
Browse files Browse the repository at this point in the history
* feat(SiteWeb.Endpoint): add live view config

* feat(SiteWeb.Endpoint): add LiveView socket

* feat(SiteWeb.Endpoint): add .heex to live reload

* feat(app.html.eex): Add CSRF token meta tag

* deps(npm): add phoenix_live_view

* feat: connect Phoenix LiveSocket in frontend
  • Loading branch information
thecristen authored Oct 19, 2023
1 parent 742321b commit b7f89b3
Show file tree
Hide file tree
Showing 9 changed files with 13,238 additions and 13,198 deletions.
22 changes: 22 additions & 0 deletions apps/site/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ import tabbedNav from "./tabbed-nav.js";
import { accordionInit } from "../ts/ui/accordion";
import initializeSentry from "../ts/sentry";

// Establish Phoenix Socket and LiveView configuration.
import { Socket } from "phoenix";
import { LiveSocket } from "phoenix_live_view";

let csrfToken = document
.querySelector("meta[name='csrf-token']")
.getAttribute("content");
let Hooks = {};
let liveSocket = new LiveSocket("/live", Socket, {
params: { _csrf_token: csrfToken },
hooks: Hooks
});

// connect if there are any LiveViews on the page
liveSocket.connect();

// expose liveSocket on window for web console debug logs and latency simulation:
// >> liveSocket.enableDebug()
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
// >> liveSocket.disableLatencySim()
window.liveSocket = liveSocket;

initializeSentry();

document.body.className = document.body.className.replace("no-js", "js");
Expand Down
Loading

0 comments on commit b7f89b3

Please sign in to comment.