Add ability to export and import followers with settings #121

This commit is contained in:
dragongoose
2024-06-02 11:01:40 -04:00
parent 7018e264b2
commit e5d021e94a
3 changed files with 19 additions and 14 deletions

View File

@ -1,4 +1,5 @@
<script lang="ts">
import { getFollows } from '@/settingsManager';
import { ref } from 'vue'
export default {
@ -33,13 +34,11 @@ export default {
* @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)
let follows = getFollows()
if (follows.includes(username)) return false
if (parsedFollows.includes(username)) return false
parsedFollows.push(username)
localStorage.setItem('following', JSON.stringify(parsedFollows))
follows.push(username)
localStorage.setItem('following', JSON.stringify(follows))
return true
},
@ -49,13 +48,12 @@ export default {
* @returns true if unfollowed, false if not followed.
*/
unfollowStreamer(username: string): boolean {
const follows = localStorage.getItem('following') || '[]'
let parsedFollows: string[] = JSON.parse(follows)
let follows = getFollows()
const index = parsedFollows.indexOf(username)
const index = follows.indexOf(username)
if (index === -1) return false
parsedFollows.splice(index, 1)
localStorage.setItem('following', JSON.stringify(parsedFollows))
follows.splice(index, 1)
localStorage.setItem('following', JSON.stringify(follows))
return true
}