Skip to content

Commit f9acb92

Browse files
committed
desktop-app: Delete FetchStateTag from track repo search
1 parent 605227a commit f9acb92

File tree

3 files changed

+8
-91
lines changed

3 files changed

+8
-91
lines changed

crates/desktop-app/src/track/repo_search/mod.rs

+6-43
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,6 @@ pub struct Context {
2222
pub params: Params,
2323
}
2424

25-
/// A light-weight tag that denotes the [`State`] variant.
26-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
27-
pub enum FetchStateTag {
28-
#[default]
29-
Initial,
30-
Ready,
31-
Pending,
32-
Failed,
33-
}
34-
35-
impl FetchStateTag {
36-
/// Check whether the state is stable.
37-
#[must_use]
38-
pub const fn is_idle(&self) -> bool {
39-
match self {
40-
Self::Initial | Self::Ready | Self::Failed => true,
41-
Self::Pending => false,
42-
}
43-
}
44-
45-
#[must_use]
46-
pub const fn should_prefetch(&self) -> bool {
47-
matches!(self, Self::Initial)
48-
}
49-
}
50-
5125
#[derive(Debug, Clone)]
5226
pub struct FetchedEntity {
5327
pub offset_hash: u64,
@@ -85,20 +59,13 @@ enum FetchState {
8559

8660
impl FetchState {
8761
#[must_use]
88-
const fn state_tag(&self) -> FetchStateTag {
62+
const fn is_idle(&self) -> bool {
8963
match self {
90-
Self::Initial => FetchStateTag::Initial,
91-
Self::Ready { .. } => FetchStateTag::Ready,
92-
Self::Failed { .. } => FetchStateTag::Failed,
93-
Self::Pending { .. } => FetchStateTag::Pending,
64+
Self::Initial | Self::Ready { .. } | Self::Failed { .. } => true,
65+
Self::Pending { .. } => false,
9466
}
9567
}
9668

97-
#[must_use]
98-
const fn is_idle(&self) -> bool {
99-
self.state_tag().is_idle()
100-
}
101-
10269
#[must_use]
10370
fn fetched_entities(&self) -> Option<&[FetchedEntity]> {
10471
match self {
@@ -119,7 +86,7 @@ impl FetchState {
11986

12087
#[must_use]
12188
const fn should_prefetch(&self) -> bool {
122-
self.state_tag().should_prefetch()
89+
matches!(self, Self::Initial)
12390
}
12491

12592
#[must_use]
@@ -272,11 +239,6 @@ impl State {
272239
&self.context
273240
}
274241

275-
#[must_use]
276-
pub const fn fetch_state_tag(&self) -> FetchStateTag {
277-
self.fetch.state_tag()
278-
}
279-
280242
#[must_use]
281243
pub const fn is_idle(&self) -> bool {
282244
self.fetch.is_idle()
@@ -314,7 +276,8 @@ impl State {
314276
// is required to avoid redundant code for determining in advance if
315277
// the state would actually change or not.
316278
let reset = Self::new(self.default_params.clone());
317-
if self.context == reset.context && self.fetch.state_tag() == reset.fetch.state_tag() {
279+
if self.context == reset.context && matches!(self.fetch, FetchState::Initial) {
280+
debug_assert!(matches!(reset.fetch, FetchState::Initial));
318281
// No effect.
319282
log::debug!("State doesn't need to be reset");
320283
return false;

crates/desktop-app/src/track/repo_search/tasklet.rs

+1-38
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use unnest::some_or_return_with;
1212

1313
use crate::{collection, WeakHandle};
1414

15-
use super::{FetchStateTag, ObservableState, State};
15+
use super::{ObservableState, State};
1616

1717
pub fn on_should_prefetch_trigger(
1818
subscriber: Subscriber<State>,
@@ -76,43 +76,6 @@ pub fn on_should_prefetch(
7676
}
7777
}
7878

79-
fn capture_fetch_state_tag_changes(state_tag: &mut FetchStateTag, new_state: &State) -> bool {
80-
if *state_tag == new_state.fetch_state_tag() {
81-
return false;
82-
}
83-
*state_tag = new_state.fetch_state_tag();
84-
true
85-
}
86-
87-
pub fn on_fetch_state_tag_changed(
88-
mut subscriber: Subscriber<State>,
89-
mut on_changed: impl FnMut(FetchStateTag) -> OnChanged + Send + 'static,
90-
) -> impl Future<Output = ()> + Send + 'static {
91-
let initial_value = subscriber.read_ack().fetch_state_tag();
92-
discro::tasklet::capture_changes(
93-
subscriber,
94-
initial_value,
95-
capture_fetch_state_tag_changes,
96-
move |fetch_state_tag| on_changed(*fetch_state_tag),
97-
)
98-
}
99-
100-
pub fn on_fetch_state_tag_changed_async<T>(
101-
mut subscriber: Subscriber<State>,
102-
mut on_changed: impl FnMut(FetchStateTag) -> T + Send + 'static,
103-
) -> impl Future<Output = ()> + Send + 'static
104-
where
105-
T: Future<Output = OnChanged> + Send + 'static,
106-
{
107-
let initial_value = subscriber.read_ack().fetch_state_tag();
108-
discro::tasklet::capture_changes_async(
109-
subscriber,
110-
initial_value,
111-
capture_fetch_state_tag_changes,
112-
move |fetch_state_tag| on_changed(*fetch_state_tag),
113-
)
114-
}
115-
11679
pub fn on_collection_state_changed(
11780
collection_state: &Arc<collection::ObservableState>,
11881
observable_state: Weak<ObservableState>,

demo-app/src/main.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,7 @@ impl Model for AppModel {
424424
self.collection_state = new_collection_state;
425425
}
426426
LibraryNotification::TrackSearchStateChanged => {
427-
log::warn!(
428-
"TODO: Track search state changed: {fetch_state_tag:?}",
429-
fetch_state_tag = self
430-
.app
431-
.library
432-
.state()
433-
.track_search()
434-
.read_observable()
435-
.fetch_state_tag()
436-
);
427+
log::warn!("TODO: Track search state changed");
437428
}
438429
},
439430
},

0 commit comments

Comments
 (0)