]> git.localhorst.tv Git - alttp.git/commitdiff
add command to reload clients
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 11 Mar 2022 08:53:15 +0000 (09:53 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 11 Mar 2022 08:53:15 +0000 (09:53 +0100)
app/Console/Commands/PleaseRefresh.php [new file with mode: 0644]
app/Events/PleaseRefresh.php [new file with mode: 0644]
resources/js/components/App.js
resources/js/i18n/de.js
routes/channels.php

diff --git a/app/Console/Commands/PleaseRefresh.php b/app/Console/Commands/PleaseRefresh.php
new file mode 100644 (file)
index 0000000..7ebea1c
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class PleaseRefresh extends Command
+{
+       /**
+        * The name and signature of the console command.
+        *
+        * @var string
+        */
+       protected $signature = 'app:refresh';
+
+       /**
+        * The console command description.
+        *
+        * @var string
+        */
+       protected $description = 'Ask clients to reload';
+
+       /**
+        * Execute the console command.
+        *
+        * @return int
+        */
+       public function handle()
+       {
+               \App\Events\PleaseRefresh::dispatch();
+               return 0;
+       }
+}
diff --git a/app/Events/PleaseRefresh.php b/app/Events/PleaseRefresh.php
new file mode 100644 (file)
index 0000000..ea21738
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace App\Events;
+
+use Illuminate\Broadcasting\Channel;
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Broadcasting\PresenceChannel;
+use Illuminate\Broadcasting\PrivateChannel;
+use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Queue\SerializesModels;
+
+class PleaseRefresh implements ShouldBroadcast
+{
+       use Dispatchable, InteractsWithSockets, SerializesModels;
+
+       /**
+        * Create a new event instance.
+        *
+        * @return void
+        */
+       public function __construct()
+       {
+               //
+       }
+
+       /**
+        * Get the channels the event should broadcast on.
+        *
+        * @return \Illuminate\Broadcasting\Channel|array
+        */
+       public function broadcastOn()
+       {
+               return new Channel('App.Control');
+       }
+
+}
index b5bd9c9fdfd8388d500d97f5ae8e10b9e594719b..f63298978de960aa1602ba08c99772e4989c9b0f 100644 (file)
@@ -37,6 +37,16 @@ const App = () => {
                };
        }, []);
 
+       useEffect(() => {
+               window.Echo.channel('App.Control')
+                       .listen('PleaseRefresh', () => {
+                               location.reload();
+                       });
+               return () => {
+                       window.Echo.leave('App.Control');
+               };
+       }, []);
+
        return <BrowserRouter>
                <UserContext.Provider value={user}>
                        <Header doLogout={doLogout} />
index e31b96c780800c8f34eb5c1c1139de0dcd6de73c..033059b40f7ef0f10907461526d2e8756e137d52 100644 (file)
@@ -21,6 +21,7 @@ export default {
                },
                rounds: {
                        date: '{{ date, L }}',
+                       empty: 'Noch keine Runde gestartet',
                        heading: 'Runden',
                        new: 'Neue Runde',
                },
index 5d451e1fae88c81c097aa55de6ff039a3cc0a1c3..4302bb7d72871176f7d244756cdc14ca64197566 100644 (file)
@@ -14,5 +14,9 @@ use Illuminate\Support\Facades\Broadcast;
 */
 
 Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
-    return (int) $user->id === (int) $id;
+       return (int) $user->id === (int) $id;
+});
+
+Broadcast::channel('App.Control', function ($user) {
+       return true;
 });