Skip to content

Commit

Permalink
Merge pull request #31 from dewetblomerus/admin-bug
Browse files Browse the repository at this point in the history
Admin bug
  • Loading branch information
De Wet Blomerus authored Oct 7, 2023
2 parents 80ff08e + f9695d6 commit 63367e4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 41 deletions.
15 changes: 10 additions & 5 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ window.addEventListener(`phx:set_storage`, (e) => {
}
})

const userFromStorage = {
admin_token: localStorage.getItem('admin_token'),
name: localStorage.getItem('name'),
only_viewing: localStorage.getItem('only_viewing'),
}

Hooks.RestoreUser = {
mounted() {
console.log('Restoring user from localStorage 🥶')
this.pushEvent('restore_user', {
admin_token: localStorage.getItem('admin_token'),
name: localStorage.getItem('name'),
only_viewing: localStorage.getItem('only_viewing'),
this.handleEvent('restore_user', () => {
console.log('Server requested user from localStorage 🥶')
console.log('Sending this user:', userFromStorage)
this.pushEvent('restore_user', userFromStorage)
})
},
}
Expand Down
11 changes: 7 additions & 4 deletions lib/quick_average_web/live/average_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule QuickAverageWeb.AverageLive do
def mount(%{"room_id" => room_id}, _session, socket) do
ManagerSupervisor.create(room_id)
PubSubInterface.subscribe_display(room_id)
send(self(), :ask_frontend_to_restore_user)

new_socket =
assign(socket, %{
Expand All @@ -36,10 +37,7 @@ defmodule QuickAverageWeb.AverageLive do

PresenceInterface.track(new_socket)

{
:ok,
new_socket
}
{:ok, new_socket}
end

@impl true
Expand Down Expand Up @@ -165,6 +163,11 @@ defmodule QuickAverageWeb.AverageLive do
{:noreply, socket}
end

@impl true
def handle_info(:ask_frontend_to_restore_user, socket) do
{:noreply, push_event(socket, "restore_user", %{})}
end

@impl true
def handle_info(%DisplayState{users: users, average: average}, socket) do
is_admin = socket.assigns.is_admin || is_alone?(users)
Expand Down
2 changes: 1 addition & 1 deletion lib/quick_average_web/live/average_live.html.heex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="hooker" phx-hook="RestoreUser"></div>
<div id="hook-1" phx-hook="RestoreUser"></div>
<div class="border-2 border-gray-400 rounded-xl mt-2">
<div class="pl-4 pt-4 pr-4">
<.simple_form
Expand Down
8 changes: 4 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ defmodule QuickAverage.MixProject do
{:esbuild, "~> 0.6", runtime: Mix.env() == :dev},
{:floki, ">= 0.34.0", only: :test},
{:gettext, "~> 0.22"},
{:heroicons, "~> 0.5"},
{:heroicons, "> 0.5.2"},
{:jason, "~> 1.2"},
{:mimic, "~> 1.7", only: :test},
{:mix_test_watch, "~> 1.1", only: :dev, runtime: false},
{:phoenix_ecto, "~> 4.4.2"},
{:phoenix_html, "~> 3.3"},
{:phoenix_live_dashboard, "~> 0.7.2"},
{:phoenix_live_dashboard, "> 0.8.0"},
{:phoenix_live_reload, "~> 1.4", only: :dev},
{:phoenix_live_view, "~> 0.18.17"},
{:phoenix, "~> 1.7.1", override: true},
{:phoenix_live_view, "~> 0.20.0"},
{:phoenix, "~> 1.7.7", override: true},
{:plug_cowboy, "~> 2.6"},
{:sobelow, "~> 0.12", only: [:dev, :test], runtime: false},
{:tailwind, "~> 0.1.10", runtime: Mix.env() == :dev},
Expand Down
Loading

0 comments on commit 63367e4

Please sign in to comment.