@@ -12,6 +12,7 @@ pub fn configuration_page() -> Html {
1212 let ( i18n, _set_language) = use_translation ( ) ;
1313
1414 let bot_status = use_state ( || "running" . to_string ( ) ) ;
15+ let presence_status = use_state ( || "online" . to_string ( ) ) ;
1516 let is_loading = use_state ( || false ) ;
1617 let config = use_state ( || None :: < ConfigResponse > ) ;
1718 let config_loading = use_state ( || true ) ;
@@ -52,6 +53,7 @@ pub fn configuration_page() -> Html {
5253
5354 {
5455 let bot_status = bot_status. clone ( ) ;
56+ let presence_status = presence_status. clone ( ) ;
5557 let is_loading = is_loading. clone ( ) ;
5658
5759 use_effect_with ( ( ) , move |_| {
@@ -63,6 +65,9 @@ pub fn configuration_page() -> Html {
6365 if let Some ( status) = json[ "status" ] . as_str ( ) {
6466 bot_status. set ( status. to_string ( ) ) ;
6567 }
68+ if let Some ( presence) = json[ "presence" ] . as_str ( ) {
69+ presence_status. set ( presence. to_string ( ) ) ;
70+ }
6671 }
6772 }
6873 }
@@ -117,6 +122,30 @@ pub fn configuration_page() -> Html {
117122 } )
118123 } ;
119124
125+ let handle_presence_change = {
126+ let presence_status = presence_status. clone ( ) ;
127+ let is_loading = is_loading. clone ( ) ;
128+
129+ Callback :: from ( move |new_presence : String | {
130+ let presence_status = presence_status. clone ( ) ;
131+ let is_loading = is_loading. clone ( ) ;
132+
133+ spawn_local ( async move {
134+ is_loading. set ( true ) ;
135+ if let Ok ( req) = Request :: post ( "/api/bot/presence" )
136+ . json ( & serde_json:: json!( { "status" : new_presence} ) )
137+ {
138+ if let Ok ( resp) = req. send ( ) . await {
139+ if resp. ok ( ) {
140+ presence_status. set ( new_presence) ;
141+ }
142+ }
143+ }
144+ is_loading. set ( false ) ;
145+ } ) ;
146+ } )
147+ } ;
148+
120149 let handle_save = {
121150 let show_restart_modal = show_restart_modal. clone ( ) ;
122151 let save_message = save_message. clone ( ) ;
@@ -212,7 +241,7 @@ pub fn configuration_page() -> Html {
212241 </div>
213242 </div>
214243
215- <div class="flex flex-wrap gap-3" >
244+ <div class="flex flex-wrap gap-3 mb-4 " >
216245 <button
217246 onclick={ {
218247 let handle_bot_action = handle_bot_action. clone( ) ;
@@ -256,6 +285,41 @@ pub fn configuration_page() -> Html {
256285 { i18n. t( "panel.configuration.restart_bot" ) }
257286 </button>
258287 </div>
288+
289+ <div class="border-t border-slate-600 pt-4" >
290+ <label class="block text-sm text-gray-300 mb-2" >{ i18n. t( "panel.configuration.presence_status" ) } </label>
291+ <div class="flex items-center gap-3" >
292+ <select
293+ value={ ( * presence_status) . clone( ) }
294+ disabled={ * is_loading || * bot_status == "stopped" }
295+ onchange={ {
296+ let handle_presence_change = handle_presence_change. clone( ) ;
297+ move |e: Event | {
298+ if let Some ( select) = e. target_dyn_into:: <web_sys:: HtmlSelectElement >( ) {
299+ handle_presence_change. emit( select. value( ) ) ;
300+ }
301+ }
302+ } }
303+ class="px-4 py-2 bg-slate-900/50 border border-slate-600 rounded-md text-white focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed"
304+ >
305+ <option value="online" selected={ * presence_status == "online" } >{ i18n. t( "panel.configuration.presence.online" ) } </option>
306+ <option value="idle" selected={ * presence_status == "idle" } >{ i18n. t( "panel.configuration.presence.idle" ) } </option>
307+ <option value="dnd" selected={ * presence_status == "dnd" } >{ i18n. t( "panel.configuration.presence.dnd" ) } </option>
308+ <option value="invisible" selected={ * presence_status == "invisible" } >{ i18n. t( "panel.configuration.presence.invisible" ) } </option>
309+ <option value="maintenance" selected={ * presence_status == "maintenance" } >{ i18n. t( "panel.configuration.presence.maintenance" ) } </option>
310+ </select>
311+ <div class={ classes!(
312+ "w-3" , "h-3" , "rounded-full" ,
313+ match ( * presence_status) . as_str( ) {
314+ "online" => "bg-green-500" ,
315+ "idle" => "bg-yellow-500" ,
316+ "dnd" | "maintenance" => "bg-red-500" ,
317+ "invisible" => "bg-gray-500" ,
318+ _ => "bg-green-500"
319+ }
320+ ) } ></div>
321+ </div>
322+ </div>
259323 </div>
260324
261325 <div class="bg-slate-800/50 border border-slate-700 rounded-lg p-6" >
0 commit comments