Files
VoelinClient/crates/voelin-gpui/src/shell/main_panel.rs
T
faumarayandClaude Sonnet 5.5 b1f673fce3 voelin-gpui: the channel tree, with a password prompt and what it remembers
Slice 2, first half: the sidebar's placeholder becomes the selected
server's channel tree from voelin-ui-vm's rows (tree_view): nested
channels with their spacers, icons, banners, lock and counts, and the
people in them with their avatar, badges and marks. A TreeModel entity
builds the rows once for both panes on the tree, toolbar and member-card
signals and tells what differs (list::diff, the row operations the Slint
front end applies to its VecModel); ChannelTree is a cached pane over a
virtual list that applies them, so a person who joins is a row inserted
and the scroll stays. The rows carry no `talking`: a talker redraws the
members panel, not the tree (docs/ui.md says so).

A click selects a channel, a double-click joins it (sequence::join_channel:
the move, the prompt for a locked channel's password, a connect into it
without voice), the chevron folds it, a right-click offers Join, fold and
Edit channel (logged: the channel editor is another slice), a click on a
person is logged (their volume dialog is another slice). The password
prompt (Update::password) is a card over the window, asking again when the
server refuses the password. The folds and the selection are kept per
server in ui.tree and found again by the next run.

The shell's cached panes lay out their root at the size the place gives
them (size_full), which the main area needed.

Tests: the sample server's rows, folding and its settings, the round trip
through a closed run, double-click and action join, the password prompt
and its refusal, a move (the exact row operations) and a mute (one row),
a talker leaves the tree alone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-27 23:56:39 +03:00

221 lines
6.2 KiB
Rust

//! The main area. Until the voice page, the chat and the rest come, it is the
//! empty page: the "no server selected" state with the way to add one, and for
//! a server on screen its name, address and state with the buttons that
//! connect, disconnect and edit it. An entity of its own, drawn as a cached
//! pane: it listens to the servers' signal and tells the window only when
//! what it shows changed.
use gpui_kit::component::button::{Button, ButtonVariants as _};
use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::{
Context, Entity, FontWeight, InteractiveElement as _, IntoElement, ParentElement as _, Render,
Styled as _, Subscription, Window, div, px,
};
use voelin_ui_vm::bridge::ServerItem;
use voelin_ui_vm::servers::logic;
use super::actions::{AddServer, ConnectVoice, DisconnectVoice, EditServer};
use super::widgets::{Avatar, Presence, icon, panel, tagged};
use crate::app::AppState;
use crate::meter::Counters;
use crate::signals::Area;
use crate::theme::{VoelinTheme, hsla};
/// What the main area shows.
#[derive(Clone, Debug, PartialEq)]
pub enum MainState {
/// No server is on screen.
NoServer,
/// A server is.
Server(ServerItem),
}
impl MainState {
/// The main area for the state.
pub fn of(app: &AppState) -> Self {
let current = app.vm.current;
logic::rail(&app.vm, |bookmark| app.server_icon(bookmark))
.into_iter()
.find(|item| Some(i64::from(item.id)) == current)
.map_or(Self::NoServer, Self::Server)
}
}
/// The words for a server's state.
fn state_words(status: &str) -> &'static str {
match status {
"connected" => "Connected with voice",
"connecting" => "Connecting…",
"observing" => "Observed without joining",
_ => "Not connected",
}
}
/// The main area.
pub struct MainPanel {
state: MainState,
counters: Counters,
_subscriptions: Vec<Subscription>,
}
impl MainPanel {
/// A main area that follows the server on screen in `app`.
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
let (state, counters, signals) = {
let shown = app.read(cx);
(MainState::of(shown), shown.counters().clone(), shown.signals().clone())
};
let subscriptions = signals.watch(app, &[Area::Servers], cx, |this: &mut Self, app, cx| {
let state = MainState::of(app.read(cx));
if state != this.state {
this.state = state;
cx.notify();
}
});
Self { state, counters, _subscriptions: subscriptions }
}
/// What it shows now.
pub fn state(&self) -> &MainState {
&self.state
}
}
impl Render for MainPanel {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
self.counters.panes.main.incr();
let theme = VoelinTheme::global(cx).clone();
let (c, m) = (&theme.colors, &theme.metrics);
let body = match &self.state {
MainState::NoServer => div()
.id("main-empty")
.debug_selector(|| "main-empty".into())
.flex()
.flex_col()
.items_center()
.gap(px(m.space_4))
.child(
div()
.size(px(72.0))
.rounded(px(m.radius_xl))
.bg(hsla(c.surface_2))
.border_1()
.border_color(hsla(c.border))
.flex()
.items_center()
.justify_center()
.child(icon("server", 32.0, c.text_muted)),
)
.child(
div()
.text_size(px(m.font_xl))
.font_weight(FontWeight::SEMIBOLD)
.text_color(hsla(c.text))
.child("No server selected"),
)
.child(
div()
.max_w(px(360.0))
.text_center()
.text_size(px(m.font_body))
.text_color(hsla(c.text_muted))
.child("Pick a server in the list, or add one to start talking."),
)
.child(tagged(
"main-add",
Button::new("main-add")
.primary()
.label("Add a server")
.on_click(|_, window, cx| window.dispatch_action(Box::new(AddServer), cx)),
)),
MainState::Server(item) => {
let id = i64::from(item.id);
let connected = item.status.as_ref() == "connected";
let connecting = item.status.as_ref() == "connecting";
div()
.id("main-server")
.debug_selector(|| "main-server".into())
.flex()
.flex_col()
.items_center()
.gap(px(m.space_4))
.child(
Avatar::new("main-server-avatar", 72.0, &item.initials, item.tint)
.image(item.icon.clone())
.square()
.presence(Presence::of_server(&item.status)),
)
.child(
div()
.max_w(px(480.0))
.truncate()
.text_size(px(m.font_2xl))
.font_weight(FontWeight::SEMIBOLD)
.text_color(hsla(c.text))
.child(item.name.to_string()),
)
.child(
div()
.text_size(px(m.font_body))
.text_color(hsla(c.text_secondary))
.child(item.address.to_string()),
)
.child(
div()
.id("main-server-state")
.text_size(px(m.font_sm))
.text_color(hsla(c.text_muted))
.child(state_words(&item.status)),
)
.child(
div()
.max_w(px(360.0))
.text_center()
.text_size(px(m.font_body))
.text_color(hsla(c.text_muted))
.child("Its chat and its voice page come with the next slices."),
)
.child(
div()
.flex()
.flex_row()
.gap(px(m.space_3))
.when(connected || connecting, |row| {
row.child(tagged(
"main-disconnect",
Button::new("main-disconnect")
.danger()
.label("Disconnect")
.on_click(|_, window, cx| {
window.dispatch_action(Box::new(DisconnectVoice), cx);
}),
))
})
.when(!connected && !connecting, |row| {
row.child(tagged(
"main-connect",
Button::new("main-connect")
.primary()
.label("Connect")
.on_click(|_, window, cx| {
window.dispatch_action(Box::new(ConnectVoice), cx);
}),
))
})
.child(tagged(
"main-edit",
Button::new("main-edit").label("Edit").on_click(
move |_, window, cx| {
window.dispatch_action(Box::new(EditServer { id }), cx);
},
),
)),
)
}
};
// The root of a cached pane takes the size its place gives it: laid out
// on its own, `flex_1` would be as wide as its contents.
panel(&theme).id("main").size_full().items_center().justify_center().child(body)
}
}