Packages

Real-time admin dashboard for Phoenix

Current section

Files

Jump to
phoenix_live_admin priv static js app.js
Raw

priv/static/js/app.js

import css from "../css/app.scss"
import "phoenix_html"
import { Socket } from "phoenix"
import NProgress from "nprogress"
import { LiveSocket } from "phoenix_live_view"
let Hooks = {}
let socketPath = document.querySelector("html").getAttribute("phx-socket") || "/live"
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket(socketPath, Socket, {
hooks: Hooks,
params: { _csrf_token: csrfToken }
})
// Show progress bar on live nagiation and form submits
window.addEventListener("phx:page-loading-start", info => NProgress.start())
window.addeventListener("phx:page-loading-stop", info => NProgress.done())
// connect if there are any LiveViews on the page
liveSocket.connect()
// expose liveSocket on window for web console debug logs
// >> liveSocket.enableDebug()
window.liveSocket = liveSocket