0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch.git synced 2024-12-22 05:12:57 -05:00

Clean up follow button

This commit is contained in:
dragongoose 2024-06-02 10:48:35 -04:00
parent 49a8a80c25
commit 7018e264b2
No known key found for this signature in database
GPG key ID: 01397EEC371CDAA5

View file

@ -16,26 +16,48 @@ export default {
}
},
methods: {
followStreamer() {
toggleFollow() {
const username = this.$props.username
const follows = localStorage.getItem('following') || '[]'
let parsedFollows: string[] = JSON.parse(follows)
if (follows?.includes(username)) {
const index = parsedFollows.indexOf(username)
console.log(index)
if (index === -1) return
parsedFollows.splice(index, 1)
console.log(parsedFollows)
if (this.isFollowing) {
this.unfollowStreamer(username)
this.isFollowing = false
} else {
if (follows) parsedFollows = JSON.parse(follows)
parsedFollows.push(username)
this.followStreamer(username)
this.isFollowing = true
}
},
/**
* Follows a Streamer.
* @param username
* @returns true if streamer was followed, false if streamer was already followed.
*/
followStreamer(username: string): boolean {
const follows = localStorage.getItem('following') || '[]'
let parsedFollows: string[] = JSON.parse(follows)
if (parsedFollows.includes(username)) return false
parsedFollows.push(username)
localStorage.setItem('following', JSON.stringify(parsedFollows))
return true
},
/**
* Unfollows a streamer.
* @param username
* @returns true if unfollowed, false if not followed.
*/
unfollowStreamer(username: string): boolean {
const follows = localStorage.getItem('following') || '[]'
let parsedFollows: string[] = JSON.parse(follows)
const index = parsedFollows.indexOf(username)
if (index === -1) return false
parsedFollows.splice(index, 1)
localStorage.setItem('following', JSON.stringify(parsedFollows))
return true
}
},
mounted() {
@ -53,11 +75,8 @@ export default {
</script>
<template>
<button
ref="followButton"
@click="followStreamer"
class="text-contrast text-sm font-bold p-2 py-1 rounded-md bg-purple"
>
<button ref="followButton" @click="toggleFollow"
class="text-contrast text-sm font-bold p-2 py-1 rounded-md bg-purple">
<v-icon name="bi-heart-fill" scale="0.85"></v-icon>
<span v-if="isFollowing"> {{ $t('streamer.unfollow') }} </span>
<span v-else> {{ $t('streamer.follow') }} </span>