-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathShowProgressMainButton.jsx
47 lines (42 loc) · 1.89 KB
/
ShowProgressMainButton.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React from 'react';
import TelegramDetailedButton from "../../kit/DetailedButton/TelegramDetailedButton";
import {useTelegram} from "../../../hooks/useTelegram";
import TelegramMiniForm from "../../kit/MiniForm/TelegramMiniForm";
import TelegramMiniFormWithOptions from "../../kit/MiniFormWithOptions/TelegramMiniFormWithOptions";
import TelegramOptionsForm from "../../kit/OptionsForm/TelegramOptionsForm";
/**
* MainButton.showProgress(leaveActive) is a method to show a loading indicator on the button.
* It is recommended to display loading progress if the action tied to the button may take a long time.
*
* By default, the button is disabled while the action is in progress.
* If the parameter leaveActive=true is passed, the button remains enabled.
*
* @see https://core.telegram.org/bots/webapps#mainbutton
*/
const ShowProgressMainButton = () => {
const {webApp, executeMethod} = useTelegram()
const onShowProgress = (options) => {
const leaveActive= options[0] === 'true'
executeMethod(
'MainButton.showProgress',
() => webApp.MainButton.showProgress(leaveActive),
true
)
}
const options = ['true', 'false']
return (
<TelegramOptionsForm
formlabel={'MainButton.showProgress(leaveActive)'}
formdescription={
'A method to show a loading indicator on the button.' +
'It is recommended to display loading progress if the action tied to the button may take a long time. By default, the button is disabled while the action is in progress. If the parameter leaveActive=true is passed, the button remains enabled.'
}
optionsmultiple={false}
optionslabel={'leaveActive'}
options={options}
buttonlabel={'Execute'}
onSubmit={onShowProgress}
/>
);
};
export default ShowProgressMainButton;