Skip to content
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

Extract PostStream state #2160

Merged
merged 65 commits into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
7af8e35
Extract PostStream state
askvortsov1 May 10, 2020
cff9b32
Remove event from PostState, pass handler in via props,
askvortsov1 May 10, 2020
614bb0d
Moved refresh method of discussionpage into init, as its not used ext…
askvortsov1 May 10, 2020
6bcecd6
Revert inlining method, rename the method instead
franzliedke Jul 3, 2020
6c087da
Remove obsolete event handler
franzliedke Jul 3, 2020
8a9e50d
Encapsulate viewingEnd() in state
franzliedke Jul 3, 2020
062dc8f
Don't call protected method outside of state
franzliedke Jul 3, 2020
2ec49db
Pass discussion as prop to stream components
franzliedke Jul 3, 2020
5427b35
Large simplifications of PostStreamScrubber
askvortsov1 Jul 5, 2020
9c63c54
Simplify paused logic
askvortsov1 Jul 5, 2020
9a357f5
Add scrubber height change transition css, don't apply when dragging
askvortsov1 Jul 5, 2020
51008bc
Use scrollToIndex to contain scrollToLast
askvortsov1 Jul 5, 2020
c03fece
Fix goToLast
askvortsov1 Jul 6, 2020
eb24e62
Get rid of js-PostStream
askvortsov1 Jul 6, 2020
74cb4f9
Get rid of post stream events. Initial load is still buggy
askvortsov1 Jul 6, 2020
193f3b0
Slightly improve scrubber label accuracy on click
askvortsov1 Jul 6, 2020
6e1d385
Code cleanup, added a bunch of debug console logging
askvortsov1 Jul 6, 2020
5cdfeaf
Move scrollPromise log into scrollToItem
askvortsov1 Jul 6, 2020
1360723
Separate updateScrubber into separate method from onscroll
askvortsov1 Jul 6, 2020
beab8ce
Update scrubber after scrollToItem
askvortsov1 Jul 6, 2020
c150c09
Add some more debugging flags
askvortsov1 Jul 6, 2020
b2917c8
Add more console logs
askvortsov1 Jul 6, 2020
ba82969
Remove unnecessary redraw
askvortsov1 Jul 6, 2020
f8d1c7a
Add redraws after posts have been loaded from the API
askvortsov1 Jul 6, 2020
e84960d
Cleanup
askvortsov1 Jul 6, 2020
514165c
Anchor scroll after loading posts
askvortsov1 Jul 7, 2020
ac1eef7
Remove unused anchorScroll import
askvortsov1 Jul 7, 2020
9572863
Add anchorScroll with redraw after loadPromise loads in scrollToItem
askvortsov1 Jul 7, 2020
9db2f78
Incorporate math floor in sanitizeIndex, use that for scrubber index …
askvortsov1 Jul 7, 2020
0c63be5
Pass in a selector string to anchorScroll instead of a DOM element. B…
askvortsov1 Jul 7, 2020
aa15db6
Ensure consistent index in scrubber, rework current post index calcul…
askvortsov1 Jul 7, 2020
9f2540d
Properly bind loadNext button to the state
askvortsov1 Jul 7, 2020
4bce030
Use same logic as in updateScrubber to calculate current post number
askvortsov1 Jul 7, 2020
479e5a8
in goToNumber, only redraw when the response has been returned.
askvortsov1 Jul 7, 2020
d3fb5ee
Handle scroll to end as a special case of scroll to index to ensure t…
askvortsov1 Jul 7, 2020
73507f4
Don't use anchorScroll on goToNumber, instead scrolling directly to item
askvortsov1 Jul 7, 2020
c98c0b0
Fix missing method call
askvortsov1 Jul 7, 2020
cc10eaa
Get rid of separate system for scrollToLast
askvortsov1 Jul 7, 2020
2360745
Fix jumping around on page reload
askvortsov1 Jul 7, 2020
ef20649
Try calculating index before redraw to avoid calling redraw immediate…
askvortsov1 Jul 7, 2020
875a1f7
Fix date, index calculation on reload
askvortsov1 Jul 7, 2020
d20650f
Use date of the post in index
askvortsov1 Jul 7, 2020
cdcf648
Restore scrubber behavior
askvortsov1 Jul 8, 2020
228c7b8
move index calculation back out of show
askvortsov1 Jul 8, 2020
88e6be9
When scrolling to first post, scroll all the way to top, simplify scr…
askvortsov1 Jul 8, 2020
5ef4de7
Fix date not showing up properly
askvortsov1 Jul 8, 2020
92b62e7
Minor cleanup of PostStreamState methods
askvortsov1 Jul 9, 2020
af55a13
A bit more cleanup, UI bugfixes
askvortsov1 Jul 9, 2020
a850f4a
Restore old scrubber index calculation system
askvortsov1 Jul 9, 2020
1d86620
A bit more cleanup and bugfixes
askvortsov1 Jul 10, 2020
bbd8136
A bit more cleanup
askvortsov1 Jul 10, 2020
f99f79e
De-propify visible
askvortsov1 Jul 10, 2020
8c362bf
Don't save index twice in post stream post-load
askvortsov1 Jul 10, 2020
1a2f952
Revert formatting changes
franzliedke Jul 31, 2020
aae6f24
Fix docblock
franzliedke Jul 31, 2020
3ce9475
Rename props
franzliedke Jul 31, 2020
09c722e
Remove unused prop
franzliedke Jul 31, 2020
8b69b24
Fix docblocks
franzliedke Jul 31, 2020
57f5ad4
Move method to previous position
franzliedke Jul 31, 2020
0138413
Encapsulate a bit more logic in the state
franzliedke Jul 31, 2020
a044c64
Add default parameter value
franzliedke Jul 31, 2020
e455e6c
Restore old implementation of goToLast()
franzliedke Jul 31, 2020
e8394e4
Unify pausing
franzliedke Jul 31, 2020
6f6a09d
Start decoupling scrolling from state
franzliedke Jul 31, 2020
d4abf58
Default parameter value
franzliedke Aug 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions js/src/forum/components/DiscussionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SplitDropdown from '../../common/components/SplitDropdown';
import listItems from '../../common/helpers/listItems';
import DiscussionControls from '../utils/DiscussionControls';
import DiscussionList from './DiscussionList';
import PostStreamState from '../states/PostStreamState';

/**
* The `DiscussionPage` component displays a whole discussion page, including
Expand All @@ -27,11 +28,11 @@ export default class DiscussionPage extends Page {
/**
* The number of the first post that is currently visible in the viewport.
*
* @type {Integer}
* @type {number}
*/
this.near = null;
this.near = m.route.param('near') || 0;

this.refresh();
this.load();

// If the discussion list has been loaded, then we'll enable the pane (and
// hide it by default). Also, if we've just come from another discussion
Expand Down Expand Up @@ -107,7 +108,14 @@ export default class DiscussionPage extends Page {
<nav className="DiscussionPage-nav">
<ul>{listItems(this.sidebarItems().toArray())}</ul>
</nav>
<div className="DiscussionPage-stream">{this.stream.render()}</div>
<div className="DiscussionPage-stream">
{PostStream.component({
discussion,
stream: this.stream,
targetPost: this.stream.targetPost,
onPositionChange: this.positionChanged.bind(this),
})}
</div>
</div>,
]
: LoadingIndicator.component({ className: 'LoadingIndicator--block' })}
Expand All @@ -125,12 +133,9 @@ export default class DiscussionPage extends Page {
}

/**
* Clear and reload the discussion.
* Load the discussion from the API or use the preloaded one.
*/
refresh() {
this.near = m.route.param('near') || 0;
this.discussion = null;

load() {
const preloadedDiscussion = app.preloadedApiDocument();
if (preloadedDiscussion) {
// We must wrap this in a setTimeout because if we are mounting this
Expand Down Expand Up @@ -197,8 +202,7 @@ export default class DiscussionPage extends Page {
// Set up the post stream for this discussion, along with the first page of
// posts we want to display. Tell the stream to scroll down and highlight
// the specific post that was routed to.
this.stream = new PostStream({ discussion, includedPosts });
this.stream.on('positionChanged', this.positionChanged.bind(this));
this.stream = new PostStreamState(discussion, includedPosts);
this.stream.goToNumber(m.route.param('near') || (includedPosts[0] && includedPosts[0].number()), true);

app.current.set('discussion', discussion);
Expand Down
Loading