chore: add missing fixture

This commit is contained in:
2026-05-28 22:43:52 +01:00
parent ecf019a956
commit 4a7ebf660e

View File

@@ -0,0 +1,110 @@
--- a/src/query.rs
+++ b/src/query.rs
@@ -1,56 +1,82 @@
-use std::collections::HashMap;
+use std::{collections::HashMap, time::SystemTime};
#[derive(Clone, Default)]
-pub struct CachedSelection {
- pub issue_id: Option<String>,
+pub struct CachedQueryState {
+ pub selected_issue_id: Option<String>,
+ pub selected_pull_request_id: Option<String>,
+ pub scroll_anchor: Option<String>,
pub scroll_offset: usize,
+ pub stale_at: Option<SystemTime>,
}
#[derive(Default)]
pub struct QueryStore {
- entries: HashMap<String, CachedSelection>,
+ entries: HashMap<String, CachedQueryState>,
}
impl QueryStore {
- pub fn snapshot(&self, key: &str) -> Option<CachedSelection> {
- self.entries.get(key).cloned()
- }
-
- pub fn remember(
+ pub fn remember_issue_state(
&mut self,
key: impl Into<String>,
- issue_id: Option<String>,
+ selected_issue_id: Option<String>,
+ selected_pull_request_id: Option<String>,
+ scroll_anchor: Option<String>,
scroll_offset: usize,
) {
self.entries.insert(
key.into(),
- CachedSelection {
- issue_id,
+ CachedQueryState {
+ selected_issue_id,
+ selected_pull_request_id,
+ scroll_anchor,
scroll_offset,
+ stale_at: None,
},
);
}
- pub fn clear(&mut self, key: &str) {
- self.entries.remove(key);
+ pub fn snapshot(&self, key: &str) -> Option<CachedQueryState> {
+ self.entries.get(key).cloned()
}
+
+ pub fn clear_stale(&mut self) {
+ self.entries
+ .retain(|_, state| state.stale_at.is_none() || state.selected_issue_id.is_some());
+ }
+
+ pub fn remove(&mut self, key: &str) -> Option<CachedQueryState> {
+ self.entries.remove(key)
+ }
}
-pub fn reconcile_selection(
- cached: Option<&CachedSelection>,
+pub fn reconcile_selected_issue(
+ cached: Option<&CachedQueryState>,
visible_ids: &[String],
) -> Option<String> {
- let current = cached.and_then(|state| state.issue_id.clone());
+ let cached_issue = cached.and_then(|state| state.selected_issue_id.as_ref());
- if let Some(id) = current.as_ref() {
- if visible_ids.iter().any(|visible| visible == id) {
- return Some(id.clone());
- }
- }
+ cached_issue
+ .filter(|issue_id| visible_ids.iter().any(|visible| visible == *issue_id))
+ .cloned()
+ .or_else(|| visible_ids.first().cloned())
+}
- visible_ids.first().cloned()
+pub fn reconcile_scroll_anchor(
+ cached: Option<&CachedQueryState>,
+ visible_ids: &[String],
+) -> Option<String> {
+ cached
+ .and_then(|state| state.scroll_anchor.as_ref())
+ .filter(|anchor| visible_ids.iter().any(|visible| visible == *anchor))
+ .cloned()
}
-pub fn should_repaint(cached: Option<&CachedSelection>, next_issue_id: Option<&str>) -> bool {
- cached.and_then(|state| state.issue_id.as_deref()) != next_issue_id
+pub fn should_repaint(
+ cached: Option<&CachedQueryState>,
+ next_issue_id: Option<&str>,
+ next_pull_request_id: Option<&str>,
+) -> bool {
+ cached.and_then(|state| state.selected_issue_id.as_deref()) != next_issue_id
+ || cached.and_then(|state| state.selected_pull_request_id.as_deref())
+ != next_pull_request_id
}