From 3d87fda2ebe68e80ab4a059b1ba0488167b310a4 Mon Sep 17 00:00:00 2001 From: cdrani Date: Tue, 14 May 2024 12:27:29 -0600 Subject: [PATCH] feat: get blocked tracks from store --- src/data/current.js | 4 ++++ src/stores/cache.js | 4 ++++ src/stores/data.js | 15 +++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/data/current.js b/src/data/current.js index 90acce7a..a44d3542 100644 --- a/src/data/current.js +++ b/src/data/current.js @@ -81,6 +81,10 @@ class CurrentData { value: { playbackRate: 1, preservesPitch: true } }) } + + get blockedTracks() { + return this._store.blockedTracks + } } export const currentData = new CurrentData(store) diff --git a/src/stores/cache.js b/src/stores/cache.js index 31c20b10..0d2b2f02 100644 --- a/src/stores/cache.js +++ b/src/stores/cache.js @@ -2,6 +2,10 @@ export default class CacheStore { #cache constructor() { this.#cache = sessionStorage } + get cache() { + return this.#cache + } + getKey(key) { const result = this.#cache.getItem(key) try { return JSON.parse(result) } diff --git a/src/stores/data.js b/src/stores/data.js index a77b9651..415478d0 100644 --- a/src/stores/data.js +++ b/src/stores/data.js @@ -14,6 +14,21 @@ class DataStore { this.#dispatcher = dispatcher } + get blockedTracks() { + const cacheValues = Object.values(JSON.parse(JSON.stringify(this.#cache.cache))) + return cacheValues.filter(value => { + try { + let parsed = JSON.parse(value) + const id = parsed?.id + if (!id) return false + + return id.includes('by') && parsed.isSkipped + } catch { + return false + } + }) + } + async populate() { const response = await this.#dispatcher.sendEvent({ eventType: 'storage.populate', detail: {} })