Skip to content

Commit

Permalink
refactor: only expose refreshQueue from Queue
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrani committed May 15, 2024
1 parent 0924ad5 commit 0eee5e2
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/models/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export default class Queue {
this._dispatcher = new Dispatcher()
}

get addedToQueue() {
get #addedToQueue() {
return document.querySelector('[aria-label="Next in queue"]')?.children || []
}

get nextInQueue() {
get #nextInQueue() {
return document.querySelector('[aria-label="Next up"]')?.children || []
}

get tracksInQueue() {
return [...this.addedToQueue, ...this.nextInQueue].map(div => {
get #tracksInQueue() {
return [...this.#addedToQueue, ...this.#nextInQueue].map(div => {
const songInfo = Array.from(div.querySelectorAll('p > span'))

const songTitle = songInfo.at(0).innerText
Expand All @@ -29,7 +29,7 @@ export default class Queue {
})
}

get blockedTracks() {
get #blockedTracks() {
return currentData.blockedTracks
}

Expand All @@ -40,40 +40,45 @@ export default class Queue {
})
}

async refreshQueue() {
await this.#getQueuedTracks()
await this.#setQueuedTracks()
}

async #dispatchQueueSetter() {
return await this._dispatcher.sendEvent({
eventType: 'queue.set',
detail: { key: 'queue.set', values: { next_tracks: this._nextQueuedTracks } },
})
}

async setQueuedTracks() {
async #setQueuedTracks() {
if (!this._userBlockedTracks.length) return
if (!this._nextQueuedTracks.length) return

await this.#dispatchQueueSetter()
}

async getQueuedTracks() {
this._userBlockedTracks = this.filterUnBlockedTracks()
async #getQueuedTracks() {
this._userBlockedTracks = this.#filterUnBlockedTracks()
if (!this._userBlockedTracks.length) return

const queueList = await this.#dispatchQueueList()

const spotifyQueuedTracks = queueList?.data?.player_state?.next_tracks
this._nextQueuedTracks = this.filterQueuedTracks({
this._nextQueuedTracks = this.#filterQueuedTracks({
spotifyQueuedTracks,
userBlockedTracks: this._userBlockedTracks
})
}

filterUnBlockedTracks() {
const blocked = this.blockedTracks
const tracksInQueue = this.tracksInQueue
#filterUnBlockedTracks() {
const blocked = this.#blockedTracks
const tracksInQueue = this.#tracksInQueue
return blocked.filter(track => tracksInQueue.includes(track.id))
}

filterQueuedTracks({ spotifyQueuedTracks, userBlockedTracks }) {
#filterQueuedTracks({ spotifyQueuedTracks, userBlockedTracks }) {
const userBlockedTrackIds = userBlockedTracks.map(track => `spotify:track:${track.trackId}`)
return spotifyQueuedTracks.filter(item => !userBlockedTrackIds.includes(item.uri))
}
Expand Down

0 comments on commit 0eee5e2

Please sign in to comment.