import { TrackModel } from '../database/TracksDatabase' ; import { StateDatabase } from '../database/StateDatabase' ; import { DraftArray , DraftObject } from 'immer' ; param { DraftArray < TrackModel > } List returns { DraftArray < TrackModel > } export function shuffleList ( list ) { let current = list . length ; let temp ; let swap ; while ( current ) { swap = Math . floor ( Math . random ( ) * current -- ) ; temp = list [ current ] ; list [ current ] = list [ swap ] ; list [ swap ] = temp ; } return list ; } export function updatePlayerState ( queue , originalQueue , cursor ) { let db = new StateDatabase ( 'state' ) ; db . queue . put ( { queue , originalQueue , cursor , id : 1 } ) . then ( ( ) => db . close ( ) ) ; } export function updatePlayerStateCursor ( cursor ) { let db = new StateDatabase ( 'state' ) ; db . queue . update ( 1 , { cursor } ) . then ( ( ) => db . close ( ) ) ; } export function updatePlayerStateQueue ( queue , originalQueue ) { let db = new StateDatabase ( 'state' ) ; db . queue . update ( 1 , { queue , originalQueue } ) ; db . close ( ) ; }