Skip to content

Commit

Permalink
Merge branch 'master' into mp-isnew
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko authored Jul 28, 2023
2 parents 4997cfe + 4f664da commit d35b23c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
11 changes: 6 additions & 5 deletions app/Http/Controllers/CommentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ public function destroy($id)
*
* `pinned_comments` is only included when `commentable_type` and `commentable_id` are specified.
*
* @queryParam commentable_type The type of resource to get comments for.
* @queryParam commentable_id The id of the resource to get comments for.
* @queryParam cursor Pagination option. See [CommentSort](#commentsort) for detail. The format follows [Cursor](#cursor) except it's not currently included in the response.
* @queryParam parent_id Limit to comments which are reply to the specified id. Specify 0 to get top level comments.
* @queryParam sort Sort option as defined in [CommentSort](#commentsort). Defaults to `new` for guests and user-specified default when authenticated.
* @queryParam after Return comments which come after the specified comment id as per sort option. No-example
* @queryParam commentable_type The type of resource to get comments for. Example: beatmapset
* @queryParam commentable_id The id of the resource to get comments for. Example: 1
* @queryParam cursor Pagination option. See [CommentSort](#commentsort) for detail. The format follows [Cursor](#cursor) except it's not currently included in the response. No-example
* @queryParam parent_id Limit to comments which are reply to the specified id. Specify 0 to get top level comments. Example: 1
* @queryParam sort Sort option as defined in [CommentSort](#commentsort). Defaults to `new` for guests and user-specified default when authenticated. Example: new
*/
public function index()
{
Expand Down
14 changes: 11 additions & 3 deletions app/Libraries/CommentBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ public function countForPaginator()

private function getComments($query, $isChildren = true, $pinnedOnly = false)
{
$sortOrCursorHelper = $pinnedOnly ? 'new' : $this->params->cursorHelper;
$cursorHelper = $pinnedOnly
? Comment::makeDbCursorHelper('new')
: $this->params->cursorHelper;
$queryLimit = $this->params->limit;

if (!$isChildren) {
Expand All @@ -180,14 +182,20 @@ private function getComments($query, $isChildren = true, $pinnedOnly = false)
}

$queryLimit++;
$cursor = $this->params->cursor;

if ($this->params->after === null) {
$cursor = $this->params->cursor;
} else {
$lastComment = Comment::findOrFail($this->params->after);
$cursor = $cursorHelper->next([$lastComment]);
}

if ($cursor === null) {
$query->offset(max_offset($this->params->page, $this->params->limit));
}
}

$query->cursorSort($sortOrCursorHelper, $cursor ?? null);
$query->cursorSort($cursorHelper, $cursor ?? null);

if (!$this->includeDeleted) {
$query->whereNull('deleted_at');
Expand Down
2 changes: 2 additions & 0 deletions app/Libraries/CommentBundleParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CommentBundleParams
const DEFAULT_PAGE = 1;
const DEFAULT_LIMIT = 50;

public ?int $after = null;
public $userId;
public $commentableId;
public $commentableType;
Expand Down Expand Up @@ -64,6 +65,7 @@ public function setAll($params)
$this->cursorHelper = Comment::makeDbCursorHelper($params['sort'] ?? $this->sort);
$this->cursor = get_arr($params['cursor'] ?? null);
$this->sort = $this->cursorHelper->getSortName();
$this->after = get_int($params['after'] ?? null);
}

public function filterByParentId()
Expand Down
7 changes: 1 addition & 6 deletions resources/js/components/comment-show-more.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ export default class CommentShowMore extends React.Component<Props> {

const lastComment = last(this.props.comments);
if (lastComment != null) {
// TODO: convert to plain after_id params of some sort instead of cursor
params.cursor = {
created_at: lastComment.createdAt,
id: lastComment.id,
votes_count: lastComment.votesCount,
};
params.after = lastComment.id;
}

this.xhr = $.ajax(route('comments.index'), { data: params, dataType: 'json' });
Expand Down
9 changes: 5 additions & 4 deletions resources/js/contest-voting/art-entry-list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ export class ArtEntryList extends BaseEntryList

selected = new Set(@state.selected)

displayIndex = -1
entries = @state.contest.entries.map (entry) =>
galleryIndex = -1
entries = @state.contest.entries.map (entry, index) =>
isSelected = selected.has(entry.id)

return null if @state.showVotedOnly && !isSelected

el ArtEntry,
key: entry.id,
contest: @state.contest,
displayIndex: ++displayIndex,
galleryIndex: ++galleryIndex,
index: index
entry: entry,
isSelected: isSelected
options: @state.options,
Expand All @@ -32,7 +33,7 @@ export class ArtEntryList extends BaseEntryList

if @state.contest.show_votes
partitions = _.partition entries, (i) ->
i != null && i.props.displayIndex < 3
i != null && i.props.index < 3

div className: 'contest__art-list',
div className: 'contest__vote-summary--art',
Expand Down
6 changes: 3 additions & 3 deletions resources/js/contest-voting/art-entry.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export class ArtEntry extends React.Component
showUserLink = @props.entry.user?.id?
thumbnailShape = @props.contest.thumbnail_shape
galleryId = "contest-#{@props.contest.id}"
buttonId = "#{galleryId}:#{@props.displayIndex}"
buttonId = "#{galleryId}:#{@props.entry.id}"
hideVoteButton = (@props.selected.length >= @props.contest.max_votes || votingOver) && !isSelected

if showVotes
place = @props.displayIndex + 1
place = @props.index + 1
top3 = place <= 3
usersVotedPercentage = _.round((@props.entry.results.votes / @props.contest.users_voted_count)*100, 2)

Expand All @@ -39,7 +39,7 @@ export class ArtEntry extends React.Component
entryLinkProps['data-width'] = @props.entry.artMeta.width
entryLinkProps['data-height'] = @props.entry.artMeta.height
entryLinkProps['data-gallery-id'] = galleryId
entryLinkProps['data-index'] = @props.displayIndex
entryLinkProps['data-index'] = @props.galleryIndex
entryLinkProps['data-button-id'] = buttonId
else
entryLinkProps.rel = 'nofollow noreferrer'
Expand Down

0 comments on commit d35b23c

Please sign in to comment.