Skip to content

Commit 1e055bb

Browse files
committed
add file uploading toast in file pin widget
1 parent 44839d0 commit 1e055bb

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

webiojs/src/handlers/pin.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {CommandHandler} from "./base";
33
import {GetPinValue, PinChangeCallback, PinUpdate, WaitChange, IsFileInput} from "../models/pin";
44
import {state} from "../state";
55
import {serialize_file, serialize_json} from "../utils";
6+
import {t} from "../i18n";
67

78

89
export class PinHandler implements CommandHandler {
@@ -58,12 +59,26 @@ export class PinHandler implements CommandHandler {
5859
// msg.data.value: {multiple: bool, files: File[]}
5960
let {multiple, files} = msg.data.value;
6061
msg.data.value = multiple ? [] : null; // replace file value with initial value
62+
63+
let toast = Toastify({
64+
text: `⏳${t("file_uploading")} 0%`,
65+
duration: -1,
66+
gravity: "top",
67+
position: 'center',
68+
backgroundColor: '#1565c0',
69+
});
70+
if (files.length > 0) toast.showToast();
6171
state.CurrentSession.send_buffer(
6272
new Blob([
6373
serialize_json(msg),
6474
...files.map((file: File) => serialize_file(file, 'value'))
65-
], {type: 'application/octet-stream'})
75+
], {type: 'application/octet-stream'}),
76+
(loaded: number, total: number) => {
77+
toast.toastElement.innerText = `⏳${t("file_uploading")} ${(loaded / total).toFixed(2)}%`;
78+
if (total - loaded < 100) toast.hideToast();
79+
}
6680
);
81+
6782
} else {
6883
state.CurrentSession.send_message(msg);
6984
}

webiojs/src/i18n.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const translations: { [lang: string]: { [msgid: string]: string } } = {
1818
"duplicated_pin_name": "This pin widget has expired (due to the output of a new pin widget with the same name).",
1919
"browse_file": "Browse",
2020
"duplicated_scope_name": "Error: The name of this scope is duplicated with the previous one!",
21+
"file_uploading": "File Uploading...",
2122
},
2223
"zh": {
2324
"disconnected_with_server": "与服务器连接已断开,请刷新页面重新操作",
@@ -31,6 +32,7 @@ const translations: { [lang: string]: { [msgid: string]: string } } = {
3132
"duplicated_pin_name": "该 Pin widget 已失效(由于输出了新的同名 pin widget)",
3233
"browse_file": "浏览文件",
3334
"duplicated_scope_name": "错误: 此scope与已有scope重复!",
35+
"file_uploading": "文件上传中",
3436
},
3537
"ru": {
3638
"disconnected_with_server": "Соединение с сервером потеряно, пожалуйста перезагрузите страницу",
@@ -43,6 +45,7 @@ const translations: { [lang: string]: { [msgid: string]: string } } = {
4345
"cancel": "Отмена",
4446
"duplicated_pin_name": "Этот закреп виджет устарел (виджет с таким же именем был выведен).",
4547
"browse_file": "Обзор",
48+
4649
},
4750
"de": {
4851
"disconnected_with_server": "Verbindung zum Server unterbrochen. Bitte laden Sie die Seite neu.",
@@ -94,7 +97,7 @@ function strfmt(fmt: string) {
9497
let args = arguments;
9598

9699
return fmt
97-
// put space after double % to prevent placeholder replacement of such matches
100+
// put space after double % to prevent placeholder replacement of such matches
98101
.replace(/%%/g, '%% ')
99102
// replace placeholders
100103
.replace(/%(\d+)/g, function (str, p1) {
@@ -104,10 +107,10 @@ function strfmt(fmt: string) {
104107
.replace(/%% /g, '%')
105108
}
106109

107-
export function t(msgid: string, ...args:string[]): string {
110+
export function t(msgid: string, ...args: string[]): string {
108111
let fmt = null;
109112
for (let lang of ['custom', userLangCode, langPrefix, 'en']) {
110-
if (translations[lang] && translations[lang][msgid]){
113+
if (translations[lang] && translations[lang][msgid]) {
111114
fmt = translations[lang][msgid];
112115
break;
113116
}

0 commit comments

Comments
 (0)