Skip to content

Commit 8bd1ea0

Browse files
committed
Rename tweet added action, add error handler to feed container
1 parent e18fcf1 commit 8bd1ea0

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

backend/app/Action/Tweet/AddTweetAction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use App\Entity\Tweet;
88
use App\Repository\TweetRepository;
99
use Illuminate\Support\Facades\Auth;
10-
use App\Events\AddTweetEvent;
10+
use App\Events\TweetAddedEvent;
1111

1212
final 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
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
use Illuminate\Broadcasting\InteractsWithSockets;
1111
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
1212
use 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

frontend/src/api/Api.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff 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];

frontend/src/components/view/feed/FeedContainer.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ import NoContent from '../../common/NoContent.vue';
3131
import NewTweetForm from './NewTweetForm.vue';
3232
import { pusher } from '@/services/Pusher';
3333
import { SET_TWEET } from '@/store/modules/tweet/mutationTypes';
34+
import showStatusToast from '@/components/mixin/showStatusToast';
3435
3536
export 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

frontend/src/components/view/user/UserContainer.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)