Skip to content

Commit bfb3f70

Browse files
committed
chore: completed implementation of transfer token
1 parent 1355d63 commit bfb3f70

6 files changed

Lines changed: 63 additions & 16 deletions

File tree

src/locales/de.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@
5656
"index.createOpenPad": "Pad öffnen",
5757
"index.settings": "Einstellungen",
5858
"index.receiveSessionTitle": "Sitzung empfangen",
59+
"index.receiveSessionDescription": "Hier kannst du eine Etherpad-Sitzung aus einem anderen Browser oder Gerät empfangen. Bedenke allerdings, dass dadurch deine aktuelle Sitzung, falls vorhanden gelöscht wird.",
60+
"index.code": "Übertragungscode",
5961
"index.transferSessionTitle": "Sitzung übertragen",
6062
"index.transferSession": "1. Sitzung übertragen",
6163
"index.copyLink": "2. Link kopieren",
62-
"index.copyLinkButton": "Übertragungslink kopieren",
63-
"index.copyLinkDescription": "Klicke auf den untenstehenden Button, um den Übertragungslink in deine Zwischenablage zu kopieren.",
64+
"index.copyLinkButton": "Übertragungscode kopieren",
65+
"index.copyLinkDescription": "Klicke auf den untenstehenden Button, um den Übertragungscode in deine Zwischenablage zu kopieren.",
6466
"index.transferToSystem": "3. Sitzung einfügen",
6567
"index.transferToSystemDescription": "Öffne den kopierten Link in dem neuen Browser oder Gerät, um deine aktuelle Etherpad-Sitzung zu übertragen.",
6668
"index.transferSessionNow": "Jetzt übertragen",

src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"index.settings": "Settings",
3838
"index.transferSessionTitle": "Transfer session",
3939
"index.receiveSessionTitle": "Receive session",
40+
"index.receiveSessionDescription": "Here you can receive an Etherpad session from another browser or device. Please note, however, that this will delete your current session, if any.",
4041
"index.transferSession": "1. Transfer session",
4142
"index.transferSessionNow": "Transfer session now",
4243
"index.copyLink": "2. Copy link",

src/node/hooks/express/tokenTransfer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export const expressCreateServer = (hookName:string, {app}:ArgsExpressType) =>
3737
}
3838

3939
const token = await db.get(`${tokenTransferKey}:${id}`)
40+
41+
res.cookie('token', tokenData.token, {path: '/', maxAge: 1000*60*60*24*365});
42+
res.cookie('prefsHttp', tokenData.prefsHttp, {path: '/', maxAge: 1000*60*60*24*365});
4043
res.send(token);
4144
})
4245
}

src/static/js/welcome.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ function handleTransferOfSession() {
4343
copyButton.style.justifyContent = 'center';
4444
copyButton.innerHTML = `${checkmark}`;
4545
copyButton.disabled = true;
46-
47-
48-
// Show the new section
49-
const linkDisplay = document.getElementById('transfer-to-system-section')
50-
if (!linkDisplay) return;
51-
linkDisplay.style.display = 'block';
5246
})
5347
});
5448
}
@@ -63,6 +57,8 @@ const handleSettingsButtonClick = () => {
6357
if (e.target === settingsDialog) {
6458
settingsDialog.close();
6559
settingsDialog.innerHTML = initialSettingsHtml;
60+
handleMenuBarClicked();
61+
handleTransferOfSession();
6662
}
6763
});
6864

@@ -85,6 +81,32 @@ const handleMenuBarClicked = () => {
8581
(sections[index +1] as HTMLElement).style.display = 'block';
8682
});
8783
})
84+
85+
const transferSessionButton = document.getElementById('transferSessionButton')
86+
const codeInputField = document.getElementById('codeInput') as HTMLInputElement
87+
if (transferSessionButton) {
88+
transferSessionButton.addEventListener('click', ()=>{
89+
const code = codeInputField.value
90+
fetch("./tokenTransfer/"+code, {
91+
method: 'GET'
92+
})
93+
.then(res => res.json())
94+
.then(()=>{
95+
window.location.reload()
96+
})
97+
});
98+
}
99+
100+
if (codeInputField) {
101+
codeInputField.addEventListener('input', (e)=>{
102+
if (e.target.value.length === 36) {
103+
transferSessionButton?.removeAttribute('disabled');
104+
} else {
105+
transferSessionButton?.setAttribute('disabled', 'true');
106+
}
107+
})
108+
}
109+
88110
}
89111

90112
window.addEventListener('load', () => {

src/static/skins/colibris/index.css

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ h1 {
102102
border-radius: 5px;
103103
}
104104

105-
#button, #button:hover, #go2Name [type="submit"] {
105+
#button, #button:hover, #go2Name [type="submit"], #transferSessionButton {
106106
order: 2;
107107
margin-top: 0.5rem;
108108
line-height: 1.25rem;
@@ -117,10 +117,14 @@ h1 {
117117
cursor: pointer;
118118
}
119119

120-
#go2Name [type="submit"]:hover {
120+
#go2Name [type="submit"]:hover, #transferSessionButton {
121121
background-color: oklch(52.7% 0.154 150.069)
122122
}
123123

124+
#transferSessionButton:disabled {
125+
opacity: 0.5;
126+
}
127+
124128
#button, #button:hover {
125129
order: 2;
126130
}
@@ -134,7 +138,7 @@ h1 {
134138
}
135139

136140

137-
#go2Name [type="submit"] {
141+
#go2Name [type="submit"], #transferSessionButton {
138142
display: block;
139143
background-color: var(--ep-color);
140144
color: white;
@@ -245,6 +249,16 @@ a, a:visited, a:hover, a:active {
245249
padding: 1.5rem;
246250
}
247251

252+
#codeInput {
253+
height: auto;
254+
position: static;
255+
border: 1px solid var(--muted-border);
256+
border-radius: 0.375rem;
257+
font-size: 1rem;
258+
outline: none;
259+
transition: border 0.2s;
260+
}
261+
248262
@media (max-width: 640px) {
249263
#inner {
250264
max-width: 100%;

src/templates/index.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ <h1>Etherpad</h1>
171171
<button data-l10n-id="index.transferSessionTitle" class="active-btn"></button>
172172
<button data-l10n-id="index.receiveSessionTitle"></button>
173173
</div>
174-
175174
<div>
176175

177176
<!-- Initial link button -->
@@ -185,11 +184,17 @@ <h3 data-l10n-id="index.copyLink"></h3>
185184
<div data-l10n-id="index.copyLinkDescription"></div>
186185
<button type="button" class="btn-secondary" style="margin-top: 20px" data-l10n-id="index.copyLinkButton"></button>
187186
</div>
188-
189-
<div id="transfer-to-system-section" style="display: none; margin-top: 30px;">
190-
<h3 data-l10n-id="index.transferToSystem"></h3>
191-
<div data-l10n-id="index.transferToSystemDescription"></div>
187+
</div>
188+
<div id="transfer-to-system-section" style="display: none; margin-top: 30px;">
189+
<h3 data-l10n-id="index.transferToSystem"></h3>
190+
<div data-l10n-id="index.transferToSystemDescription"></div>
191+
<p data-l10n-id="index.receiveSessionDescription"></p>
192+
<div>
193+
<label for="codeInput" data-l10n-id="index.code"></label>
194+
<input type="text" id="codeInput"/>
192195
</div>
196+
197+
<button data-l10n-id="index.transferSessionTitle" id="transferSessionButton" disabled></button>
193198
</div>
194199

195200
<div>

0 commit comments

Comments
 (0)