35 lines
983 B
JavaScript
35 lines
983 B
JavaScript
import { getCookie, setCookie } from '../utils/cookies.js'
|
|
import axios from '@nextcloud/axios'
|
|
import { defineStore } from 'pinia'
|
|
import { generateUrl } from '@nextcloud/router'
|
|
|
|
export const useSubscriptions = defineStore('subscriptions', {
|
|
state: () => ({
|
|
subs: [],
|
|
favorites: [],
|
|
}),
|
|
actions: {
|
|
async fetch() {
|
|
const metrics = await axios.get(
|
|
generateUrl('/apps/gpoddersync/personal_settings/metrics'),
|
|
)
|
|
const subs = [...metrics.data.subscriptions].sort(
|
|
(a, b) => b.listenedSeconds - a.listenedSeconds,
|
|
)
|
|
this.subs = subs.map((sub) => sub.url)
|
|
|
|
try {
|
|
this.favorites = JSON.parse(getCookie('repod.favorites')) || []
|
|
} catch {}
|
|
},
|
|
addFavorite(url) {
|
|
this.favorites.push(url)
|
|
setCookie('repod.favorites', JSON.stringify(this.favorites), 365)
|
|
},
|
|
removeFavorite(url) {
|
|
this.favorites = this.favorites.filter((favorite) => favorite !== url)
|
|
setCookie('repod.favorites', JSON.stringify(this.favorites), 365)
|
|
},
|
|
},
|
|
})
|