1
1
import { getMusicQueueRenderer } from './song' ;
2
2
import { mapQueueItem } from './utils' ;
3
3
4
- import { ConnectionEventUnion } from '@/plugins/music-together/connection' ;
5
4
import { t } from '@/i18n' ;
6
5
7
- import type { Profile , QueueAPI , VideoData } from '../types' ;
6
+ import type { ConnectionEventUnion } from '@/plugins/music-together/connection' ;
7
+ import type { Profile , QueueElement , VideoData } from '../types' ;
8
8
import type { QueueItem } from '@/types/datahost-get-state' ;
9
9
10
10
const getHeaderPayload = ( ( ) => {
@@ -103,26 +103,29 @@ const getHeaderPayload = (() => {
103
103
export type QueueOptions = {
104
104
videoList ?: VideoData [ ] ;
105
105
owner ?: Profile ;
106
- queue ?: HTMLElement & QueueAPI ;
106
+ queue ?: QueueElement ;
107
107
getProfile : ( id : string ) => Profile | undefined ;
108
108
}
109
109
export type QueueEventListener = ( event : ConnectionEventUnion ) => void ;
110
110
111
111
export class Queue {
112
- private queue : ( HTMLElement & QueueAPI ) ;
112
+ private readonly queue : QueueElement ;
113
+
113
114
private originalDispatch ?: ( obj : {
114
115
type : string ;
115
116
payload ?: { items ?: QueueItem [ ] | undefined ; } ;
116
117
} ) => void ;
118
+
117
119
private internalDispatch = false ;
118
120
private ignoreFlag = false ;
119
121
private listeners : QueueEventListener [ ] = [ ] ;
120
- private owner : Profile | null = null ;
121
- private getProfile : ( id : string ) => Profile | undefined ;
122
+
123
+ private owner : Profile | null ;
124
+ private readonly getProfile : ( id : string ) => Profile | undefined ;
122
125
123
126
constructor ( options : QueueOptions ) {
124
127
this . getProfile = options . getProfile ;
125
- this . queue = options . queue ?? document . querySelector < HTMLElement & QueueAPI > ( '#queue' ) ! ;
128
+ this . queue = options . queue ?? ( document . querySelector < QueueElement > ( '#queue' ) ! ) ;
126
129
this . owner = options . owner ?? null ;
127
130
this . _videoList = options . videoList ?? [ ] ;
128
131
}
@@ -135,11 +138,11 @@ export class Queue {
135
138
}
136
139
137
140
get selectedIndex ( ) {
138
- return mapQueueItem ( ( it ) => it ?. selected , this . queue . store . getState ( ) . queue . items ) . findIndex ( Boolean ) ?? 0 ;
141
+ return mapQueueItem ( ( it ) => it ?. selected , this . queue . queue . store . store . getState ( ) . queue . items ) . findIndex ( Boolean ) ?? 0 ;
139
142
}
140
143
141
144
get rawItems ( ) {
142
- return this . queue ?. store . getState ( ) . queue . items ;
145
+ return this . queue ?. queue . store . store . getState ( ) . queue . items ;
143
146
}
144
147
145
148
get flatItems ( ) {
@@ -169,8 +172,8 @@ export class Queue {
169
172
this . queue ?. dispatch ( {
170
173
type : 'ADD_ITEMS' ,
171
174
payload : {
172
- nextQueueItemId : this . queue . store . getState ( ) . queue . nextQueueItemId ,
173
- index : index ?? this . queue . store . getState ( ) . queue . items . length ?? 0 ,
175
+ nextQueueItemId : this . queue . queue . store . store . getState ( ) . queue . nextQueueItemId ,
176
+ index : index ?? this . queue . queue . store . store . getState ( ) . queue . items . length ?? 0 ,
174
177
items,
175
178
shuffleEnabled : false ,
176
179
shouldAssignIds : true
@@ -249,7 +252,7 @@ export class Queue {
249
252
return ;
250
253
}
251
254
252
- if ( this . originalDispatch ) this . queue . store . dispatch = this . originalDispatch ;
255
+ if ( this . originalDispatch ) this . queue . queue . store . store . dispatch = this . originalDispatch ;
253
256
}
254
257
255
258
injection ( ) {
@@ -258,8 +261,8 @@ export class Queue {
258
261
return ;
259
262
}
260
263
261
- this . originalDispatch = this . queue . store . dispatch ;
262
- this . queue . store . dispatch = ( event ) => {
264
+ this . originalDispatch = this . queue . queue . store . store . dispatch ;
265
+ this . queue . queue . store . store . dispatch = ( event ) => {
263
266
if ( ! this . queue || ! this . owner ) {
264
267
console . error ( 'Queue is not initialized!' ) ;
265
268
return ;
@@ -361,10 +364,13 @@ export class Queue {
361
364
362
365
const fakeContext = {
363
366
...this . queue ,
364
- store : {
365
- ...this . queue . store ,
366
- dispatch : this . originalDispatch
367
- }
367
+ queue : {
368
+ ...this . queue . queue ,
369
+ store : {
370
+ ...this . queue . queue . store ,
371
+ dispatch : this . originalDispatch ,
372
+ }
373
+ } ,
368
374
} ;
369
375
this . originalDispatch ?. call ( fakeContext , event ) ;
370
376
} ;
@@ -400,7 +406,7 @@ export class Queue {
400
406
type : 'UPDATE_ITEMS' ,
401
407
payload : {
402
408
items : items ,
403
- nextQueueItemId : this . queue . store . getState ( ) . queue . nextQueueItemId ,
409
+ nextQueueItemId : this . queue . queue . store . store . getState ( ) . queue . nextQueueItemId ,
404
410
shouldAssignIds : true ,
405
411
currentIndex : - 1
406
412
}
0 commit comments