Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cf-online-ui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
cf-online-ui
Commits
76dd445b
Commit
76dd445b
authored
4 years ago
by
xaralis
Browse files
Options
Downloads
Patches
Plain Diff
feat: re-sort posts after ranking in a throttled manner
parent
9004a89b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2081
passed
4 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/containers/PostFilters.jsx
+1
-5
1 addition, 5 deletions
src/containers/PostFilters.jsx
src/ws/handlers/posts.js
+17
-6
17 additions, 6 deletions
src/ws/handlers/posts.js
with
18 additions
and
11 deletions
src/containers/PostFilters.jsx
+
1
−
5
View file @
76dd445b
...
...
@@ -22,16 +22,12 @@ const PostFilters = () => {
{
title
:
"
Jen příspěvky
"
,
value
:
"
discussionOnly
"
},
];
const
setFilter
=
(
prop
,
newValue
,
resetPage
=
true
)
=>
{
const
setFilter
=
(
prop
,
newValue
)
=>
{
PostStore
.
update
((
state
)
=>
{
state
.
filters
[
prop
]
=
newValue
;
state
.
window
.
itemCount
=
state
.
window
.
items
.
length
;
updateWindowPosts
(
state
);
if
(
resetPage
)
{
state
.
window
.
page
=
1
;
}
});
};
...
...
This diff is collapsed.
Click to expand it.
src/ws/handlers/posts.js
+
17
−
6
View file @
76dd445b
import
has
from
"
lodash/has
"
;
import
throttle
from
"
lodash/throttle
"
;
import
{
markdownConverter
}
from
"
markdown
"
;
import
{
PostStore
}
from
"
stores
"
;
import
{
parseRawPost
,
postsStateMapping
,
updateWindowPosts
}
from
"
utils
"
;
/**
* Re-apply sorting by rank but no more than once every 3 seconds.
*/
const
sortOnRankThrottled
=
throttle
(()
=>
{
PostStore
.
update
((
state
)
=>
{
if
(
state
.
filters
.
sort
===
"
byScore
"
)
{
updateWindowPosts
(
state
);
}
});
},
3000
);
export
const
handlePostRanked
=
(
payload
)
=>
{
PostStore
.
update
((
state
)
=>
{
if
(
state
.
items
[
payload
.
id
])
{
...
...
@@ -12,12 +24,11 @@ export const handlePostRanked = (payload) => {
state
.
items
[
payload
.
id
].
ranking
.
score
=
state
.
items
[
payload
.
id
].
ranking
.
likes
-
state
.
items
[
payload
.
id
].
ranking
.
dislikes
;
if
(
state
.
filters
.
sort
===
"
byScore
"
)
{
updateWindowPosts
(
state
);
}
}
});
// Run sorting in a throttled manner.
sortOnRankThrottled
();
};
export
const
handlePostChanged
=
(
payload
)
=>
{
...
...
@@ -33,13 +44,13 @@ export const handlePostChanged = (payload) => {
if
(
has
(
payload
,
"
state
"
))
{
state
.
items
[
payload
.
id
].
state
=
postsStateMapping
[
payload
.
state
];
updateWindowPosts
(
state
);
}
if
(
has
(
payload
,
"
is_archived
"
))
{
state
.
items
[
payload
.
id
].
archived
=
payload
.
is_archived
;
updateWindowPosts
(
state
);
}
updateWindowPosts
(
state
);
}
});
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment