Browse Source

hook up the twitter reply box!

master
Aaron Parecki 7 years ago
parent
commit
5f503397a5
No known key found for this signature in database GPG Key ID: 276C2817346D6056
11 changed files with 1470 additions and 32 deletions
  1. +5
    -5
      app/Events/NewTweetEvent.php
  2. +18
    -0
      app/Http/Controllers/DashboardController.php
  3. +3
    -1
      app/Http/Controllers/TwitterController.php
  4. +2
    -1
      package.json
  5. +19
    -4
      public/css/app.css
  6. +1373
    -8
      public/js/app.js
  7. BIN
      public/twitter.ico
  8. +2
    -0
      resources/assets/js/bootstrap.js
  9. +33
    -8
      resources/assets/js/components/Scorecard.vue
  10. +14
    -5
      resources/assets/sass/app.scss
  11. +1
    -0
      routes/web.php

+ 5
- 5
app/Events/NewTweetEvent.php View File

@ -36,13 +36,13 @@ class NewTweetEvent implements ShouldBroadcast
{ {
$this->tweet_id = $tweet->id; $this->tweet_id = $tweet->id;
$this->tweet_date = strtotime($tweet->tweet_date); $this->tweet_date = strtotime($tweet->tweet_date);
$this->team_name = $tweet->team->name;
$this->team_color = $tweet->team->color;
$this->player_username = $tweet->player->twitter;
$this->player_photo = $tweet->player->photo;
$this->team_name = ($tweet->team ? $tweet->team->name : null);
$this->team_color = ($tweet->team ? $tweet->team->color : null);
$this->player_username = ($tweet->player ? $tweet->player->twitter : null);
$this->player_photo = ($tweet->player ? $tweet->player->photo : null);
$this->text = $tweet->text; $this->text = $tweet->text;
$this->photos = json_decode($tweet->photo); $this->photos = json_decode($tweet->photo);
$this->mission = $tweet->mission->hashtag;
$this->mission = ($tweet->mission ? $tweet->mission->hashtag : null);
$this->mission_id = $tweet->mission_id; $this->mission_id = $tweet->mission_id;
} }

+ 18
- 0
app/Http/Controllers/DashboardController.php View File

@ -117,4 +117,22 @@ class DashboardController extends Controller
'transit_lines' => $transit_lines 'transit_lines' => $transit_lines
]); ]);
} }
public function reply_to_tweet(Request $request) {
$tweet = Tweet::where('id', $request->input('tweet_id'))->first();
if($tweet) {
$params = [
'auto_populate_reply_metadata' => true,
'in_reply_to_status_id' => $tweet->tweet_id,
'status' => $request->input('text')
];
$response = Twitter::postTweet($params);
if($response && $response->id_str) {
return response()->json(['result'=>'ok']);
}
}
return response()->json(['result'=>'error']);
}
} }

+ 3
- 1
app/Http/Controllers/TwitterController.php View File

@ -59,7 +59,9 @@ class TwitterController extends BaseController
$tweet->tweet_date = date('Y-m-d H:i:s', strtotime($data['created_at'])); $tweet->tweet_date = date('Y-m-d H:i:s', strtotime($data['created_at']));
$tweet->save(); $tweet->save();
event(new NewTweetEvent($tweet));
if($tweet->mission_id) {
event(new NewTweetEvent($tweet));
}
return $data['id_str']; return $data['id_str'];
} }

+ 2
- 1
package.json View File

@ -21,6 +21,7 @@
"dependencies": { "dependencies": {
"featherlight": "^1.7.6", "featherlight": "^1.7.6",
"laravel-echo": "^1.3.0", "laravel-echo": "^1.3.0",
"pusher-js": "^4.1.0"
"pusher-js": "^4.1.0",
"twitter-text": "^1.14.7"
} }
} }

+ 19
- 4
public/css/app.css View File

@ -8629,12 +8629,27 @@ button.close {
background-color: #f5f8fa; background-color: #f5f8fa;
} }
.scorecard .tweet-reply button {
float: right;
.scorecard .tweet-reply .bottom {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
} }
.scorecard .tweet-reply .clear {
clear: both;
.scorecard .tweet-reply .bottom .fill {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
}
.scorecard .tweet-reply .bottom img {
margin-right: 4px;
}
.scorecard .tweet-reply .bottom .remaining-chars {
margin-right: 10px;
} }
.scorecard .tweet-actions { .scorecard .tweet-actions {

+ 1373
- 8
public/js/app.js
File diff suppressed because it is too large
View File


BIN
public/twitter.ico View File

Before After

+ 2
- 0
resources/assets/js/bootstrap.js View File

@ -56,3 +56,5 @@ window.Echo = new Echo({
cluster: 'us2', cluster: 'us2',
encrypted: true encrypted: true
}); });
window.twitter = require('twitter-text')

+ 33
- 8
resources/assets/js/components/Scorecard.vue View File

@ -31,10 +31,16 @@
</div> </div>
</div> </div>
<div class="tweet-reply">
<textarea class="form-control" rows="2" v-model="replyText" style="margin-bottom: 4px;"></textarea>
<button type="submit" class="btn btn-primary" :disabled="isTweetReplyDisabled">Reply</button>
<div class="clear"></div>
<div class="tweet-reply" v-if="showReplyBox">
<div class="top">
<textarea class="form-control" rows="2" v-model="replyText" style="margin-bottom: 4px;" :disabled="replyInProgress"></textarea>
</div>
<div class="bottom">
<div class="fill"></div>
<img src="/twitter.ico" width="16">
<div class="remaining-chars">{{ replyTextCharsRemaining }}</div>
<button class="btn btn-primary" :disabled="isTweetReplyDisabled" v-on:click="sendReply">Reply</button>
</div>
</div> </div>
<div class="tweet-actions"> <div class="tweet-actions">
@ -151,9 +157,6 @@
</div> </div>
</template> </template>
</div> </div>
</div> </div>
@ -169,6 +172,9 @@ module.exports = {
centers: [], centers: [],
lines: [], lines: [],
replyText: '', replyText: '',
replyTextCharsRemaining: 140,
replyInProgress: false,
showReplyBox: true,
selectedDocument: null, selectedDocument: null,
selectedTransitCenter: null, selectedTransitCenter: null,
selectedTransitLine: null, selectedTransitLine: null,
@ -203,7 +209,7 @@ module.exports = {
} }
}, },
isTweetReplyDisabled() { isTweetReplyDisabled() {
return this.replyText == '';
return this.replyText == '' || this.replyInProgress || this.replyTextCharsRemaining < 0;
} }
}, },
methods: { methods: {
@ -216,6 +222,7 @@ module.exports = {
this.selectedM5Singing = false; this.selectedM5Singing = false;
this.selectedM5Tipping = false; this.selectedM5Tipping = false;
this.replyText = ''; this.replyText = '';
this.showReplyBox = true;
}, },
dismiss() { dismiss() {
this.clearState(); this.clearState();
@ -268,6 +275,21 @@ module.exports = {
this.clearState(); this.clearState();
this.$emit('complete'); this.$emit('complete');
}.bind(this)); }.bind(this));
},
sendReply() {
this.replyInProgress = true;
$.post("/dashboard/reply", {
tweet_id: this.tweet.tweet_id,
text: this.replyText
}, function(response){
if(response.result == "ok") {
this.replyText = '';
}
this.replyInProgress = false;
}.bind(this));
// setTimeout(function(){ this.replyInProgress = false; this.showReplyBox = false; }.bind(this), 1000);
} }
}, },
watch: { watch: {
@ -279,6 +301,9 @@ module.exports = {
$(".multi-photo .photo").featherlight(); $(".multi-photo .photo").featherlight();
}.bind(this)); }.bind(this));
} }
},
replyText: function(val) {
this.replyTextCharsRemaining = 140 - twitter.getTweetLength(val);
} }
}, },
created() { created() {

+ 14
- 5
resources/assets/sass/app.scss View File

@ -147,12 +147,21 @@
padding: 8px; padding: 8px;
background-color: $body-bg; background-color: $body-bg;
button {
float: right;
}
.bottom {
display: flex;
align-items: center;
.fill {
flex: 1;
}
img {
margin-right: 4px;
}
.clear {
clear: both;
.remaining-chars {
margin-right: 10px;
}
} }
} }

+ 1
- 0
routes/web.php View File

@ -24,6 +24,7 @@ Route::get('/dashboard/dropdowns', 'DashboardController@load_dropdowns');
Route::post('/dashboard/claim-tweet', 'DashboardController@claim_tweet'); Route::post('/dashboard/claim-tweet', 'DashboardController@claim_tweet');
Route::post('/dashboard/reject-tweet', 'DashboardController@reject_tweet'); Route::post('/dashboard/reject-tweet', 'DashboardController@reject_tweet');
Route::post('/dashboard/score-tweet', 'DashboardController@score_tweet'); Route::post('/dashboard/score-tweet', 'DashboardController@score_tweet');
Route::post('/dashboard/reply', 'DashboardController@reply_to_tweet');
Route::get('/slideshow', 'SlideshowController@slideshow')->name('slideshow'); Route::get('/slideshow', 'SlideshowController@slideshow')->name('slideshow');

Loading…
Cancel
Save