Skip to content

Commit 3bf9666

Browse files
committed
Refactor UI: Add margin to play, stop, and copy buttons
1 parent db1f047 commit 3bf9666

File tree

6 files changed

+70
-5
lines changed

6 files changed

+70
-5
lines changed

src/assets/scss/main.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,29 @@ body {
7474
.play {
7575
font-size: 20px;
7676
cursor: pointer;
77+
margin-left: .5rem;
78+
margin-right: .5rem;
7779
}
7880

7981
.stop {
8082
font-size: 20px;
8183
cursor: pointer;
84+
margin-left: .5rem;
85+
margin-right: .5rem;
86+
}
87+
88+
.copy {
89+
font-size: 20px;
90+
cursor: pointer;
91+
margin-left: .5rem;
92+
margin-right: .5rem;
93+
&-clicked {
94+
color: #ff9d00;
95+
}
96+
}
97+
98+
.url-prefix{
99+
cursor: pointer;
82100
}
83101

84102
.port {

src/assets/styles/main.css

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/assets/styles/main.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/views/edit.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ function saveMock() {
6060
jsonUpdated = window.editor.get();
6161
const recoveryData = addHideFields(jsonUpdated);
6262
console.log('jsonUpdated', recoveryData);
63-
debugger;
6463
ipcRenderer.send('saveMock', recoveryData);
6564
}
6665
ipcRenderer.on('responseSaveMock', (event, data) => {

src/views/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ <h1>Mockingbird Proxy</h1>
3131
<!-- <input id="path" class="path" type="text" value="/Users/davidesalvato/Downloads/mockbird"> -->
3232
<span class="led"></span>
3333
<input id="port" class="port" type="text" value="">
34-
<i id="stop" class="stop bi bi-stop-fill d-none" onclick="stopServer()"></i>
35-
<i id="play" class="play bi bi-play-fill" onclick="startServer()"></i>
34+
<i id="stop" class="ml-5 stop bi bi-stop-fill d-none" onclick="stopServer()"></i>
35+
<i id="play" class="ml-5 play bi bi-play-fill" onclick="startServer()"></i>
3636
<p id="config"></p>
37+
<i id="copy" class="copy bi bi-clipboard" onclick="copyPrefixUrl()"></i>
3738
</div>
3839
<div class="col-lg-12 col-xl-4 d-flex my-sm-2 justify-content-xl-end align-items-center">
3940
<div>

src/views/index.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const fs = require('fs');
22
const path = require('path');
33
const { ipcRenderer } = require('electron');
44

5+
let prefixUrl = '';
6+
57
window.addEventListener('load', () => {
68
ipcRenderer.send('checkServerRunning');
79
ipcRenderer.send('getConfig');
@@ -83,7 +85,20 @@ function startServer() {
8385
ipcRenderer.send('startServer', port);
8486
}
8587
function changeUiToServerStart(){
86-
document.querySelector('#config').innerHTML = 'http://localhost:' + document.querySelector('#port').value + '/https://your-real-api-url.com/api/v1/...';
88+
prefixUrl = 'http://localhost:' + document.querySelector('#port').value + '/';
89+
// create element span
90+
document.querySelector('#config').innerHTML = '';
91+
const span = document.createElement('span');
92+
span.className = 'url-prefix';
93+
span.textContent = prefixUrl;
94+
span.onclick = () => copyPrefixUrl();
95+
document.querySelector('#config').appendChild(span);
96+
const spanExample = document.createElement('span');
97+
spanExample.className = 'url-prefix-example';
98+
spanExample.textContent = 'https://your-real-api-url.com/api/v1/...';
99+
document.querySelector('#config').appendChild(spanExample);
100+
101+
// document.querySelector('#config').innerHTML = prefixUrl + 'https://your-real-api-url.com/api/v1/...';
87102
document.querySelector('#port').disabled = true;
88103
// document.querySelector('#path').disabled = true;
89104
document.querySelector('#stop').classList.remove('d-none');
@@ -96,6 +111,22 @@ ipcRenderer.on('responseStartServer', (event, port) => {
96111
console.log('responseStartServer', port);
97112
});
98113

114+
async function copyPrefixUrl() {
115+
// add effect to button on click
116+
document.querySelector('#config .url-prefix').classList.add('copy-clicked');
117+
document.querySelector('#copy').classList.add('copy-clicked');
118+
setTimeout(() => {
119+
document.querySelector('#config .url-prefix').classList.remove('copy-clicked');
120+
document.querySelector('#copy').classList.remove('copy-clicked');
121+
}, 500);
122+
try {
123+
await navigator.clipboard.writeText(prefixUrl);
124+
}
125+
catch (err) {
126+
console.error('Failed to copy: ', err);
127+
}
128+
}
129+
99130
function stopServer() {
100131
ipcRenderer.send('stopServer');
101132
}

0 commit comments

Comments
 (0)