22
33namespace App \Http \Livewire \ResearchSpace ;
44
5+ use Livewire \Attributes \On ;
56use Livewire \Component ;
67use App \Models \ResearchSpace ;
78use App \Events \ResearchSpaceUpdated ;
@@ -12,16 +13,14 @@ class CollaboratorBoard extends Component
1213 use AuthorizesRequests;
1314
1415 public ResearchSpace $ space ;
16+ public int $ spaceId = 0 ;
1517 public $ content = '' ;
1618 public $ userPermissions = [];
1719
18- protected $ listeners = [
19- 'echo:research-space.{spaceId},ResearchSpaceUpdated ' => 'onExternalUpdate ' ,
20- ];
21-
2220 public function mount ($ spaceId )
2321 {
2422 $ this ->space = ResearchSpace::with ('collaborators.user ' )->findOrFail ($ spaceId );
23+ $ this ->spaceId = $ this ->space ->id ;
2524
2625 $ this ->authorize ('view ' , $ this ->space );
2726
@@ -30,12 +29,10 @@ public function mount($spaceId)
3029 $ this ->userPermissions = []; // can be populated from collaborators
3130 }
3231
33- public function saveContent (string $ updated )
32+ public function saveContent ()
3433 {
3534 $ this ->authorize ('update ' , $ this ->space );
3635
37- $ this ->content = $ updated ;
38-
3936 $ settings = $ this ->space ->settings ?? [];
4037 $ settings ['board ' ] = array_merge ($ settings ['board ' ] ?? [], ['content ' => $ this ->content , 'updated_at ' => now ()->toDateTimeString ()]);
4138 $ this ->space ->settings = $ settings ;
@@ -45,11 +42,12 @@ public function saveContent(string $updated)
4542 event (new ResearchSpaceUpdated ($ this ->space ->id , ['content ' => $ this ->content , 'user_id ' => auth ()->id ()]));
4643 }
4744
45+ #[On('echo:research-space.{spaceId},ResearchSpaceUpdated ' )]
4846 public function onExternalUpdate ($ payload )
4947 {
5048 // When we get an external broadcast, update local content
5149 $ this ->content = data_get ($ payload , 'content ' , $ this ->content );
52- $ this ->emitSelf ('contentUpdated ' );
50+ $ this ->dispatch ('contentUpdated ' );
5351 }
5452
5553 public function render ()
0 commit comments