1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
//! `handle_action` dispatcher and per-action handler helpers.
use tracing::{debug, warn};
use crate::ui::pr_detail::DetailSection;
use super::actions::Action;
use super::state::App;
use super::types::{CommentSubjectKind, DetailKind, Focus, MutationRefresh, PerTabState};
impl App {
/// Route an action to the appropriate handler.
// Taking `Action` by value is correct — the dispatcher owns and consumes
// the action. clippy prefers `&Action` here but that would require cloning
// for variants like `RawKey(KeyEvent)` which are not `Copy`.
#[allow(clippy::needless_pass_by_value, clippy::too_many_lines)]
pub(super) fn handle_action(&mut self, action: Action) {
match action {
Action::Quit => {
self.running = false;
}
Action::RawKey(key) => {
self.handle_key(key);
}
Action::Resize(w, h) => {
// ratatui redraws the full frame on the next loop iteration;
// no explicit handling is required for resize events.
debug!("terminal resized to {w}x{h}");
}
Action::Mouse(m) => {
self.handle_mouse(m);
}
Action::NextTab => {
self.save_current_tab_state();
self.tabs.next();
self.restore_active_tab_state();
}
Action::PrevTab => {
self.save_current_tab_state();
self.tabs.prev();
self.restore_active_tab_state();
}
Action::SwitchTab(idx) => {
self.save_current_tab_state();
self.tabs.set_active_by_index(idx);
self.restore_active_tab_state();
}
Action::OpenHelp => {
self.show_help = !self.show_help;
if self.show_help {
self.focus = Focus::Help;
} else {
self.focus = Focus::Dashboard;
}
}
Action::Refresh | Action::RefreshAll => {
if let Some(tx) = self.action_tx.clone() {
self.spawn_fetch(tx);
}
}
Action::ToggleShowAll => {
self.config.show_all_prs = !self.config.show_all_prs;
self.config.save();
let msg = if self.config.show_all_prs {
"Showing all open PRs/issues"
} else {
"Showing only yours"
};
self.show_flash(msg, std::time::Duration::from_secs(3));
// Kick a fresh fetch with the new mode.
if let Some(tx) = self.action_tx.clone() {
self.spawn_fetch(tx);
}
}
Action::OpenDetail => {
warn!("Action::OpenDetail not yet implemented (Phase 3)");
}
Action::BackToDashboard => {
warn!("Action::BackToDashboard not yet implemented (Phase 3)");
}
Action::ToggleView => {
if let Some(repo) = self.tabs.active_tab().map(|t| t.repo.clone()) {
let current = self.session.view_mode(&repo);
let next = match current {
crate::state::ViewMode::Prs => crate::state::ViewMode::Issues,
crate::state::ViewMode::Issues => crate::state::ViewMode::Prs,
};
self.session.set_view_mode(&repo, next);
// Reset selection to 0 when toggling view.
self.selection.insert(repo, 0);
}
}
Action::OpenInBrowser => {
warn!("Action::OpenInBrowser not yet implemented (Phase 4)");
}
Action::CopyUrl => {
warn!("Action::CopyUrl not yet implemented (Phase 4)");
}
Action::CheckoutBranch => {
self.begin_checkout_from_selection();
}
Action::ConfirmCheckout(confirmed) | Action::ConfirmPending(confirmed) => {
if confirmed {
self.execute_confirm();
} else {
self.dismiss_confirm();
}
}
Action::BeginMergePullRequest(method) => {
self.begin_merge_from_detail(method);
}
Action::OpenCommentComposer(target) => {
self.open_comment_composer(target);
}
Action::SubmitCommentComposer => {
self.submit_comment_composer();
}
Action::MutationStarted(pending) => {
self.pending_mutation = Some(pending);
self.mutation_error = None;
}
Action::MutationSucceeded(refresh) => {
self.on_mutation_succeeded(refresh);
}
Action::MutationFailed(err) => {
self.pending_mutation = None;
self.mutation_error = Some(err.clone());
if let Some(draft) = self.pending_comment_draft.take() {
self.composer = Some(draft);
self.focus = Focus::Composer;
}
self.show_flash(err, std::time::Duration::from_secs(5));
}
Action::OpenRepoPicker => {
debug!("Action::OpenRepoPicker: switching focus from {:?}", self.focus);
self.repo_picker_list_cursor = 0;
self.repo_picker_input.clear();
self.repo_picker_mode = super::types::RepoPickerMode::List;
self.repo_picker_return_focus = self.focus;
self.focus = Focus::RepoPicker;
}
Action::InboxFetchStarted => {
self.fetching = true;
}
Action::InboxLoaded(inbox) => {
self.on_inbox_loaded(*inbox);
}
Action::FetchFailed(msg) => {
self.on_fetch_failed(msg);
}
Action::FetchPrDetail(repo, number) => {
if let Some(tx) = self.action_tx.clone() {
self.spawn_detail_fetch(DetailKind::Pr, repo, number, tx);
}
}
Action::FetchIssueDetail(repo, number) => {
if let Some(tx) = self.action_tx.clone() {
self.spawn_detail_fetch(DetailKind::Issue, repo, number, tx);
}
}
Action::PrDetailLoaded(detail) => {
// Collect live SHAs before the borrow ends, used for pruning.
let current_shas: Vec<String> =
detail.commits.iter().map(|c| c.sha.clone()).collect();
let prefetch_repo = detail.repo.clone();
let prefetch_shas = current_shas.clone();
let previous_selected_sha = self.selected_commit.and_then(|idx| {
self.pr_detail
.as_ref()
.and_then(|d| d.commits.get(idx))
.map(|commit| commit.sha.clone())
});
let previous_cursor_sha = self
.pr_detail
.as_ref()
.and_then(|d| d.commits.get(self.commits_cursor))
.map(|commit| commit.sha.clone());
// Evict stale per-commit patch entries. A force-push can
// rewrite SHAs; keeping stale patches would serve wrong diffs.
self.detail_cache.prune_stale_commits(&detail.repo, ¤t_shas);
// Always upsert into cache — background SWR fetches land here
// too, even if the user has tabbed away.
self.detail_cache.insert_pr(*detail.clone());
// Only update visible state when the user is still looking at
// this exact item. Silently dropping is correct: the cache
// already holds the fresh data for the next visit.
let active_pr_matches = self
.pr_detail
.as_ref()
.is_some_and(|d| d.repo == detail.repo && d.number == detail.number);
// Also accept when pr_detail is None but focus is Detail and
// this was a foreground (cold-miss) fetch.
let foreground_cold_miss =
self.pr_detail.is_none() && self.focus == Focus::Detail && self.detail_fetching;
if self.focus == Focus::Detail && (active_pr_matches || foreground_cold_miss) {
let pr_detail = *detail.clone();
let selected_commit = previous_selected_sha.as_ref().and_then(|sha| {
pr_detail.commits.iter().position(|commit| &commit.sha == sha)
});
let commits_cursor = previous_cursor_sha
.as_ref()
.and_then(|sha| {
pr_detail.commits.iter().position(|commit| &commit.sha == sha)
})
.or(selected_commit)
.unwrap_or(0)
.min(pr_detail.commits.len().saturating_sub(1));
// Rebuild the thread index alongside every new PrDetail so
// the Files overview + future inline-expansion path have
// O(1) `(path, line)` lookups on the current thread set.
self.thread_index = Some(crate::ui::pr_detail::build_thread_index(&pr_detail));
// Preserve commit navigation by SHA across SWR refreshes.
// If a force-push removed the selected SHA, the scope is
// cleared rather than keeping a stale index.
self.commits_cursor = commits_cursor;
self.selected_commit = selected_commit;
self.pr_detail = Some(pr_detail);
}
self.prefetch_commit_diffs(&prefetch_repo, prefetch_shas);
self.clear_detail_loading_markers(&detail.repo, detail.number);
}
Action::IssueDetailLoaded(detail) => {
self.detail_cache.insert_issue(*detail.clone());
let active_issue_matches = self
.issue_detail
.as_ref()
.is_some_and(|d| d.repo == detail.repo && d.number == detail.number);
let foreground_cold_miss = self.issue_detail.is_none()
&& self.focus == Focus::Detail
&& self.detail_fetching;
if self.focus == Focus::Detail && (active_issue_matches || foreground_cold_miss) {
self.issue_detail = Some(*detail.clone());
}
self.clear_detail_loading_markers(&detail.repo, detail.number);
}
Action::DetailFetchFailed(msg) => {
self.detail_fetching = false;
// A failed background SWR fetch must not erase the stale content
// the user is currently reading — only log the warning.
warn!("GitHub detail fetch failed: {msg}");
// Only surface the error when no stale content is available.
if self.pr_detail.is_none() && self.issue_detail.is_none() {
self.detail_error = Some(msg);
}
// Clear the SWR marker regardless so a future tick can retry.
self.detail_refreshing = None;
}
Action::CommitDiffLoaded(repo, sha, patches) => {
self.commit_diff_fetching.remove(&(repo.clone(), sha.clone()));
// Store the per-commit patch map so the Files renderer can use it
// when `selected_commit` points at this SHA.
self.detail_cache.insert_commit_patches(repo, sha, patches);
// No explicit redraw call needed: the next event-loop iteration
// always re-renders after processing an action.
}
Action::CommitDiffFailed(repo, sha, err) => {
self.commit_diff_fetching.remove(&(repo.clone(), sha.clone()));
warn!("commit diff fetch failed for {repo}@{sha}: {err}");
// A late failure from an older duplicate request must not
// override a successful response that already populated cache.
if self.detail_cache.get_commit_patches(&repo, &sha).is_some() {
return;
}
let still_scoped = self.selected_commit.is_some_and(|idx| {
self.pr_detail
.as_ref()
.and_then(|d| d.commits.get(idx))
.is_some_and(|c| c.sha == sha)
});
if still_scoped {
// Flash the error and snap back to HEAD so the Files
// section doesn't stay blank. Prefetch failures for
// unselected commits are only logged above.
self.show_flash(
format!("Commit diff fetch failed: {err}"),
std::time::Duration::from_secs(4),
);
self.selected_commit = None;
}
}
Action::AutoRefresh => {
// Inbox refresh (same as RefreshAll / Refresh).
if let Some(tx) = self.action_tx.clone() {
self.spawn_fetch(tx.clone());
// Detail SWR: re-fetch the open item if one exists and we
// are not already re-fetching it.
if self.focus == Focus::Detail {
let detail_key: Option<(DetailKind, String, u32)> =
if let Some(d) = &self.pr_detail {
Some((DetailKind::Pr, d.repo.clone(), d.number))
} else {
self.issue_detail
.as_ref()
.map(|d| (DetailKind::Issue, d.repo.clone(), d.number))
};
if let Some((kind, repo, number)) = detail_key {
let already = self
.detail_refreshing
.as_ref()
.is_some_and(|(r, n)| r == &repo && *n == number);
if !already {
self.detail_refreshing = Some((repo.clone(), number));
self.spawn_detail_fetch_background(kind, repo, number, tx);
}
}
}
}
}
}
// Every action path could have mutated `pr_detail_scroll` — explicitly
// in the scroll keys, implicitly in focus transitions or new data
// arriving. A single clamp here guarantees the offset never points
// past the current content's end (which previously left users staring
// at a blank frame and punching `k` to recover).
self.clamp_pr_detail_scroll();
}
/// Return to the dashboard, clearing all detail state.
///
/// Also clears the per-tab detail ref for the active tab — an explicit
/// Esc / `b` means "I'm done with that PR", so a later tab round-trip
/// should land on the dashboard list, not auto-reopen what we just left.
pub(super) fn back_to_dashboard(&mut self) {
if let Some(repo) = self.tabs.active_tab().map(|t| t.repo.clone()) {
self.per_tab_state.insert(repo, PerTabState::default());
}
self.focus = Focus::Dashboard;
self.pr_detail = None;
self.issue_detail = None;
self.detail_error = None;
self.detail_fetching = false;
// NOTE: `detail_cache` is intentionally NOT cleared here. The cached
// payloads remain available for instant serving on the next visit.
self.detail_refreshing = None;
self.pr_detail_scroll.clear();
self.pr_detail_diff_scroll.clear();
self.pr_detail_files_expanded = false;
self.detail_comments_expanded = false;
self.pr_detail_selected_section = DetailSection::default();
self.pr_detail_files_cursor = 0;
self.pr_detail_files_show_diff = false;
self.pr_detail_sidebar_scroll = 0;
self.pr_detail_expanded_threads.clear();
*self.pr_detail_diff_cursor.borrow_mut() = None;
self.selected_commit = None;
self.commits_cursor = 0;
self.copy_mode.exit();
}
/// Open the detail view for the currently selected PR or issue.
///
/// Reads the active tab, view mode, and selection index to determine which
/// item to fetch, then dispatches the appropriate detail action and switches
/// focus to [`Focus::Detail`].
pub(super) fn open_detail_for_selection(&mut self) {
let Some(repo) = self.tabs.active_tab().map(|t| t.repo.clone()) else {
return;
};
let Some(inbox) = &self.inbox else {
return;
};
let mode = self.session.view_mode(&repo);
let sel = self.selection.get(&repo).copied().unwrap_or(0);
match mode {
crate::state::ViewMode::Prs => {
let prs = crate::github::types::sorted_prs_for_repo(inbox, &repo);
if let Some(pr) = prs.get(sel) {
let number = pr.number;
// Reset detail state before switching focus. `detail_fetching`
// is set by `spawn_detail_fetch` itself — if we set it here
// too, the guard inside that function sees `true` and
// silently skips the fetch, leaving the view stuck on the
// spinner forever.
self.pr_detail = None;
self.issue_detail = None;
self.detail_error = None;
self.pr_detail_scroll.clear();
self.pr_detail_diff_scroll.clear();
self.pr_detail_files_expanded = false;
self.detail_comments_expanded = false;
self.pr_detail_selected_section = DetailSection::default();
self.pr_detail_files_cursor = 0;
self.pr_detail_sidebar_scroll = 0;
self.focus = Focus::Detail;
if let Some(tx) = self.action_tx.clone() {
self.spawn_detail_fetch(DetailKind::Pr, repo, number, tx);
}
}
}
crate::state::ViewMode::Issues => {
let issues = crate::github::types::sorted_issues_for_repo(inbox, &repo);
if let Some(issue) = issues.get(sel) {
let number = issue.number;
// See the PR branch above: `detail_fetching` is set by
// `spawn_detail_fetch`, not here, to avoid the self-
// blocking guard.
self.pr_detail = None;
self.issue_detail = None;
self.detail_error = None;
self.pr_detail_scroll.clear();
self.pr_detail_diff_scroll.clear();
self.pr_detail_files_expanded = false;
self.detail_comments_expanded = false;
self.pr_detail_selected_section = DetailSection::default();
self.pr_detail_files_cursor = 0;
self.pr_detail_sidebar_scroll = 0;
self.focus = Focus::Detail;
if let Some(tx) = self.action_tx.clone() {
self.spawn_detail_fetch(DetailKind::Issue, repo, number, tx);
}
}
}
}
}
// ── Confirmation overlay ─────────────────────────────────────────────────
/// Dismiss the confirmation overlay and restore prior focus.
pub(super) fn dismiss_confirm(&mut self) {
self.confirm = None;
self.focus = self.confirm_return_focus;
}
/// Execute the pending confirmation action, then dismiss the overlay.
pub(super) fn execute_confirm(&mut self) {
let Some(confirm) = self.confirm.take() else {
return;
};
self.focus = self.confirm_return_focus;
match confirm.pending_action {
crate::ui::confirm::ConfirmPending::CheckoutBranch { branch, .. } => {
// Check tree cleanliness before running git.
match crate::git::is_working_tree_clean() {
Err(e) => {
self.show_flash(
format!("git checkout failed: {e}"),
std::time::Duration::from_secs(4),
);
return;
}
Ok(false) => {
self.show_flash(
"Working tree is not clean; commit or stash first.",
std::time::Duration::from_secs(4),
);
return;
}
Ok(true) => {}
}
match crate::git::checkout_branch(&branch) {
Ok(()) => {
self.show_flash(
format!("Checked out {branch}"),
std::time::Duration::from_secs(3),
);
}
Err(e) => {
self.show_flash(
format!("git checkout failed: {e}"),
std::time::Duration::from_secs(4),
);
}
}
}
crate::ui::confirm::ConfirmPending::MergePullRequest {
repo,
number,
method,
expected_head_sha,
} => {
self.spawn_merge_mutation(repo, number, method, expected_head_sha);
}
}
}
/// Build a `Confirm` overlay for checking out the selected PR's head branch.
///
/// Reads from `pr_detail` when in Detail focus, or from the list-level
/// `PullRequest` when in Dashboard focus. No-ops if no branch can be
/// resolved.
pub(super) fn begin_checkout_from_selection(&mut self) {
// Prefer the detail view's head_ref when we are in it.
let (branch, repo, number) = if let Some(detail) = &self.pr_detail {
// `PrDetail::head_ref` is a `String`, so it can technically be
// empty even though GitHub would not return one. Guard against it
// so we never shell out `git checkout ""` (which produces a
// confusing usage error instead of a clean flash).
if detail.head_ref.is_empty() {
self.show_flash(
"Branch info not available for this PR.",
std::time::Duration::from_secs(3),
);
return;
}
(detail.head_ref.clone(), detail.repo.clone(), detail.number)
} else {
// Fall back to the list-level PullRequest.
let Some(repo_slug) = self.tabs.active_tab().map(|t| t.repo.clone()) else {
return;
};
let Some(inbox) = &self.inbox else {
return;
};
let sel = self.selection.get(&repo_slug).copied().unwrap_or(0);
let prs = crate::github::types::sorted_prs_for_repo(inbox, &repo_slug);
let Some(pr) = prs.get(sel) else {
return;
};
let Some(head) = pr.head_ref.clone() else {
self.show_flash(
"Branch info not available; open the detail view first.",
std::time::Duration::from_secs(3),
);
return;
};
(head, repo_slug, pr.number)
};
// Warn when not in a git repo.
if !crate::git::repo_cwd_is_git() {
self.show_flash(
"Not in a git repository; cannot checkout branch.",
std::time::Duration::from_secs(3),
);
return;
}
let cwd =
std::env::current_dir().map_or_else(|_| ".".to_owned(), |p| p.display().to_string());
let confirm = crate::ui::confirm::Confirm {
title: "Checkout branch".to_owned(),
prompt: format!("Checkout `{branch}` in {cwd}?"),
pending_action: crate::ui::confirm::ConfirmPending::CheckoutBranch {
repo: repo.clone(),
number,
branch,
},
};
self.confirm = Some(confirm);
self.confirm_return_focus = self.focus;
self.focus = Focus::Confirm;
}
/// Build a confirmation overlay for merging the currently-open PR.
pub(super) fn begin_merge_from_detail(
&mut self,
method: crate::github::mutations::MergeMethod,
) {
if self.pending_mutation.is_some() {
self.show_flash(
"Another GitHub action is still running",
std::time::Duration::from_secs(3),
);
return;
}
let Some(detail) = self.pr_detail.as_ref() else {
self.show_flash(
"Open a pull request before merging",
std::time::Duration::from_secs(3),
);
return;
};
if detail.merged {
self.show_flash("Pull request is already merged", std::time::Duration::from_secs(3));
return;
}
if detail.is_draft {
self.show_flash(
"Draft pull requests cannot be merged",
std::time::Duration::from_secs(3),
);
return;
}
if detail.head_oid.is_empty() {
self.show_flash(
"Head SHA unavailable; refresh the PR detail",
std::time::Duration::from_secs(3),
);
return;
}
let short_sha = detail.head_oid.chars().take(7).collect::<String>();
let confirm = crate::ui::confirm::Confirm {
title: format!("{} PR", method.label()),
prompt: format!(
"{} {}#{} into `{}` from `{}` at {short_sha}?",
method.label(),
detail.repo,
detail.number,
detail.base_ref,
detail.head_ref
),
pending_action: crate::ui::confirm::ConfirmPending::MergePullRequest {
repo: detail.repo.clone(),
number: detail.number,
method,
expected_head_sha: detail.head_oid.clone(),
},
};
self.confirm = Some(confirm);
self.confirm_return_focus = self.focus;
self.focus = Focus::Confirm;
}
/// Open the markdown composer overlay for `target`.
pub(super) fn open_comment_composer(&mut self, target: super::types::CommentComposerTarget) {
if self.pending_mutation.is_some() {
self.show_flash(
"Another GitHub action is still running",
std::time::Duration::from_secs(3),
);
return;
}
self.composer = Some(super::types::CommentComposer::new(target));
self.composer_return_focus = self.focus;
self.focus = Focus::Composer;
}
/// Submit the composer body if non-empty, preserving it on validation failure.
pub(super) fn submit_comment_composer(&mut self) {
let Some(composer) = self.composer.take() else {
return;
};
let body = composer.body.trim().to_owned();
if body.is_empty() {
self.composer = Some(composer);
self.show_flash("Comment body is empty", std::time::Duration::from_secs(2));
return;
}
if self.client.is_none() || self.action_tx.is_none() {
self.composer = Some(composer);
self.show_flash("No GitHub client configured", std::time::Duration::from_secs(3));
return;
}
let target = composer.target.clone();
self.pending_comment_draft = Some(composer);
self.focus = self.composer_return_focus;
self.spawn_comment_mutation(target, body);
}
/// Handle a successful mutation by refreshing the affected detail and inbox.
pub(super) fn on_mutation_succeeded(&mut self, refresh: MutationRefresh) {
self.pending_mutation = None;
self.pending_comment_draft = None;
self.mutation_error = None;
self.show_flash(refresh.message, std::time::Duration::from_secs(4));
match refresh.detail_ref.kind {
DetailKind::Pr => {
self.detail_cache
.invalidate_pr(&refresh.detail_ref.repo, refresh.detail_ref.number);
}
DetailKind::Issue => {
self.detail_cache
.invalidate_issue(&refresh.detail_ref.repo, refresh.detail_ref.number);
}
}
if let Some(tx) = self.action_tx.clone() {
self.spawn_fetch(tx.clone());
let is_visible = match refresh.detail_ref.kind {
DetailKind::Pr => self.pr_detail.as_ref().is_some_and(|d| {
d.repo == refresh.detail_ref.repo && d.number == refresh.detail_ref.number
}),
DetailKind::Issue => self.issue_detail.as_ref().is_some_and(|d| {
d.repo == refresh.detail_ref.repo && d.number == refresh.detail_ref.number
}),
};
if is_visible {
self.detail_refreshing =
Some((refresh.detail_ref.repo.clone(), refresh.detail_ref.number));
self.spawn_detail_fetch_background(
refresh.detail_ref.kind,
refresh.detail_ref.repo,
refresh.detail_ref.number,
tx,
);
}
}
}
/// Build a top-level comment target for the currently-open PR or issue.
pub(super) fn top_level_comment_target(&self) -> Option<super::types::CommentComposerTarget> {
if let Some(detail) = &self.pr_detail {
return Some(super::types::CommentComposerTarget::TopLevel {
repo: detail.repo.clone(),
number: detail.number,
subject_id: detail.node_id.clone(),
kind: CommentSubjectKind::PullRequest,
});
}
self.issue_detail.as_ref().map(|detail| super::types::CommentComposerTarget::TopLevel {
repo: detail.repo.clone(),
number: detail.number,
subject_id: detail.node_id.clone(),
kind: CommentSubjectKind::Issue,
})
}
}