Skip to content

Commit d03ad05

Browse files
committed
refactor: js style appy code for crash recovery
1 parent 35c8ac1 commit d03ad05

File tree

1 file changed

+46
-41
lines changed

1 file changed

+46
-41
lines changed

src/main.js

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ function _unregisterServiceWorkers() {
190190

191191
const SESSION_RESTART_ONCE_DUE_TO_CRITICAL_ERROR = "SESSION_RESTART_ONCE_DUE_TO_CRITICAL_ERROR";
192192

193+
function applyStyles(element, styles) {
194+
Object.assign(element.style, styles);
195+
}
193196
function confirmReload(title, message) {
194197
// vanilla js elements as we dont know if anything else is available in crash scenario
195198
const modal = document.createElement('div');
@@ -214,52 +217,54 @@ function confirmReload(title, message) {
214217
reloadButton.textContent = 'Reload Page';
215218

216219
// Styling for visibility
217-
modalTitle.style.color = 'red';
218-
modal.style.color = 'black';
219-
modal.style.position = 'fixed';
220-
modal.style.top = '0';
221-
modal.style.left = '0';
222-
modal.style.width = '100%';
223-
modal.style.height = '100%';
224-
modal.style.backgroundColor = 'rgba(0, 0, 0, 0.75)';
225-
modal.style.zIndex = '10000000'; // Ensure modal is on top
226-
modal.style.display = 'flex';
227-
modal.style.justifyContent = 'center';
228-
modal.style.alignItems = 'center';
220+
// Define common styles for buttons
221+
const buttonStyles = {
222+
padding: '10px 20px',
223+
marginRight: '10px', // Space between buttons
224+
border: 'none',
225+
color: 'white',
226+
borderRadius: '5px',
227+
cursor: 'pointer'
228+
};
229229

230-
modalContent.style.backgroundColor = 'white';
231-
modalContent.style.padding = '20px';
232-
modalContent.style.borderRadius = '10px';
233-
modalContent.style.textAlign = 'center';
234-
modalContent.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
230+
// Specific styles for different buttons
231+
const copyButtonStyles = {backgroundColor: '#288edf'};
232+
const getHelpButtonStyles = {backgroundColor: '#4CAF50'};
233+
const reloadButtonStyles = {backgroundColor: '#4CAF50'};
235234

236-
// Styling buttons and their container
237-
buttonsContainer.style.marginTop = '20px';
238-
buttonsContainer.style.display = 'flex';
239-
buttonsContainer.style.justifyContent = 'space-around'; // Space buttons nicely
235+
modalTitle.style.color = 'red';
236+
applyStyles(modal, {
237+
color: 'black',
238+
position: 'fixed',
239+
top: '0',
240+
left: '0',
241+
width: '100%',
242+
height: '100%',
243+
backgroundColor: 'rgba(0, 0, 0, 0.75)',
244+
zIndex: '10000000',
245+
display: 'flex',
246+
justifyContent: 'center',
247+
alignItems: 'center'
248+
});
240249

241-
copyButton.style.padding = '10px 20px';
242-
copyButton.style.marginRight = '10px'; // Space between buttons
243-
copyButton.style.border = 'none';
244-
copyButton.style.color = 'white';
245-
copyButton.style.backgroundColor = '#288edf';
246-
copyButton.style.borderRadius = '5px';
247-
copyButton.style.cursor = 'pointer';
250+
applyStyles(modalContent, {
251+
backgroundColor: 'white',
252+
padding: '20px',
253+
borderRadius: '10px',
254+
textAlign: 'center',
255+
boxShadow: '0 4px 8px rgba(0,0,0,0.2)'
256+
});
248257

249-
getHelpButton.style.padding = '10px 20px';
250-
getHelpButton.style.marginRight = '10px'; // Space between buttons
251-
getHelpButton.style.border = 'none';
252-
getHelpButton.style.color = 'white';
253-
getHelpButton.style.backgroundColor = '#4CAF50';
254-
getHelpButton.style.borderRadius = '5px';
255-
getHelpButton.style.cursor = 'pointer';
258+
applyStyles(buttonsContainer, {
259+
marginTop: '20px',
260+
display: 'flex',
261+
justifyContent: 'space-around'
262+
});
256263

257-
reloadButton.style.padding = '10px 20px';
258-
reloadButton.style.border = 'none';
259-
reloadButton.style.color = 'white';
260-
reloadButton.style.backgroundColor = '#4CAF50';
261-
reloadButton.style.borderRadius = '5px';
262-
reloadButton.style.cursor = 'pointer';
264+
// Apply styles to buttons
265+
applyStyles(copyButton, {...buttonStyles, ...copyButtonStyles});
266+
applyStyles(getHelpButton, {...buttonStyles, ...getHelpButtonStyles});
267+
applyStyles(reloadButton, {...buttonStyles, ...reloadButtonStyles});
263268

264269
// Event listeners for buttons
265270
copyButton.onclick = function() {

0 commit comments

Comments
 (0)