Skip to content

Commit b48bdde

Browse files
committed
like button functionality & UI for block and report
1 parent 7dd537a commit b48bdde

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

frontend/src/components/app/users/LikeButton.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,25 @@
88
<img v-bind:src="getImage" class="h-8">
99
<h1 class="text-white-matcha text-2xl ml-2 font-bold">{{getText}}</h1>
1010
</div>
11-
<h1 v-if="description" class="text-purple-matcha text-sm mt-2">{{description}}</h1>
11+
<h1 v-if="description && !hasBeenClicked" class="text-purple-matcha text-sm mt-2"><span v-if="counter" class="font-bold">{{counter}}. </span>{{description}}</h1>
1212
</div>
1313
</template>
1414

1515
<script>
1616
/* eslint-disable max-len */
1717
1818
export default {
19-
props: ['name', 'startImage', 'hoverImage', 'clickedImage', 'text', 'textRevert', 'description'],
19+
props: [
20+
'name',
21+
'startImage',
22+
'hoverImage',
23+
'clickedImage',
24+
'text',
25+
'textRevert',
26+
'counter',
27+
'description',
28+
'hasBeenClicked',
29+
],
2030
data: () => ({
2131
hover: false,
2232
clicked: false,
@@ -48,5 +58,10 @@ export default {
4858
return this.text;
4959
},
5060
},
61+
beforeMount() {
62+
if (this.hasBeenClicked) {
63+
this.clicked = true;
64+
}
65+
},
5166
};
5267
</script>

frontend/src/components/app/users/UserProfile.vue

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<div class="text-center flex flex-col mx-auto p-8 border-b">
3939
<LikeButton
4040
v-if="!likeButtons.superLikeClicked"
41+
v-bind:hasBeenClicked="likeButtons.likeClicked"
4142
v-bind:name="'like'"
4243
v-bind:startImage="likeImage"
4344
v-bind:hoverImage="likeImageHover"
@@ -47,15 +48,17 @@
4748
v-on:clicked="buttonClicked"
4849
v-on:revert="buttonRevert"></LikeButton>
4950
<LikeButton
50-
v-if="!likeButtons.likeClicked && superLikesLeft()"
51+
v-if="(!likeButtons.likeClicked && superLikesLeft()) || this.likeButtons.superLikeClicked"
52+
v-bind:hasBeenClicked="likeButtons.superLikeClicked"
5153
v-bind:name="'superLike'"
5254
v-bind:class="{'mt-8': !likeButtons.superLikeClicked}"
5355
v-bind:startImage="superLikeImage"
5456
v-bind:hoverImage="superLikeImageHover"
5557
v-bind:clickedImage="superLikeImageClicked"
5658
v-bind:text="'Super Like'"
5759
v-bind:textRevert="'Unlike'"
58-
v-bind:description="`Worth 10 likes, and ${user.first_name} sees your extra interest`"
60+
v-bind:counter="`${this.$store.getters.getLoggedInUser.superlikes_counter} left today`"
61+
v-bind:description="`${user.first_name} will notice you better.`"
5962
v-on:clicked="buttonClicked"
6063
v-on:revert="buttonRevert"></LikeButton>
6164
</div>
@@ -67,14 +70,19 @@
6770
v-bind:position="'center'"
6871
v-bind:starting-option="'harassment'"
6972
v-bind:options="['harassment', 'bot', 'spam', 'inappropriate content']"></DropdownDisplayChoice>
70-
<h1 v-on:click="makeReport()" class="onboarding-sub-container-content-button-outline mx-auto">Report</h1>
73+
<h1 v-if="!reported" v-on:click="makeReport()" class="onboarding-sub-container-content-button-outline mx-auto">Report</h1>
74+
<h1 v-else class="onboarding-sub-container-content-button-outline cursor-default text-green-500 border-green-500 mx-auto">Thank you</h1>
7175
</div>
72-
<div class="text-center p-8">
73-
<h1
74-
v-on:click="block()"
76+
<div v-if="user.blocks.length === 0 && blocked === false" class="text-center p-8">
77+
<h1 v-on:click="block()"
7578
class="onboarding-sub-container-content-button-outline text-red-500 mt-0 border-red-500 mx-auto">Block</h1>
7679
<h1 class="mx-auto mt-2 text-sm text-gray-600">Don't suggest this user and stop notifications</h1>
7780
</div>
81+
<div v-else class="text-center p-8">
82+
<h1 v-on:click="unblock()"
83+
class="onboarding-sub-container-content-button-outline text-green-500 mt-0 border-green-500 mx-auto">Unblock</h1>
84+
<h1 class="mx-auto mt-2 text-sm text-gray-600">Suggest this user and enable notifications</h1>
85+
</div>
7886
</div>
7987
</template>
8088

@@ -108,6 +116,8 @@ export default {
108116
superLikeClicked: false,
109117
},
110118
report: 'harassment',
119+
reported: false,
120+
blocked: false,
111121
}),
112122
methods: {
113123
preferences() {
@@ -132,7 +142,7 @@ export default {
132142
return 'any gender';
133143
},
134144
superLikesLeft() {
135-
return true;
145+
return this.$store.getters.getLoggedInUser.superlikes_counter > 0;
136146
},
137147
async buttonClicked(...args) {
138148
const [name] = args;
@@ -143,6 +153,8 @@ export default {
143153
await this.$http.post(`/like/${this.user.id}`, { is_superlike: true });
144154
this.likeButtons.superLikeClicked = true;
145155
}
156+
const user = await this.$http.get(`/users/${this.$store.getters.getLoggedInUser.id}`);
157+
await this.$store.dispatch('login', user.data);
146158
},
147159
async buttonRevert(...args) {
148160
const [name] = args;
@@ -153,6 +165,8 @@ export default {
153165
await this.$http.post(`/unlike/${this.user.id}`, { is_superlike: true });
154166
this.likeButtons.superLikeClicked = false;
155167
}
168+
const user = await this.$http.get(`/users/${this.$store.getters.getLoggedInUser.id}`);
169+
await this.$store.dispatch('login', user.data);
156170
},
157171
saveSingleChoice(...args) {
158172
const [key, value] = args;
@@ -162,12 +176,35 @@ export default {
162176
},
163177
async makeReport() {
164178
await this.$http.post(`/profile/report/${this.user.id}`, { reason: this.report });
179+
this.reported = true;
180+
setTimeout(() => {
181+
this.reported = false;
182+
}, 3000);
165183
},
166184
async block() {
167-
return true;
185+
await this.$http.post(`/profile/block/${this.user.id}`);
186+
this.blocked = true;
187+
},
188+
async unblock() {
189+
await this.$http.post(`/profile/unblock/${this.user.id}`);
190+
this.blocked = false;
191+
},
192+
checkIfUserIsLiked() {
193+
const likes = this.$store.getters.getLoggedInUser.likes.sent;
194+
const viewedUserId = this.user.id;
195+
for (let i = 0; i < likes.length; i += 1) {
196+
if (likes[i].liked_id === viewedUserId) {
197+
if (likes[i].is_superlike) {
198+
this.likeButtons.superLikeClicked = true;
199+
} else {
200+
this.likeButtons.likeClicked = true;
201+
}
202+
}
203+
}
168204
},
169205
},
170206
async beforeMount() {
207+
this.checkIfUserIsLiked();
171208
const sliderRangesRequest = await this.$http.get('/search/values');
172209
const maxScore = sliderRangesRequest.data.search_minmax.max_score;
173210
const sliderScore = document.getElementById('sliderScore');

0 commit comments

Comments
 (0)