Skip to content

Commit b17ce00

Browse files
committed
make sure to respect ai availability
1 parent 8d65af5 commit b17ce00

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

app/src/code_review/comment_list_view.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use warpui::{
3636
ViewHandle, WeakViewHandle,
3737
};
3838

39-
use crate::ai::AIRequestUsageModel;
39+
use crate::ai::request_usage_model::{AIRequestUsageModel, AIRequestUsageModelEvent};
4040
use crate::appearance::Appearance;
4141
use crate::code::buffer_location::LocalOrRemotePath;
4242
use crate::code::editor::comment_editor::DEFAULT_COMMENT_MAX_WIDTH;
@@ -233,6 +233,16 @@ impl CommentListView {
233233
Event::ItemHovered => {}
234234
});
235235

236+
// Keep the stored button state in sync when AI availability changes.
237+
ctx.subscribe_to_model(
238+
&AIRequestUsageModel::handle(ctx),
239+
|me, _, event, ctx| {
240+
if let AIRequestUsageModelEvent::RequestUsageUpdated = event {
241+
me.sync_send_button(ctx);
242+
}
243+
},
244+
);
245+
236246
Self {
237247
parent,
238248
comment_model: None,
@@ -1188,7 +1198,9 @@ impl TypedActionView for CommentListView {
11881198
ctx.emit(CommentListEvent::Cancelled);
11891199
}
11901200
CommentListAction::Submit => {
1191-
ctx.emit(CommentListEvent::Submitted);
1201+
if self.can_send(ctx) {
1202+
ctx.emit(CommentListEvent::Submitted);
1203+
}
11921204
}
11931205
CommentListAction::ShowOverflow { comment_id } => {
11941206
let current_overflow = self.active_overflow_comment_id.take();

0 commit comments

Comments
 (0)