From a9a56db22ad8e1349b9601ad1b3442aca5881fca Mon Sep 17 00:00:00 2001 From: Benjamin Eckel Date: Thu, 2 Mar 2023 13:58:37 -0600 Subject: [PATCH] feat: wrap game in a shadow dom --- assets/js/app.js | 29 +++++++++++++++++++++++++++-- games/trivia/src/game.ts | 11 ++++++++++- lib/game_box_web/live/arena_live.ex | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index dcc5175..5a1343d 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -26,9 +26,34 @@ import {Socket} from "phoenix" import {LiveSocket} from "phoenix_live_view" import topbar from "../vendor/topbar" import {s3Uploader} from "./uploader" +import {LitElement} from "lit" +import {unsafeHTML} from 'lit/directives/unsafe-html.js' + +let Hooks = {} + +Hooks.GameboxGame = { + mounted() { + debugger + } +} + +class GameboxGame extends LitElement { + static properties = { + view: { + type: String + } + } + + render() { + return unsafeHTML(this.view) + } +} + +customElements.define('gamebox-game', GameboxGame) + let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") -let liveSocket = new LiveSocket("/live", Socket, {uploaders: {S3: s3Uploader}, params: {_csrf_token: csrfToken}}) +let liveSocket = new LiveSocket("/live", Socket, {hooks: Hooks, uploaders: {S3: s3Uploader}, params: {_csrf_token: csrfToken}}) // Show progress bar on live navigation and form submits topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"}) @@ -55,7 +80,7 @@ window.addEventListener("gamebox:clipcopy", (event) => { liveSocket.connect() // expose liveSocket on window for web console debug logs and latency simulation: -// >> liveSocket.enableDebug() +liveSocket.enableDebug() // >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session // >> liveSocket.disableLatencySim() window.liveSocket = liveSocket diff --git a/games/trivia/src/game.ts b/games/trivia/src/game.ts index 54a4a41..e65d389 100644 --- a/games/trivia/src/game.ts +++ b/games/trivia/src/game.ts @@ -25,6 +25,15 @@ export interface LiveEvent { const questions = getQuestions() +const style = ` + +` + export class Game { players: Array; version: number; @@ -67,7 +76,7 @@ export class Game { return `
  • ` }).join("\n") - return [question, ``].join("\n") + return [style, question, ``].join("\n") } renderScoreboard(_assigns: Assigns): string { diff --git a/lib/game_box_web/live/arena_live.ex b/lib/game_box_web/live/arena_live.ex index a28462a..165dab7 100644 --- a/lib/game_box_web/live/arena_live.ex +++ b/lib/game_box_web/live/arena_live.ex @@ -243,7 +243,7 @@ defmodule GameBoxWeb.ArenaLive do /> <% end %>
    - <%= Phoenix.HTML.raw(board) %> +
    <% end %> """