-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(timeline): add a virtual start of timeline item #4816
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4816 +/- ##
=======================================
Coverage 86.45% 86.45%
=======================================
Files 297 297
Lines 34616 34636 +20
=======================================
+ Hits 29928 29946 +18
- Misses 4688 4690 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
76133ef
to
a534f65
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I like having this marker. One note about a loop that can be simplified. Otherwise everything else is good.
One note while reading your code (it's NOT something I'm asking you to do, I can do it, just wanted to share my idea). I wonder if ObservableItems
shouldn't get a method to push or insert specific timeline items, so that we move the logic of where to insert or shift index in there instead of having it inside the EventHandler
:
insert_timeline_start
: will emit aPushFront
with aTimelineStart
insert_remote_timeline_item(index, item)
: depending ofindex
and the presence of some items, it will emit aPushFront
,Insert
orPushBack
insert_local_timeline_item
: always push at the end etc.
The idea is to get a cleaner API and a central place where to have all the invariants regarding the position of the items. Thoughts?
let mut state = self.state.write().await; | ||
let mut txn = state.transaction(); | ||
for item in txn.items.iter() { | ||
if item.is_timeline_start() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a VirtualTimelineItem::TimelineStart
at another position than the first position? I don' think so.
Consequently, this loop is unecessary (and even dangerous as we will loop over all items if there is no TimelineStart
):
if self.items.get(0).is_some_and(|item| item.is_timeline_start()) {
return;
}
txn.items.push_front(…);
txn.commit();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was worried that the date separator or the read marker could go before, but maybe you're right and I could add a test that a date separator can't be first.
At least we can stop iterating on the first non virtual item, otherwise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're checking the first item in the EventHandler. Be sure to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's keep it simple and only check the first item. I think it's fine, because we're inserting read markers and date dividers before event items, only, so if the timeline start has been inserted, it should always remain the first item.
I think that makes sense overall, although I'm not quite sure what it buys us. More concise names would be sweet, like Overall, I think the most valuable part would be to make it possible in the tests to assert against somewhat different expectations, using one of the macros that asserts what's the next timeline update is: e.g. asserting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to me. Thanks for the changes!
935bdf2
to
35f6a7e
Compare
Might be better than letting the apps figure out whether they need to put one or not.
The next step would be to add a virtuel item for gaps as well,
Gap { loading: bool }
:loading: true
loading: false
. The next call toTimeline::paginate_backwards()
would resolve it into aTimelineStart
or anotherGap { loading: false }
.Part of #4821.