Skip to content

Commit f605b62

Browse files
devvaannshabose
authored andcommitted
feat: add close button in live preview overlay so that it can be closed
1 parent e598a47 commit f605b62

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/LiveDevelopment/main.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,26 +274,48 @@ define(function main(require, exports, module) {
274274

275275
let $livePreviewPanel = null; // stores the live preview panel, need this as overlay is appended inside this
276276
let $overlayContainer = null; // the overlay container
277+
let shouldShowSyncErrorOverlay = true; // once user closes the overlay we don't show them again
278+
let shouldShowConnectingOverlay = true;
277279

278280
/**
279281
* this function is responsible to show the overlay.
280282
* so overlay is shown when the live preview is connecting or live preview stopped because of some syntax error
281283
* @param {String} textMessage - the text that is written inside the overlay
284+
* @param {Number} status - 1 for connect, 4 for sync error but we match it using MultiBrowserLiveDev
282285
*/
283-
function _showOverlay(textMessage) {
286+
function _showOverlay(textMessage, status) {
284287
if (!$livePreviewPanel) {
285288
$livePreviewPanel = $("#panel-live-preview");
286289
}
287290

288291
// remove any existing overlay
289292
_hideOverlay();
290293

294+
// to not show the overlays if user has already closed it before
295+
if(status === MultiBrowserLiveDev.STATUS_CONNECTING && !shouldShowConnectingOverlay) { return; }
296+
if(status === MultiBrowserLiveDev.STATUS_SYNC_ERROR && !shouldShowSyncErrorOverlay) { return; }
297+
291298
// create the overlay element
292299
// styled inside the 'src/extensionsIntegrated/Phoenix-live-preview/live-preview.css'
293300
$overlayContainer = $("<div>").addClass("live-preview-status-overlay"); // the wrapper for overlay element
294301
const $message = $("<div>").addClass("live-preview-overlay-message").text(textMessage);
295302

303+
// the close button at the right end of the overlay
304+
const $close = $("<div>").addClass("live-preview-overlay-close")
305+
.attr("title", Strings.LIVE_PREVIEW_HIDE_OVERLAY)
306+
.on('click', () => {
307+
if(status === MultiBrowserLiveDev.STATUS_CONNECTING) {
308+
shouldShowConnectingOverlay = false;
309+
} else if(status === MultiBrowserLiveDev.STATUS_SYNC_ERROR) {
310+
shouldShowSyncErrorOverlay = false;
311+
}
312+
_hideOverlay();
313+
});
314+
const $closeIcon = $("<i>").addClass("fas fa-times");
315+
316+
$close.append($closeIcon);
296317
$overlayContainer.append($message);
318+
$overlayContainer.append($close);
297319
$livePreviewPanel.append($overlayContainer);
298320
}
299321

@@ -384,9 +406,9 @@ define(function main(require, exports, module) {
384406

385407
MultiBrowserLiveDev.on(MultiBrowserLiveDev.EVENT_STATUS_CHANGE, function(event, status) {
386408
if (status === MultiBrowserLiveDev.STATUS_CONNECTING) {
387-
_showOverlay(Strings.LIVE_DEV_STATUS_TIP_PROGRESS1);
409+
_showOverlay(Strings.LIVE_DEV_STATUS_TIP_PROGRESS1, status);
388410
} else if (status === MultiBrowserLiveDev.STATUS_SYNC_ERROR) {
389-
_showOverlay(Strings.LIVE_DEV_STATUS_TIP_SYNC_ERROR);
411+
_showOverlay(Strings.LIVE_DEV_STATUS_TIP_SYNC_ERROR, status);
390412
} else {
391413
_hideOverlay();
392414
}

src/extensionsIntegrated/Phoenix-live-preview/live-preview.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,9 @@
172172
text-align: center;
173173
}
174174

175+
.live-preview-overlay-close {
176+
position: absolute;
177+
top: 4px;
178+
right: 10px;
179+
font-size: 12px;
180+
}

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ define({
143143
"LIVE_DEV_SERVER_NOT_READY_MESSAGE": "Error starting up the HTTP server for live preview files. Please try again.",
144144
"LIVE_DEVELOPMENT_TROUBLESHOOTING": "For more information, see <a href='{0}' title='{0}'>Troubleshooting Live Preview connection errors</a>.",
145145

146+
"LIVE_PREVIEW_HIDE_OVERLAY": "Hide this message",
146147
"LIVE_DEV_STATUS_TIP_NOT_CONNECTED": "Live Preview",
147148
"LIVE_DEV_STATUS_TIP_PROGRESS1": "Live Preview: Connecting\u2026",
148149
"LIVE_DEV_STATUS_TIP_PROGRESS2": "Live Preview: Initializing\u2026",

0 commit comments

Comments
 (0)