Skip to content

Commit aab3012

Browse files
mkg20001claude
andcommitted
refactor(ui,core): remove default props for config values
- Remove serde default for max_title_size, use Default impl like max_message_size - Remove #[props(default)] from max_title_size and max_message_size in PostInput and MessageEditForm - these must be passed from configuration - Update all MessageCard call sites to pass config values - Add max_title_size and max_message_size props to MessageCard 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent bdff57b commit aab3012

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

common/src/board_state/configuration.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ pub struct Configuration {
213213
pub max_recent_messages: usize,
214214
pub max_user_bans: usize,
215215
pub max_message_size: usize,
216-
#[serde(default = "default_max_title_size")]
217216
pub max_title_size: usize,
218217
pub max_nickname_size: usize,
219218
pub max_members: usize,
@@ -222,9 +221,6 @@ pub struct Configuration {
222221
pub max_board_description: usize,
223222
}
224223

225-
fn default_max_title_size() -> usize {
226-
100
227-
}
228224

229225
#[cfg(test)]
230226
mod tests {

ui/src/components/conversation.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ pub fn Conversation(
348348
let boards = BOARDS.read();
349349
if let Some(board_data) = boards.map.get(&key) {
350350
let self_member_id = MemberId::from(&board_data.self_sk.verifying_key());
351+
let config = &board_data.board_state.configuration.configuration;
352+
let max_title_size = config.max_title_size;
353+
let max_message_size = config.max_message_size;
351354
let all_messages = get_all_messages(
352355
&board_data.board_state.recent_messages,
353356
&board_data.board_state.member_info,
@@ -374,7 +377,7 @@ pub fn Conversation(
374377
.collect();
375378

376379
let tree = build_reply_tree(&all_messages, parent_id.as_ref());
377-
return Some((tree, self_member_id, member_names));
380+
return Some((tree, self_member_id, member_names, max_title_size, max_message_size));
378381
}
379382
}
380383
None
@@ -456,10 +459,12 @@ pub fn Conversation(
456459
{
457460
if current_board_data.is_some() {
458461
match message_tree.read().as_ref() {
459-
Some((tree, self_member_id, member_names)) if !tree.is_empty() => {
462+
Some((tree, self_member_id, member_names, max_title_size, max_message_size)) if !tree.is_empty() => {
460463
let tree = tree.clone();
461464
let self_member_id = *self_member_id;
462465
let member_names = member_names.clone();
466+
let max_title_size = *max_title_size;
467+
let max_message_size = *max_message_size;
463468
Some(rsx! {
464469
div { class: "space-y-2",
465470
{tree.into_iter().map({
@@ -478,6 +483,8 @@ pub fn Conversation(
478483
member_names: member_names,
479484
replies: msg_with_replies.replies.clone(),
480485
depth: 0,
486+
max_title_size: max_title_size,
487+
max_message_size: max_message_size,
481488
on_react: move |(msg_id, emoji)| {
482489
handle_toggle_reaction(msg_id, emoji);
483490
},
@@ -797,9 +804,9 @@ fn MessageEditForm(
797804
msg_id: MessageId,
798805
on_edit: Option<EventHandler<(MessageId, String, String)>>,
799806
size: MessageSize,
800-
#[props(default = 100)]
807+
/// Maximum title length (from board configuration)
801808
max_title_size: usize,
802-
#[props(default = 10000)]
809+
/// Maximum message length (from board configuration)
803810
max_message_size: usize,
804811
) -> Element {
805812
let (input_class, textarea_class, button_class, container_class) = match size {
@@ -1211,6 +1218,12 @@ pub fn MessageCard(
12111218
/// Default reply context for replies section
12121219
#[props(default)]
12131220
default_reply_to: Option<ReplyContext>,
1221+
/// Maximum title length (from board configuration)
1222+
#[props(default = 100)]
1223+
max_title_size: usize,
1224+
/// Maximum message length (from board configuration)
1225+
#[props(default = 10000)]
1226+
max_message_size: usize,
12141227
) -> Element {
12151228
let msg = message.clone();
12161229
let is_self = msg.is_self;
@@ -1292,6 +1305,8 @@ pub fn MessageCard(
12921305
msg_id: msg_id.clone(),
12931306
on_edit: on_edit.clone(),
12941307
size: size,
1308+
max_title_size: max_title_size,
1309+
max_message_size: max_message_size,
12951310
}
12961311
} else {
12971312
MessageContentDisplay {
@@ -1349,6 +1364,8 @@ pub fn MessageCard(
13491364
member_names: member_names,
13501365
replies: reply.replies.clone(),
13511366
depth: depth + 1,
1367+
max_title_size: max_title_size,
1368+
max_message_size: max_message_size,
13521369
on_react: on_react.clone(),
13531370
on_request_delete: on_request_delete.clone(),
13541371
on_edit: on_edit.clone(),
@@ -1429,6 +1446,8 @@ pub fn MessageCard(
14291446
msg_id: msg_id.clone(),
14301447
on_edit: on_edit.clone(),
14311448
size: size,
1449+
max_title_size: max_title_size,
1450+
max_message_size: max_message_size,
14321451
}
14331452
} else {
14341453
MessageContentDisplay {

ui/src/components/conversation/message_input.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ pub fn PostInput(
1515
/// Default reply context - applied when modal opens if replying_to is None
1616
#[props(default)]
1717
default_reply_to: Option<ReplyContext>,
18-
/// Maximum title length (default 100)
19-
#[props(default = 100)]
18+
/// Maximum title length (from board configuration)
2019
max_title_size: usize,
21-
/// Maximum message length (default 10000)
22-
#[props(default = 10000)]
20+
/// Maximum message length (from board configuration)
2321
max_message_size: usize,
2422
) -> Element {
2523
let mut show_modal = use_signal(|| false);

ui/src/components/posts_view.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,17 @@ pub fn PostsView() -> Element {
8585
div { class: "flex-1 overflow-y-auto",
8686
div { class: "max-w-4xl mx-auto px-4 py-6",
8787
{
88-
let self_member_id_for_posts = current_board_data.as_ref()
89-
.map(|rd| MemberId::from(&rd.self_sk.verifying_key()));
90-
match (posts.read().as_ref(), self_member_id_for_posts) {
91-
(Some(posts), Some(self_member_id)) if !posts.is_empty() => {
88+
let board_info = current_board_data.as_ref()
89+
.map(|rd| {
90+
let config = &rd.board_state.configuration.configuration;
91+
(
92+
MemberId::from(&rd.self_sk.verifying_key()),
93+
config.max_title_size,
94+
config.max_message_size,
95+
)
96+
});
97+
match (posts.read().as_ref(), board_info) {
98+
(Some(posts), Some((self_member_id, max_title_size, max_message_size))) if !posts.is_empty() => {
9299
rsx! {
93100
div { class: "space-y-8",
94101
{posts.iter().map({
@@ -107,6 +114,8 @@ pub fn PostsView() -> Element {
107114
self_member_id: self_member_id,
108115
expanded: false,
109116
show_replies: false,
117+
max_title_size: max_title_size,
118+
max_message_size: max_message_size,
110119
on_click: move |_| {
111120
// Get current board_id for navigation
112121
if let Some(key) = CURRENT_BOARD.read().owner_key {
@@ -198,21 +207,24 @@ pub fn SinglePostView(post_id: String) -> Element {
198207
.unwrap_or_default()
199208
});
200209

201-
// Find the post and self_member_id
210+
// Find the post, self_member_id, and config
202211
let post_data = use_memo(move || {
203212
let current_board = CURRENT_BOARD.read();
204213
if let Some(key) = current_board.owner_key {
205214
let boards = BOARDS.read();
206215
if let Some(board_data) = boards.map.get(&key) {
207216
let self_member_id = MemberId::from(&board_data.self_sk.verifying_key());
217+
let config = &board_data.board_state.configuration.configuration;
218+
let max_title_size = config.max_title_size;
219+
let max_message_size = config.max_message_size;
208220
let all_messages = get_all_messages(
209221
&board_data.board_state.recent_messages,
210222
&board_data.board_state.member_info,
211223
self_member_id,
212224
&board_data.secrets,
213225
);
214226
let post = all_messages.into_iter().find(|m| m.id_string() == post_id);
215-
return post.map(|p| (p, self_member_id));
227+
return post.map(|p| (p, self_member_id, max_title_size, max_message_size));
216228
}
217229
}
218230
None
@@ -262,7 +274,7 @@ pub fn SinglePostView(post_id: String) -> Element {
262274
div { class: "flex-1 overflow-y-auto",
263275
{
264276
match post_data.read().as_ref() {
265-
Some((post, self_member_id)) => {
277+
Some((post, self_member_id, max_title_size, max_message_size)) => {
266278
rsx! {
267279
div { class: "max-w-4xl mx-auto px-4 py-6",
268280
MessageCard {
@@ -271,6 +283,8 @@ pub fn SinglePostView(post_id: String) -> Element {
271283
self_member_id: *self_member_id,
272284
expanded: true,
273285
show_replies: true,
286+
max_title_size: *max_title_size,
287+
max_message_size: *max_message_size,
274288
on_react: move |(msg_id, emoji)| {
275289
handle_toggle_reaction(msg_id, emoji);
276290
},

0 commit comments

Comments
 (0)