| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  | import {UIEventSource} from "../../Logic/UIEventSource"; | 
					
						
							|  |  |  | import BaseUIElement from "../BaseUIElement"; | 
					
						
							|  |  |  | import {VariableUiElement} from "../Base/VariableUIElement"; | 
					
						
							|  |  |  | import Translations from "../i18n/Translations"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Shows that 'images are uploading', 'all images are uploaded' as relevant... | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | export default class UploadFlowStateUI extends VariableUiElement { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  |     constructor(queue: UIEventSource<string[]>, failed: UIEventSource<string[]>, success: UIEventSource<string[]>) { | 
					
						
							|  |  |  |         const t = Translations.t.image; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-28 00:45:49 +02:00
										 |  |  |         super( | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |             queue.map(queue => { | 
					
						
							|  |  |  |                 const failedReasons = failed.data | 
					
						
							|  |  |  |                 const successCount = success.data.length | 
					
						
							|  |  |  |                 const pendingCount = queue.length - successCount - failedReasons.length; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 let stateMessages: BaseUIElement[] = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (pendingCount == 1) { | 
					
						
							|  |  |  |                     stateMessages.push(t.uploadingPicture.Clone().SetClass("alert")) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (pendingCount > 1) { | 
					
						
							|  |  |  |                     stateMessages.push(t.uploadingMultiple.Subs({count: "" + pendingCount}).SetClass("alert")) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (failedReasons.length > 0) { | 
					
						
							|  |  |  |                     stateMessages.push(t.uploadFailed.Clone().SetClass("alert")) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (successCount > 0 && pendingCount == 0) { | 
					
						
							|  |  |  |                     stateMessages.push(t.uploadDone.SetClass("thanks")) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 stateMessages.forEach(msg => msg.SetStyle("display: block ruby")) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return stateMessages | 
					
						
							|  |  |  |             }, [failed, success]) | 
					
						
							| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |