Skip to content

Commit 39e8869

Browse files
committed
Move connection indicator to footer
1 parent af6b10c commit 39e8869

5 files changed

Lines changed: 73 additions & 48 deletions

File tree

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<div id="footer-bar">
125125
<button id="btn-mode-editor" class="mode-button active">Editor</button>
126126
<button id="btn-mode-serial" class="mode-button">Serial</button>
127+
<span id="connection-indicator" aria-label="" title="" hidden></span>
127128
<div class="spacer"></div>
128129
<button class="purple-button btn-settings">Settings<i class="fa-solid fa-gear"></i></button>
129130
<button class="purple-button btn-info" disabled>Info<i class="fa-solid fa-info-circle"></i></button>

js/script.js

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const btnInfo = document.querySelector('.btn-info');
6363
const btnSettings = document.querySelector('.btn-settings');
6464
const terminalTitle = document.getElementById('terminal-title');
6565
const serialPlotter = document.getElementById('plotter');
66+
const connectionIndicator = document.getElementById('connection-indicator');
6667

6768
const messageDialog = new MessageModal("message");
6869
const connectionType = new ButtonValueDialog("connection-type");
@@ -122,28 +123,28 @@ function getConnectionIndicatorType() {
122123
return getLastBackend();
123124
}
124125

125-
function getConnectButtonContents(isConnected) {
126-
const action = isConnected ? "Disconnect" : "Connect";
126+
function getConnectButtonState(isConnected) {
127+
return {
128+
label: isConnected ? "Disconnect" : "Connect",
129+
title: isConnected ? "Disconnect" : "Connect",
130+
};
131+
}
132+
133+
function getConnectionIndicatorState(isConnected) {
127134
const connectionType = getConnectionIndicatorType();
128135
const details = CONNECTION_DETAILS[connectionType];
129136

130137
if (!details) {
131-
return {
132-
html: action,
133-
label: action,
134-
title: action,
135-
};
138+
return null;
136139
}
137140

138-
const status = isConnected ? "Connected via" : "Last connection";
139-
const actionLabel = isConnected
140-
? `Disconnect ${details.label}`
141-
: `Connect using ${details.label}`;
141+
const title = isConnected
142+
? `Connected with ${details.label}`
143+
: `Last connection: ${details.label}`;
142144

143145
return {
144-
html: `<span class="connection-indicator" aria-hidden="true"><i class="${details.iconClass}"></i><span class="connection-label">${details.label}</span></span> <span class="connect-action">${action}</span>`,
145-
label: actionLabel,
146-
title: `${status}: ${details.label}`,
146+
iconClass: details.iconClass,
147+
title,
147148
};
148149
}
149150

@@ -777,11 +778,27 @@ async function debugLog(msg) {
777778
}
778779

779780
function updateUIConnected(isConnected) {
780-
const buttonState = getConnectButtonContents(isConnected);
781+
const buttonState = getConnectButtonState(isConnected);
782+
const indicatorState = getConnectionIndicatorState(isConnected);
783+
784+
if (indicatorState) {
785+
connectionIndicator.innerHTML = `<i class="${indicatorState.iconClass}"></i>`;
786+
connectionIndicator.setAttribute("aria-label", indicatorState.title);
787+
connectionIndicator.title = indicatorState.title;
788+
connectionIndicator.hidden = false;
789+
connectionIndicator.classList.toggle("connected", isConnected);
790+
} else {
791+
connectionIndicator.replaceChildren();
792+
connectionIndicator.removeAttribute("aria-label");
793+
connectionIndicator.removeAttribute("title");
794+
connectionIndicator.hidden = true;
795+
connectionIndicator.classList.remove("connected");
796+
}
797+
781798
if (isConnected) {
782799
// Set to Connected State
783800
getConnectButtons().forEach((element) => {
784-
element.innerHTML = buttonState.html;
801+
element.textContent = buttonState.label;
785802
element.setAttribute("aria-label", buttonState.label);
786803
element.title = buttonState.title;
787804
element.disabled = false;
@@ -792,7 +809,7 @@ function updateUIConnected(isConnected) {
792809
} else {
793810
// Set to Disconnected State
794811
getConnectButtons().forEach((element) => {
795-
element.innerHTML = buttonState.html;
812+
element.textContent = buttonState.label;
796813
element.setAttribute("aria-label", buttonState.label);
797814
element.title = buttonState.title;
798815
element.disabled = false;

sass/layout/_header.scss

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,11 @@
109109
margin: 0;
110110
align-items: center;
111111
display: inline-flex;
112-
gap: 8px;
113112
justify-content: center;
114-
min-width: 118px;
115113
}
116114
}
117115
}
118116

119-
.connection-indicator {
120-
align-items: center;
121-
display: inline-flex;
122-
gap: 5px;
123-
white-space: nowrap;
124-
125-
i {
126-
font-size: 16px;
127-
line-height: 1;
128-
}
129-
}
130-
131-
.connection-label {
132-
font-size: 13px;
133-
}
134-
135-
.connect-action {
136-
white-space: nowrap;
137-
}
138-
139117
.site-navigation {
140118
padding: 0 0 10px 0;
141119
font-size: 18px;

sass/layout/_header_mobile.scss

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,7 @@
109109
display: block !important;
110110
}
111111

112-
#mobile-header {
113-
.get-started button {
114-
gap: 6px;
115-
min-width: 94px;
116-
}
117-
118-
.connection-label {
119-
display: none;
120-
}
112+
#mobile-header .get-started button {
113+
min-width: auto;
121114
}
122115
}

sass/layout/_layout.scss

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
height: 4em;
1616
padding: 0 10px;
1717
display: flex;
18+
align-items: center;
1819

1920
.spacer {
2021
flex: auto;
@@ -195,6 +196,41 @@
195196
}
196197
}
197198

199+
#connection-indicator {
200+
align-items: center;
201+
color: $gray;
202+
display: inline-flex;
203+
font-size: 1.15em;
204+
justify-content: center;
205+
line-height: 1;
206+
margin-right: 0.5em;
207+
min-width: 1.75em;
208+
209+
&.connected {
210+
color: $purple;
211+
}
212+
213+
&[hidden] {
214+
display: none;
215+
}
216+
}
217+
218+
@media (max-width: $screen-xs-max) {
219+
.layout #footer-bar {
220+
.purple-button {
221+
font-size: 0;
222+
margin-right: 0.35em;
223+
padding-left: 0.75em;
224+
padding-right: 0.75em;
225+
226+
i {
227+
font-size: 16px;
228+
margin-left: 0;
229+
}
230+
}
231+
}
232+
}
233+
198234
@media (min-width: 650px) {
199235
.popup-modal.file-dialog {
200236
max-height: 365px;

0 commit comments

Comments
 (0)