import * as React from "react"; import {AsyncAjax, PromiseToken} from "../../../Shared/AsyncAjax"; import {ListGroup, ListGroupItem} from "react-bootstrap"; import {PlayerItem} from "./PlayerItem"; import 'jQuery'; import "es6-promise"; declare var smartformsrecordingparams:any; export class PlayerItemList extends React.Component{ public LastItem:any=null; private executinSearch:boolean=false; private currentPage=-1; private items:PlayerHeader[]=[]; private noMoreRecords:boolean=false; private ExecutinSearchToken:PromiseToken; constructor(){ super(); this.state={ GroupedPlayers:[], SelectedItem:null }; } ItemSelected(player:PlayerHeader):void{ this.setState({SelectedItem:player}); this.props.ItemSelected(player); } render(){ return ( {this.state.GroupedPlayers.map((groupedPlay,index)=>{return ( this.ItemSelected(groupedPlay.RelatedPlays[0])} className={groupedPlay!=null&&groupedPlay.Contains(this.state.SelectedItem)?"active":""} > )})} {this.noMoreRecords? ( this.state.GroupedPlayers==null||this.state.GroupedPlayers.length==0? Oh there are no recordings to show, please wait until someone use your site and try again : End of the road, there are no more recordings! ):this.LastItem=list)} onClick={()=>this.ItemSelected(null)} className=''/> } ); } componentDidMount() { jQuery(window).scroll(()=>{ this.CheckIfLoadingIsNeedes(); }); this.ExecuteSearch(); } public Refresh(){ this.noMoreRecords=false; this.currentPage=-1; if(this.ExecutinSearchToken!=null) { this.ExecutinSearchToken.Cancel(); this.ExecutinSearchToken=null; } this.setState({GroupedPlayers:[],SelectedItem:null}); this.ExecuteSearch(); } public async ExecuteSearch(){ if(!this.executinSearch) { this.executinSearch=true; let promiseWithToken=AsyncAjax.PostWithToken({action:'rednao_ssr_get_recordings',page:++this.currentPage}); this.ExecutinSearchToken=promiseWithToken.Token; let resultWithToken=await promiseWithToken.Promise; if(resultWithToken.WasCancelled) { this.executinSearch=false; return; } this.ExecutinSearchToken=null; let result=resultWithToken.Result; let groupedPlayers:GroupedPlayers[]=this.MergeRelatedRecordings(result); if(result.length==0||result.length<20) this.noMoreRecords=true; this.setState({GroupedPlayers:this.state.GroupedPlayers.concat(groupedPlayers)}); this.executinSearch=false; } } private CheckIfLoadingIsNeedes() { if(this.LastItem==null) return; let scrollTop=jQuery(window).scrollTop(); let windowHeight=jQuery(window).height(); let lastNodeTop=this.LastItem.$Container.offset().top; if(lastNodeTop-200, prevState: Readonly, prevContext: any): void { if(this.props.SelectedItem!=prevProps.SelectedItem&&this.props.SelectedItem!=this.state.SelectedItem) this.setState({SelectedItem:this.props.SelectedItem}); } private MergeRelatedRecordings(recordings: PlayerHeader[]):GroupedPlayers[] { let groupedPlayersList:GroupedPlayers[]=[]; for(let i=0;i interface PlayerItemListState{ GroupedPlayers:GroupedPlayers[]; SelectedItem:PlayerHeader; } interface PlayerItemListProps{ ItemSelected:(item:PlayerHeader)=>void, SelectedItem:PlayerHeader; } export interface PlayerHeader{ duration:string; start_time:string; uniq_id:string; url:string; userid:string; session_id:string; groupedPlayers:GroupedPlayers; } export class GroupedPlayers{ public RelatedPlays:PlayerHeader[]=[]; public Duration:number=0; public StartTime:string; public SessionId:string; public UserId:string; public UniqId:string; constructor() { } public Contains(player:PlayerHeader) { return this.RelatedPlays.indexOf(player)>=0; } public AddPlayer(player:PlayerHeader) { if(this.RelatedPlays.length==0) { this.StartTime=player.start_time; this.SessionId=player.session_id; this.UserId=player.userid; this.UniqId=player.uniq_id; } this.RelatedPlays.splice(0,0,player); this.Duration+=parseInt(player.duration); player.groupedPlayers=this; } } //