File tree Expand file tree Collapse file tree 5 files changed +17
-11
lines changed
Expand file tree Collapse file tree 5 files changed +17
-11
lines changed Original file line number Diff line number Diff line change 77use App \Entity \Tweet ;
88use App \Repository \TweetRepository ;
99use Illuminate \Support \Facades \Auth ;
10- use App \Events \AddTweetEvent ;
10+ use App \Events \TweetAddedEvent ;
1111
1212final class AddTweetAction
1313{
@@ -25,8 +25,8 @@ public function execute(AddTweetRequest $request): AddTweetResponse
2525 $ tweet ->text = $ request ->getText ();
2626
2727 $ tweet = $ this ->tweetRepository ->save ($ tweet );
28-
29- broadcast (new AddTweetEvent ($ tweet ))->toOthers ();
28+
29+ broadcast (new TweetAddedEvent ($ tweet ))->toOthers ();
3030
3131 return new AddTweetResponse ($ tweet );
3232 }
Original file line number Diff line number Diff line change 1010use Illuminate \Broadcasting \InteractsWithSockets ;
1111use Illuminate \Contracts \Broadcasting \ShouldBroadcast ;
1212use App \Entity \Tweet ;
13+ use App \Http \Presenter \Tweet \TweetArrayPresenter ;
14+ use Illuminate \Support \Facades \App ;
1315
14- class AddTweetEvent implements ShouldBroadcast
16+ class TweetAddedEvent implements ShouldBroadcast
1517{
1618 use Dispatchable, InteractsWithSockets, SerializesModels;
1719
1820 public $ tweet ;
1921
2022 public function __construct (Tweet $ tweet )
2123 {
22- $ this ->tweet = $ tweet ;
24+ $ this ->tweet = App:: make (TweetArrayPresenter::class)-> present ( $ tweet) ;
2325 }
2426
2527 public function broadcastAs (): string
Original file line number Diff line number Diff line change @@ -35,9 +35,7 @@ class Api {
3535 const { response } = errorResponse ;
3636
3737 if ( ! response ) {
38- return Promise . reject ( {
39- message : 'Unexpected error!'
40- } ) ;
38+ return Promise . reject ( new Error ( 'Unexpected error!' ) ) ;
4139 }
4240
4341 const error = response . data . errors [ 0 ] ;
Original file line number Diff line number Diff line change @@ -31,10 +31,13 @@ import NoContent from '../../common/NoContent.vue';
3131import NewTweetForm from ' ./NewTweetForm.vue' ;
3232import { pusher } from ' @/services/Pusher' ;
3333import { SET_TWEET } from ' @/store/modules/tweet/mutationTypes' ;
34+ import showStatusToast from ' @/components/mixin/showStatusToast' ;
3435
3536export default {
3637 name: ' FeedContainer' ,
3738
39+ mixins: [showStatusToast],
40+
3841 components: {
3942 TweetPreviewList,
4043 NewTweetForm,
@@ -45,8 +48,12 @@ export default {
4548 isNewTweetModalActive: false ,
4649 }),
4750
48- created () {
49- this .fetchTweets ();
51+ async created () {
52+ try {
53+ await this .fetchTweets ();
54+ } catch (error) {
55+ this .showErrorMessage (error .message )
56+ }
5057
5158 const channel = pusher .subscribe (' private-tweets' );
5259
Original file line number Diff line number Diff line change @@ -22,7 +22,6 @@ export default {
2222 tweets: [],
2323 }),
2424
25-
2625 async created () {
2726 try {
2827 this .tweets = await this .fetchTweetsByUserId (this .$route .params .id );
You can’t perform that action at this time.
0 commit comments