From a9e71a85e827a32375b731709cb1c1a93c947187 Mon Sep 17 00:00:00 2001
From: vishalkrishnads <321vishalds@gmail.com>
Date: Wed, 19 Jun 2024 13:13:15 +0530
Subject: [PATCH 1/3] implemented tweetRoute()
---
src/components/DriveView/Media.jsx | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/components/DriveView/Media.jsx b/src/components/DriveView/Media.jsx
index 10f5547d6..2231e08e6 100644
--- a/src/components/DriveView/Media.jsx
+++ b/src/components/DriveView/Media.jsx
@@ -239,6 +239,7 @@ class Media extends Component {
this.copySegmentName = this.copySegmentName.bind(this);
this.openInUseradmin = this.openInUseradmin.bind(this);
this.shareCurrentRoute = this.shareCurrentRoute.bind(this);
+ this.tweetRoute = this.tweetRoute.bind(this);
this.uploadFile = this.uploadFile.bind(this);
this.uploadFilesAll = this.uploadFilesAll.bind(this);
this.getUploadStats = this.getUploadStats.bind(this);
@@ -332,6 +333,23 @@ class Media extends Component {
}
}
+ tweetRoute() {
+ const { currentRoute } = this.props;
+
+ let percentage = 0, engagements = 0;
+ currentRoute.events
+ .filter((event) => event.data && event.data.end_route_offset_millis)
+ .forEach(event => {
+ if(event.type === 'engage') {
+ percentage += parseInt(((event.data.end_route_offset_millis - event.route_offset_millis) / currentRoute.duration) * 100);
+ engagements++;
+ }
+ })
+
+ const post = `I went on a pretty chill drive ${currentRoute.startLocation?.place ? `from ${currentRoute.startLocation.place}` : ''}${currentRoute.endLocation?.place ? ` to ${currentRoute.endLocation.place}` : ''} in my ${currentRoute.platform.replace("_", ' ').toLowerCase()} as openpilot drove ~${percentage}% of the route with less than ${engagements+1} disengagements!\nCheck out the full drive on comma connect at ${window.location.href}.`;
+ window.open(`https://twitter.com/intent/tweet?text=${encodeURIComponent(post)}`, '_blank').focus();
+ }
+
async uploadFile(type) {
const { dongleId, currentRoute } = this.props;
if (!currentRoute) {
@@ -741,6 +759,10 @@ class Media extends Component {
)}
+