@@ -16,13 +16,14 @@ import BasePreview from "../preview";
16
16
17
17
export default class Preview extends BasePreview {
18
18
public displayPreview : KnockoutObservable < boolean > = ko . observable ( false ) ;
19
+ public displayPlaceholder : KnockoutObservable < boolean > = ko . observable ( false ) ;
20
+ public loading : KnockoutObservable < boolean > = ko . observable ( false ) ;
19
21
public placeholderText : KnockoutObservable < string > ;
20
22
private lastBlockId : number ;
21
23
private lastTemplate : string ;
22
24
private lastRenderedHtml : string ;
23
25
private messages = {
24
26
NOT_SELECTED : $t ( "Empty Block" ) ,
25
- LOADING : $t ( "Loading..." ) ,
26
27
UNKNOWN_ERROR : $t ( "An unknown error occurred. Please try again." ) ,
27
28
} ;
28
29
@@ -68,20 +69,25 @@ export default class Preview extends BasePreview {
68
69
if ( this . lastRenderedHtml ) {
69
70
this . data . main . html ( this . lastRenderedHtml ) ;
70
71
this . displayPreview ( true ) ;
72
+ this . displayPlaceholder ( false ) ;
71
73
}
72
-
73
- return ;
74
+ }
75
+ else {
76
+ this . displayPreview ( false ) ;
77
+ this . displayPlaceholder ( true ) ;
78
+ this . placeholderText ( "" ) ;
74
79
}
75
80
76
- this . displayPreview ( false ) ;
77
81
78
82
if ( ! data . block_id || data . template . length === 0 ) {
83
+ this . displayPreview ( false ) ;
84
+ this . displayPlaceholder ( true ) ;
79
85
this . placeholderText ( this . messages . NOT_SELECTED ) ;
80
86
81
87
return ;
82
88
}
83
89
84
- this . placeholderText ( this . messages . LOADING ) ;
90
+ this . loading ( true ) ;
85
91
86
92
const url = Config . getConfig ( "preview_url" ) ;
87
93
const requestConfig = {
@@ -100,6 +106,8 @@ export default class Preview extends BasePreview {
100
106
. done ( ( response ) => {
101
107
// Empty content means something bad happened in the controller that didn't trigger a 5xx
102
108
if ( typeof response . data !== "object" ) {
109
+ this . displayPreview ( false ) ;
110
+ this . displayPlaceholder ( true ) ;
103
111
this . placeholderText ( this . messages . UNKNOWN_ERROR ) ;
104
112
105
113
return ;
@@ -110,8 +118,11 @@ export default class Preview extends BasePreview {
110
118
111
119
if ( response . data . content ) {
112
120
this . displayPreview ( true ) ;
121
+ this . displayPlaceholder ( false ) ;
113
122
this . data . main . html ( response . data . content ) ;
114
123
} else if ( response . data . error ) {
124
+ this . displayPreview ( false ) ;
125
+ this . displayPlaceholder ( true ) ;
115
126
this . placeholderText ( response . data . error ) ;
116
127
}
117
128
@@ -120,7 +131,12 @@ export default class Preview extends BasePreview {
120
131
this . lastRenderedHtml = response . data . content ;
121
132
} )
122
133
. fail ( ( ) => {
134
+ this . displayPreview ( false ) ;
135
+ this . displayPlaceholder ( true ) ;
123
136
this . placeholderText ( this . messages . UNKNOWN_ERROR ) ;
137
+ } )
138
+ . always ( ( ) => {
139
+ this . loading ( false ) ;
124
140
} ) ;
125
141
}
126
142
}
0 commit comments