forge
Explore
Log in

Don't you dare go Hollow

Wire bastion into chat and pin user-list width

Browse files at this commit

a8d97165314e353890dddd4b89483f4772cb5da1Ahmet Kaan GümüşParent: 9c1eb2f
  • feat
    • wire bastion into chat and pin user-list width
Show full message
✨ feat(client): wire bastion into chat and pin user-list width

Thread a Bastion through Message construction to match the new common
API, rename the message sender accessor to get_user, and stop the
user-list column from shrinking when the message list overflows by
giving the chat column flex_1 and the user column flex_shrink_0.
crates/client/src/gui/chat.rsmodified+19 -7
@@ -1,4 +1,4 @@
1-use common::{Message, User};1+use common::{bastion::Bastion, message::Message, user::User};
2 use gpui::{2 use gpui::{
3 AppContext, Context, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement,3 AppContext, Context, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement,
4 StatefulInteractiveElement, Styled, Window, div, rgb,4 StatefulInteractiveElement, Styled, Window, div, rgb,
@@ -12,6 +12,7 @@ use gpui_component::{
12 use crate::gui::Nefes;12 use crate::gui::Nefes;
13 13
14 pub struct Chat {14 pub struct Chat {
15+ bastion: Bastion,
15 users: Vec<User>,16 users: Vec<User>,
16 chat_messages: Vec<Message>,17 chat_messages: Vec<Message>,
17 message_input: Entity<InputState>,18 message_input: Entity<InputState>,
@@ -26,9 +27,16 @@ impl Chat {
26 input_state27 input_state
27 });28 });
28 29
30+ let bastion = Bastion::new("Bastion").unwrap();
31+
32+ let bastion = || bastion.clone();
29 cx.subscribe_in(&message_input, window, |this, input, event, window, cx| {33 cx.subscribe_in(&message_input, window, |this, input, event, window, cx| {
30 if matches!(event, InputEvent::PressEnter { .. }) {34 if matches!(event, InputEvent::PressEnter { .. }) {
31- match Message::new(this.login.get_user().unwrap(), input.read(cx).text()) {35+ match Message::new(
36+ this.login.get_user().unwrap(),
37+ this.chat.bastion.clone(),
38+ input.read(cx).text(),
39+ ) {
32 Ok(message) => {40 Ok(message) => {
33 this.chat.chat_messages.push(message);41 this.chat.chat_messages.push(message);
34 input.update(cx, |input_state, cx| {42 input.update(cx, |input_state, cx| {
@@ -45,15 +53,17 @@ impl Chat {
45 53
46 let person_1 = User::new("Ahmet").unwrap();54 let person_1 = User::new("Ahmet").unwrap();
47 let person_2 = User::new("Kaan").unwrap();55 let person_2 = User::new("Kaan").unwrap();
48- let message_1 = Message::new(person_1, "Hello, how are you?").unwrap();56+ let message_1 = Message::new(person_1, bastion(), "Hello, how are you?").unwrap();
49- let message_2 = Message::new(person_2, "I'm doing well. How are you?").unwrap();57+ let message_2 = Message::new(person_2, bastion(), "I'm doing well. How are you?").unwrap();
50 let person_1 = User::new("Ahmet").unwrap();58 let person_1 = User::new("Ahmet").unwrap();
51- let message_3 = Message::new(person_1, "I'm good too. Thanks for asking!").unwrap();59+ let message_3 =
60+ Message::new(person_1, bastion(), "I'm good too. Thanks for asking!").unwrap();
52 let person_2 = User::new("Kaan").unwrap();61 let person_2 = User::new("Kaan").unwrap();
53- let message_4 = Message::new(person_2, "A".repeat(1024)).unwrap();62+ let message_4 = Message::new(person_2, bastion(), "A".repeat(1024)).unwrap();
54 let person_1 = User::new("Ahmet").unwrap();63 let person_1 = User::new("Ahmet").unwrap();
55 let person_2 = User::new("Kaan").unwrap();64 let person_2 = User::new("Kaan").unwrap();
56 Self {65 Self {
66+ bastion: bastion(),
57 users: vec![person_1, person_2],67 users: vec![person_1, person_2],
58 chat_messages: vec![message_1, message_2, message_3, message_4],68 chat_messages: vec![message_1, message_2, message_3, message_4],
59 message_input,69 message_input,
@@ -77,6 +87,7 @@ impl Nefes {
77 div()87 div()
78 .flex()88 .flex()
79 .flex_col()89 .flex_col()
90+ .flex_1()
80 .min_w_0()91 .min_w_0()
81 .child(92 .child(
82 div()93 div()
@@ -104,6 +115,7 @@ impl Nefes {
104 .h_full()115 .h_full()
105 .flex()116 .flex()
106 .flex_col()117 .flex_col()
118+ .flex_shrink_0()
107 .w_1_5()119 .w_1_5()
108 .border_l_1()120 .border_l_1()
109 .border_color(rgb(0x2f3136))121 .border_color(rgb(0x2f3136))
@@ -135,7 +147,7 @@ fn render_message(message: &Message) -> impl IntoElement {
135 div()147 div()
136 .text_color(rgb(0x7289da))148 .text_color(rgb(0x7289da))
137 .font_weight(FontWeight::BOLD)149 .font_weight(FontWeight::BOLD)
138- .child(message.get_sender().get_username().clone()),150+ .child(message.get_user().get_username().clone()),
139 )151 )
140 .child(div().pl_2().child(message.get_message().clone()))152 .child(div().pl_2().child(message.get_message().clone()))
141 }153 }
crates/client/src/gui/login.rsmodified+1 -1
@@ -1,4 +1,4 @@
1-use common::User;1+use common::user::User;
2 use gpui::{AppContext, Context, Entity, IntoElement, ParentElement, Styled, Window, div};2 use gpui::{AppContext, Context, Entity, IntoElement, ParentElement, Styled, Window, div};
3 use gpui_component::{3 use gpui_component::{
4 WindowExt,4 WindowExt,