Skip to content

Commit

Permalink
Reverted some frontend changes. Don't think they're needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaddox5 committed Sep 29, 2023
1 parent 271131a commit fbe9fa8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 32 deletions.
3 changes: 0 additions & 3 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"moment-timezone": "^0.5.33",
"phoenix": "file:../deps/phoenix",
"phoenix_html": "file:../deps/phoenix_html",
"phoenix_live_view": "file:../deps/phoenix_live_view",
"qrcode.react": "^1.0.1",
"raven-js": "^3.27.2",
"react": "^17.0.2",
Expand Down
3 changes: 1 addition & 2 deletions assets/src/apps/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import {
BusShelterV2ScreensTable,
PreFareV2ScreensTable,
DupV2ScreensTable,
TriptychV2ScreensTable,
TriptychV2ScreensTable
} from "Components/admin/admin_tables";
import ImageManager from "Components/admin/admin_image_manager";
import Devops from "Components/admin/devops";
// import "../../src/socket";

const App = (): JSX.Element => {
return (
Expand Down
86 changes: 60 additions & 26 deletions assets/src/socket.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,68 @@
// If you want to use Phoenix channels, run `mix help phx.gen.channel`
// to get started and then uncomment the line below.
// import "./user_socket.js"
// NOTE: The contents of this file will only be executed if
// you uncomment its entry in "assets/js/app.js".

// You can include dependencies in two ways.
// To use Phoenix channels, the first step is to import Socket,
// and connect at the socket path in "lib/web/endpoint.ex".
//
// The simplest option is to put them in assets/vendor and
// import them using relative paths:
// Pass the token on params as below. Or remove it
// from the params if you are not using authentication.
import { Socket } from "phoenix";

let socket = new Socket("/socket", { params: { token: window.userToken } });

// When you connect, you'll often need to authenticate the client.
// For example, imagine you have an authentication plug, `MyAuth`,
// which authenticates the session and assigns a `:current_user`.
// If the current user exists you can assign the user's token in
// the connection for use in the layout.
//
// import "../vendor/some-package.js"
// In your "lib/web/router.ex":
//
// Alternatively, you can `npm install some-package --prefix assets` and import
// them using a path starting with the package name:
// pipeline :browser do
// ...
// plug MyAuth
// plug :put_user_token
// end
//
// import "some-package"
// defp put_user_token(conn, _) do
// if current_user = conn.assigns[:current_user] do
// token = Phoenix.Token.sign(conn, "user socket", current_user.id)
// assign(conn, :user_token, token)
// else
// conn
// end
// end
//
// Now you need to pass this token to JavaScript. You can do so
// inside a script tag in "lib/web/templates/layout/app.html.eex":
//
// <script>window.userToken = "<%= assigns[:user_token] %>";</script>
//
// You will need to verify the user token in the "connect/3" function
// in "lib/web/channels/user_socket.ex":
//
// def connect(%{"token" => token}, socket, _connect_info) do
// # max_age: 1209600 is equivalent to two weeks in seconds
// case Phoenix.Token.verify(socket, "user socket", token, max_age: 1209600) do
// {:ok, user_id} ->
// {:ok, assign(socket, :user, user_id)}
// {:error, reason} ->
// :error
// end
// end
//
// Finally, connect to the socket:
socket.connect();

// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
import "phoenix_html"
// 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 liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})

// connect if there are any LiveViews on the page
liveSocket.connect()
// Now that you are connected, you can join channels with a topic:
let channel = socket.channel("topic:subtopic", {});
channel
.join()
.receive("ok", (resp) => {
console.log("Joined successfully", resp);
})
.receive("error", (resp) => {
console.log("Unable to join", resp);
});

// 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
export default socket;

0 comments on commit fbe9fa8

Please sign in to comment.