12
12
< link rel ="stylesheet " href ="styles.css?v=oq5lin ">
13
13
</ head >
14
14
15
- < body
16
- x-data ="{
15
+ < body x-data ="{
17
16
selected_example: 'empty.ts',
18
17
botUpdates: [],
19
18
botState: {
20
19
name: 'nameless',
21
20
status: 'idle',
22
21
token: ''
23
22
}
24
- } "
25
- x-init ="
26
- await playground.start();
27
- playground.onCodeChange(() => {
28
- playground.runBot(botState);
29
- });
30
- playground.worker.onmessage = (e) => {
31
- console.log('got message from worker', e?.data);
32
- if (!e?.data) return;
33
- if (e.data.botState) {
34
- Object.assign(botState, e.data.botState)
35
- }
36
- botUpdates.push(e.data);
37
- console.log('Scrolling', $refs.updates.scrollHeight);
38
- $nextTick(() => { $refs.updates.scrollTop = $refs.updates.scrollHeight })
39
- };
40
- "
41
- >
23
+ } ">
42
24
43
25
< h1 > Telegram Bot Playground 🤖 </ h1 >
44
26
45
27
< div style ="display: flex; gap: 20px; justify-content: center; ">
46
-
28
+
47
29
< label >
48
30
Bot token
49
- < input
50
- type ="text "
51
- x-model ="botState.token "
52
- placeholder ="your token "
53
- @input.debounce.500ms ="playground.checkToken(botState) "
54
- >
31
+ < input type ="text " x-model ="botState.token " placeholder ="your token "
32
+ @input.debounce.500ms ="playground.checkToken(botState) ">
55
33
</ label >
56
34
57
35
< label > Bot name: < span x-text ="botState.name "> </ span > </ label >
@@ -62,33 +40,43 @@ <h1>Telegram Bot Playground 🤖 </h1>
62
40
< div style ="display: flex; align-items: start; ">
63
41
< label >
64
42
Select example
65
- < select
66
-
67
- x-model ="selected_example "
68
- @change ="playground.loadExample(selected_example) "
69
- >
70
- < option value ="empty.ts "> Empty</ option >
71
- < option value ="command.ts "> Command Bot</ option >
72
- < option value ="file.ts "> File Bot</ option >
73
- </ select >
43
+ < select x-model ="selected_example " @change ="playground.loadExample(selected_example) ">
44
+ < option value ="empty.ts "> Empty</ option >
45
+ < option value ="command.ts "> Command Bot</ option >
46
+ < option value ="file.ts "> File Bot</ option >
47
+ </ select >
74
48
</ label >
75
49
76
50
</ div >
77
51
78
52
< div class ="flex-container ">
79
53
< div id ="container " x-cloak > </ div >
80
- < div
81
- id ="worker-updates "
82
- x-ref ="updates "
83
- >
84
- < template
85
- x-for ="update in botUpdates " :key ="update.id "
86
- >
54
+ < div id ="worker-updates " x-ref ="updates ">
55
+ < template x-for ="update in botUpdates " :key ="update.id ">
87
56
< div x-text ="JSON.stringify(update, undefined, 2) "> </ div >
88
57
</ template >
89
58
</ div >
90
59
</ div >
91
60
61
+ < script >
62
+ document . addEventListener ( 'alpine:initialized' , async ( ) => {
63
+ await playground . start ( ) ;
64
+ playground . onCodeChange ( ( ) => {
65
+ playground . runBot ( botState ) ;
66
+ } ) ;
67
+ playground . worker . onmessage = ( e ) => {
68
+ console . log ( 'got message from worker' , e ?. data ) ;
69
+ if ( ! e ?. data ) return ;
70
+ if ( e . data . botState ) {
71
+ Object . assign ( botState , e . data . botState )
72
+ }
73
+ botUpdates . push ( e . data ) ;
74
+ console . log ( 'Scrolling' , $refs . updates . scrollHeight ) ;
75
+ $nextTick ( ( ) => { $refs . updates . scrollTop = $refs . updates . scrollHeight } )
76
+ } ;
77
+ } )
78
+ </ script >
79
+
92
80
</ body >
93
81
94
82
</ html >
0 commit comments