Skip to content

Commit e19e542

Browse files
committed
refactor: Implement modules for components and states
1 parent ffe7a00 commit e19e542

File tree

5 files changed

+921
-1167
lines changed

5 files changed

+921
-1167
lines changed

src/sportsbet/gui/app/components.py

Lines changed: 110 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Page common components."""
22

33
import reflex as rx
4+
from reflex_ag_grid import ag_grid
45

56
SIDEBAR_OPTIONS = {
6-
'spacing': '1',
7+
'spacing': '0',
78
'position': 'fixed',
89
'left': '50px',
910
'top': '50px',
@@ -17,7 +18,10 @@
1718

1819
def home() -> rx.Component:
1920
"""Home title."""
20-
return rx.text('Sports Betting', size='4', weight='bold')
21+
return rx.vstack(
22+
rx.text('Sports Betting', size='4', weight='bold'),
23+
rx.divider(width='18em'),
24+
)
2125

2226

2327
def title(name: str, icon_name: str) -> rx.Component:
@@ -26,14 +30,14 @@ def title(name: str, icon_name: str) -> rx.Component:
2630
rx.icon(icon_name),
2731
rx.text(name, size="4"),
2832
width="100%",
29-
padding_y="0.75rem",
3033
color=rx.color("accent", 11),
3134
)
3235

3336

34-
def select_mode(state: rx.State, content: str) -> rx.Component:
35-
"""Selection of mode component."""
37+
def mode(state: rx.State, content: str) -> rx.Component:
38+
"""Mode component."""
3639
return rx.vstack(
40+
title('Mode', 'blend'),
3741
rx.text(content, size='1'),
3842
rx.hstack(
3943
rx.select(
@@ -51,22 +55,26 @@ def select_mode(state: rx.State, content: str) -> rx.Component:
5155
on_change=state.set_mode_type,
5256
),
5357
),
58+
margin_top='10px',
5459
)
5560

5661

57-
def control_buttons(state: rx.State, disabled: bool) -> rx.Component:
58-
"""Control buttons of UI."""
62+
def submit_reset(state: rx.State, disabled: bool, url: str | None = None) -> rx.Component:
63+
"""Submit and reset buttons of UI."""
5964
return rx.vstack(
6065
rx.divider(top='600px', position='fixed', width='18em'),
6166
rx.hstack(
62-
rx.button(
63-
'Submit',
64-
on_click=state.submit_state,
65-
disabled=disabled,
66-
loading=state.loading,
67-
position='fixed',
68-
top='620px',
69-
width='70px',
67+
rx.link(
68+
rx.button(
69+
'Submit',
70+
on_click=state.submit_state,
71+
disabled=disabled,
72+
loading=state.loading,
73+
position='fixed',
74+
top='620px',
75+
width='70px',
76+
),
77+
href=url,
7078
),
7179
rx.link(
7280
rx.button(
@@ -81,3 +89,90 @@ def control_buttons(state: rx.State, disabled: bool) -> rx.Component:
8189
),
8290
),
8391
)
92+
93+
94+
def save(state: rx.State, visibility_level: int) -> rx.Component:
95+
"""The save component."""
96+
return rx.cond(
97+
state.visibility_level > visibility_level,
98+
rx.button(
99+
'Save',
100+
position='fixed',
101+
top='620px',
102+
left='275px',
103+
width='70px',
104+
on_click=state.download_dataloader,
105+
),
106+
)
107+
108+
109+
def data(state: rx.State, visibility_level: int) -> rx.Component:
110+
"""Data component of UI."""
111+
return rx.cond(
112+
state.visibility_level == visibility_level,
113+
rx.vstack(
114+
rx.heading(state.data_title),
115+
rx.vstack(
116+
rx.divider(width='900px'),
117+
ag_grid(
118+
id='data',
119+
row_data=state.data,
120+
column_defs=state.data_cols,
121+
height='470px',
122+
width='900px',
123+
theme='balham',
124+
),
125+
rx.divider(width='900px'),
126+
),
127+
rx.hstack(
128+
rx.cond(
129+
state.X_fix,
130+
rx.tooltip(
131+
rx.button(
132+
rx.icon('database'),
133+
on_click=state.switch_displayed_data_category,
134+
variant='surface',
135+
loading=state.loading_db,
136+
),
137+
content='Switch between training or fixtures data',
138+
),
139+
rx.tooltip(
140+
rx.button(rx.icon('database'), variant='surface', disabled=True),
141+
content='Fixtures are not currently available',
142+
),
143+
),
144+
rx.tooltip(
145+
rx.button(
146+
rx.icon('arrow-up-down'),
147+
on_click=state.switch_displayed_data_type,
148+
variant='surface',
149+
loading=state.loading_db,
150+
),
151+
content='Switch between input, output or odds data',
152+
),
153+
margin_top='10px',
154+
),
155+
position='fixed',
156+
left='400px',
157+
top='60px',
158+
),
159+
)
160+
161+
162+
def bot(state: rx.State, visibility_level: int) -> rx.Component:
163+
"""The bot component."""
164+
return rx.cond(
165+
state.visibility_level < visibility_level,
166+
rx.box(
167+
rx.vstack(
168+
rx.icon('bot-message-square', size=70),
169+
rx.html(state.streamed_message),
170+
),
171+
position='fixed',
172+
left='600px',
173+
top='100px',
174+
width='500px',
175+
background_color=rx.color('gray', 3),
176+
padding='30px',
177+
),
178+
)

0 commit comments

Comments
 (0)