Skip to content

Commit b112fed

Browse files
committed
Editor improvements
1 parent 7b0105e commit b112fed

File tree

1 file changed

+56
-8
lines changed

1 file changed

+56
-8
lines changed

editor.html

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,25 @@
1010
box-sizing: border-box;
1111
}
1212

13+
html {
14+
display: flex;
15+
align-content: center;
16+
justify-content: center;
17+
height: 100%;
18+
}
19+
1320
body {
1421
margin: 0;
1522
font-family: Arial, sans-serif;
1623
display: flex;
17-
justify-content: center;
18-
align-items: center;
19-
height: 100vh;
24+
width: 100%;
2025
background-color: #f0f0f0;
2126
}
2227

2328
.start-screen {
2429
text-align: center;
30+
margin: auto;
31+
padding: 10px;
2532
}
2633

2734
h1 {
@@ -506,6 +513,13 @@
506513
button .icon:last-child {
507514
margin: 0;
508515
}
516+
517+
@media (max-width: 630px) {
518+
.section-edit-panel, .section-add-panel-row, .item-edit-panel, .item-add-panel {
519+
flex-direction: column;
520+
align-items: flex-start;
521+
}
522+
}
509523
</style>
510524
<style id="dynamicStyles"></style>
511525
<title>Limits Editor</title>
@@ -921,7 +935,7 @@ <h1>Telegram Limits Editor</h1>
921935
static noFsMode = false;
922936

923937
static async openHelp(source) {
924-
alert("We're already working on documentation. Until then, for guidance, please contact contributors directly.");
938+
alert("We're already working on documentation. Until then, for guidance, please contact @infowritebot");
925939
}
926940

927941
static async suggestEdit() {
@@ -1000,11 +1014,14 @@ <h1>Telegram Limits Editor</h1>
10001014
}
10011015
}
10021016

1017+
const commitSha = this.latestCommitJson ? this.latestCommitJson.sha : undefined;
1018+
10031019
const data = {
10041020
structure: this.structure,
10051021
localization: this.localization,
10061022
description: desc,
10071023
contact: dialog.querySelector('#contact').value,
1024+
baseCommitSha: commitSha,
10081025
};
10091026

10101027
const response = await fetch(url, {
@@ -1111,7 +1128,7 @@ <h1>Telegram Limits Editor</h1>
11111128
button.textContent = 'Downloading...';
11121129

11131130
try {
1114-
const { structureBlob, localizationBlob, iconBlob, iconCodePointsBlob } = await this.downloadBlobs('master');
1131+
const { structureBlob, localizationBlob, iconBlob, iconCodePointsBlob, latestCommitsJson } = await this.downloadBlobs('master');
11151132

11161133
const structureText = await structureBlob.text();
11171134
const localizationText = await localizationBlob.text();
@@ -1122,8 +1139,10 @@ <h1>Telegram Limits Editor</h1>
11221139
const iconObjectUrl = URL.createObjectURL(iconBlob);
11231140
const iconCodePointsMap = WorkDirHandle.parseIconCodePoints(iconCodePointsText);
11241141

1142+
let latestCommitJson = latestCommitsJson ? latestCommitsJson[0] : null;
1143+
11251144
this.noFsMode = true;
1126-
this.applyData({ structure, localization, iconCodePointsMap, iconObjectUrl });
1145+
this.applyData({ structure, localization, iconCodePointsMap, iconObjectUrl, latestCommitJson });
11271146
} catch (e) {
11281147
console.error(e);
11291148
alert('An error occurred while starting: ' + e.message);
@@ -1134,23 +1153,27 @@ <h1>Telegram Limits Editor</h1>
11341153
}
11351154

11361155
static async downloadBlobs(branchName) {
1137-
const urlPrefix = 'https://raw.githubusercontent.com/tginfo/Telegram-Limits/' + branchName;
1156+
const repo = 'tginfo/Telegram-Limits';
1157+
const urlPrefix = `https://raw.githubusercontent.com/${repo}/` + branchName;
11381158
const structureUrl = `${urlPrefix}/data/structure.json`;
11391159
const localizationUrl = `${urlPrefix}/localization/en/data.json`;
11401160
const iconUrl = `${urlPrefix}/assets/images/icons.woff2`;
11411161
const iconCodePointsUrl = `${urlPrefix}/assets/images/icons.codepoints`;
1162+
const latestCommitsUrl = `https://api.github.com/repos/${repo}/commits?sha=${branchName}&per_page=1`;
11421163

11431164
const structureResponse = await fetch(structureUrl);
11441165
const localizationResponse = await fetch(localizationUrl);
11451166
const iconResponse = await fetch(iconUrl);
11461167
const iconCodePointsResponse = await fetch(iconCodePointsUrl);
1168+
const latestCommitsResponse = await fetch(latestCommitsUrl);
11471169

11481170
const structureBlob = await structureResponse.blob();
11491171
const localizationBlob = await localizationResponse.blob();
11501172
const iconBlob = await iconResponse.blob();
11511173
const iconCodePointsBlob = await iconCodePointsResponse.blob();
1174+
const latestCommitsJson = await latestCommitsResponse.json();
11521175

1153-
return { structureBlob, localizationBlob, iconBlob, iconCodePointsBlob };
1176+
return { structureBlob, localizationBlob, iconBlob, iconCodePointsBlob, latestCommitsJson };
11541177
}
11551178

11561179
static async downloadFiles() {
@@ -1224,6 +1247,7 @@ <h1>Telegram Limits Editor</h1>
12241247
this.localization = data.localization;
12251248
this.iconCodePointsMap = data.iconCodePointsMap;
12261249
this.iconObjectUrl = data.iconObjectUrl;
1250+
this.latestCommitJson = data.latestCommitJson;
12271251

12281252
this.editor = new LimitsEditor(this.structure, this.localization, this.iconCodePointsMap);
12291253

@@ -1391,6 +1415,18 @@ <h1>Telegram Limits Editor</h1>
13911415
sectionDragHandle.textContent = 'drag_indicator';
13921416
sectionDragHandle.title = 'Drag to reorder';
13931417
sectionElement.appendChild(sectionDragHandle);
1418+
1419+
sectionDragHandle.addEventListener('touchstart', (e) => {
1420+
const touchTime = performance.now();
1421+
1422+
sectionDragHandle.addEventListener('touchend', (e) => {
1423+
const touchDuration = performance.now() - touchTime;
1424+
if (touchDuration < 300) {
1425+
alert('Sorry, only mouse pointer can be used to rearrange sections');
1426+
}
1427+
}, { once: true });
1428+
});
1429+
13941430
sectionDragHandle.addEventListener('mousedown', (e) => {
13951431
sectionElement.draggable = true;
13961432

@@ -1759,6 +1795,18 @@ <h1>Telegram Limits Editor</h1>
17591795
itemDragHandle.textContent = 'drag_indicator';
17601796
itemDragHandle.title = 'Drag to reorder';
17611797
itemElement.appendChild(itemDragHandle);
1798+
1799+
itemDragHandle.addEventListener('touchstart', (e) => {
1800+
const touchTime = performance.now();
1801+
1802+
itemDragHandle.addEventListener('touchend', (e) => {
1803+
const touchDuration = performance.now() - touchTime;
1804+
if (touchDuration < 300) {
1805+
alert("Sorry, only mouse pointer can be used to move items")
1806+
}
1807+
}, { once: true });
1808+
});
1809+
17621810
itemDragHandle.addEventListener('mousedown', (e) => {
17631811
itemElement.draggable = true;
17641812

0 commit comments

Comments
 (0)