0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch.git synced 2024-12-22 13:22:58 -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: { methods: {
followStreamer() { toggleFollow() {
const username = this.$props.username const username = this.$props.username
const follows = localStorage.getItem('following') || '[]'
let parsedFollows: string[] = JSON.parse(follows) if (this.isFollowing) {
this.unfollowStreamer(username)
if (follows?.includes(username)) {
const index = parsedFollows.indexOf(username)
console.log(index)
if (index === -1) return
parsedFollows.splice(index, 1)
console.log(parsedFollows)
this.isFollowing = false this.isFollowing = false
} else { } else {
if (follows) parsedFollows = JSON.parse(follows) this.followStreamer(username)
parsedFollows.push(username)
this.isFollowing = true 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)) 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() { mounted() {
@ -53,11 +75,8 @@ export default {
</script> </script>
<template> <template>
<button <button ref="followButton" @click="toggleFollow"
ref="followButton" class="text-contrast text-sm font-bold p-2 py-1 rounded-md bg-purple">
@click="followStreamer"
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> <v-icon name="bi-heart-fill" scale="0.85"></v-icon>
<span v-if="isFollowing"> {{ $t('streamer.unfollow') }} </span> <span v-if="isFollowing"> {{ $t('streamer.unfollow') }} </span>
<span v-else> {{ $t('streamer.follow') }} </span> <span v-else> {{ $t('streamer.follow') }} </span>