Skip to content

Commit 916fbdf

Browse files
committed
get an early UI
1 parent 975e8a1 commit 916fbdf

6 files changed

Lines changed: 77 additions & 93 deletions

File tree

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<!-- <script src="./main.mjs" type="module"></script> -->
1717
<div class="app"></div>
1818
<script
19-
src="./target/js/debug/build/main/main.js"
19+
src="./target/js/debug/build/app.js"
2020
type="module"
2121
defer
2222
></script>

src/container.mbt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
///|
2+
typealias @respo_node.(RespoEvent, RespoNode, DispatchFn, RespoCommonError)
3+
4+
///|
5+
fnalias @respo_node.(text_node, textarea, declare_static_style)
6+
7+
///|
8+
fnalias @respo.ui_textarea
9+
10+
///|
11+
struct ContainerState {
12+
draft : String
13+
} derive(Default, ToJson, @json.FromJson)
14+
15+
///|
16+
fn comp_container(states : @respo.RespoStatesTree) -> RespoNode[ActionOp] {
17+
let cursor = states.path()
18+
let state = (states.cast_branch() : ContainerState)
19+
div([
20+
div([
21+
textarea(
22+
class_list=[ui_textarea, style_textbox],
23+
placeholder="Question",
24+
value=state.draft,
25+
event=Map::of([
26+
(
27+
Input,
28+
fn(e, dispatch) {
29+
if e is Input(value~, ..) {
30+
dispatch.set_state!(cursor, ContainerState::{ draft: value })
31+
}
32+
},
33+
),
34+
(
35+
Keydown,
36+
fn(e, dispatch) {
37+
if e is Keyboard(key_code~, meta_key~, ..) {
38+
if key_code == 13 && meta_key {
39+
ask_gemini(state.draft)
40+
}
41+
}
42+
},
43+
),
44+
]),
45+
),
46+
button(
47+
inner_text="Ask",
48+
class_name=ui_button,
49+
style=respo_style(margin=4 |> Px),
50+
event={}..set(Click, fn(e, dispatch) { ask_gemini(state.draft) }),
51+
),
52+
]),
53+
])
54+
}
55+
56+
///|
57+
let style_textbox : String = declare_static_style([
58+
("&", respo_style(width=600 |> Px, height=160 |> Px)),
59+
])

src/control.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async function live(client: GoogleGenAI, model: string) {
143143
// await handleTurn();
144144
// console.log("-".repeat(80));
145145

146-
(window as any).ask = async (s: string) => {
146+
(window as any).ask_gemini = async (s: string) => {
147147
if (cacheOfSession) {
148148
cacheOfSession.sendClientContent({ turns: s });
149149
// await handleTurn();

src/counter.mbt

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/main.mbt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ fnalias @respo_node.(div, span, button, respo_style)
77
///|
88
let app_store_key : String = "mbt-workflow"
99

10+
///|
11+
extern "js" fn register_gemini_ask() -> Unit =
12+
#| () => {};
13+
#| import "/src/control.mjs";
14+
15+
///|
16+
extern "js" fn ask_gemini(msg : String) -> Unit =
17+
#| (msg) => { window.ask_gemini(msg); };
18+
1019
///|
1120
fn view(
1221
store : Store
@@ -17,12 +26,13 @@ fn view(
1726
// @dom_ffi.log("Store to render: " + store.to_json().stringify(indent=2))
1827
let states = store.get_states()
1928
div(class_name=ui_global, style=respo_style(padding=Px(12)), [
20-
comp_counter(states.pick("counter"), store.counted),
29+
comp_container(states.pick("container")),
2130
])
2231
}
2332

2433
///|
2534
fn main {
35+
register_gemini_ask()
2636
let window = @dom_ffi.window()
2737
let mount_target = window
2838
.document()
@@ -36,7 +46,11 @@ fn main {
3646
app.backup_model_beforeunload()
3747
// @dom_ffi.log("store: " + app.store.val.to_json().stringify(indent=2))
3848
app.render_loop(fn() { view!(app.store.val) }, fn(op) {
39-
@dom_ffi.log("Action: " + op.to_string())
49+
if op is StatesChange(_) {
50+
51+
} else {
52+
@dom_ffi.log("op: \{op}")
53+
}
4054
app.store.val.update(op)
4155
})
4256
let dev_mode = @dom_ffi.new_url_search_params(window.location().search()).get(

src/player.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ let loopPlay = () => {
3030

3131
export let loadAudio = (audioStr: string) => {
3232
audioBlobQueue.push(audioStr);
33-
console.log("load one", audioBlobQueue.length);
3433
if (!isPlaying) {
3534
if (audioBlobQueue.length > 8) {
3635
loopPlay();

0 commit comments

Comments
 (0)