Compare commits
	
		
			3 Commits
		
	
	
		
			e26f555300
			...
			2bc2fb14f6
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 2bc2fb14f6 | |||
| 281c3ef4d6 | |||
| aa6032031f | 
| @@ -2,6 +2,11 @@ | |||||||
|  |  | ||||||
| Frontend for [ministream](https://git.t-juice.club/torjus/ministream). | Frontend for [ministream](https://git.t-juice.club/torjus/ministream). | ||||||
|  |  | ||||||
|  | ## Development | ||||||
|  |  | ||||||
|  | While developing, you should run the backend on localhost:8080. Then run parcel src/index.html. | ||||||
|  | The development server should do api-requests to the backend, while frontend will reload on changes. | ||||||
|  |  | ||||||
| ## About | ## About | ||||||
|  |  | ||||||
| Made with TypeScript and React. | Made with TypeScript and React. | ||||||
|   | |||||||
| @@ -28,17 +28,48 @@ export class App extends React.Component<AppProps, AppState> { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async componentDidMount(): Promise<void> { |     async componentDidMount(): Promise<void> { | ||||||
|  |         await this.updateStreamList() | ||||||
|  |         setInterval(() => { | ||||||
|  |             this.updateStreamList() | ||||||
|  |         }, 10000) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async updateStreamList() { | ||||||
|         const streams = await this.apiClient.listStreams() |         const streams = await this.apiClient.listStreams() | ||||||
|  |         const sortedStreams = streams.sort((a, b) => { | ||||||
|  |             if (a > b) { | ||||||
|  |                 return -1 | ||||||
|  |             } else if (a < b) { | ||||||
|  |                 return 1 | ||||||
|  |             } | ||||||
|  |             return 0 | ||||||
|  |         }) | ||||||
|  |  | ||||||
|  |         if (sortedStreams.length != this.state.streamList.length) { | ||||||
|  |             this.setStreamList(streams) | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (!sortedStreams.every((_, idx) => { | ||||||
|  |             return sortedStreams[idx] === this.state.streamList[idx] | ||||||
|  |         })) { | ||||||
|  |             this.setStreamList(streams) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     setStreamList(streamList: string[]) { | ||||||
|  |         console.log("stream list updated") | ||||||
|         this.setState((state) => { |         this.setState((state) => { | ||||||
|             return { selectedStream: state.selectedStream, streamList: streams } |             return { selectedStream: state.selectedStream, streamList: streamList } | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     updateSelect(selected: string): void { |     updateSelect(selected: string): void { | ||||||
|  |         if (selected !== this.state.selectedStream) { | ||||||
|             this.setState((state) => { |             this.setState((state) => { | ||||||
|                 return { streamList: state.streamList, selectedStream: selected } |                 return { streamList: state.streamList, selectedStream: selected } | ||||||
|             }) |             }) | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     render() { |     render() { | ||||||
|         return ( |         return ( | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user