Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion functions/_middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const MOVED_APP_PAGES = new Set(['/player', '/fullscreen', '/addons', '/credits'
const PROJECT_PAGE = /^\/\d+(?:\/(editor|fullscreen))?$/;
const PROJECT_PAGE_ASSETS = {editor: '/editor', fullscreen: '/fullscreen'};
const FILE_PATH = /\/[^/]+\.(?!html$)[A-Za-z0-9]+$/;
const PROJECT_CODE_PATH = /^\/code(?:\/(?:commits|branches|pulls|releases)|\/(?:tree|blob)(?:\/[^/]+)+)?$/;
const PROJECT_CODE_PATH =
/^\/code(?:\/(?:commits|branches|pulls|releases|issues)|\/issues\/\d+|\/(?:tree|blob)(?:\/[^/]+)+)?$/;
// The app pages live at the root, but people guess /editor/fullscreen and the like from the editor's URL.
const EDITOR_PREFIXED_APP_PAGE = /^\/editor(\/[^/]+)$/;
// Standalone HTML entries with their own tags; the community SPA is index.html.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scratch-gui",
"version": "3.10.0",
"version": "3.11.0",
"private": true,
"description": "MistWarp editor, player, and community site",
"author": "MistWarp contributors",
Expand Down
2 changes: 2 additions & 0 deletions src/community/api/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default {
request(`/projects/${id}/comments/${commentId}/react`, {method: 'POST', body: {type}}),
pinComment: (id, commentId, pinned) =>
request(`/projects/${id}/comments/${commentId}/pin`, {method: 'POST', body: {pinned}}),
setCommentIssue: (id, commentId, state) =>
request(`/projects/${id}/comments/${commentId}/issue`, {method: 'PUT', body: {state}}),
reactProfileComment: (name, commentId, type) =>
request(`/users/${encodeURIComponent(name)}/comments/${commentId}/react`, {method: 'POST', body: {type}}),
pinProfileComment: (name, commentId, pinned) =>
Expand Down
8 changes: 7 additions & 1 deletion src/community/api/query.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const commentQuery = ({offset = 0, limit = 20, anchor = '', all = false, sort = 'newest'} = {}) => {
export const commentQuery = ({
offset = 0, limit = 20, anchor = '', all = false, sort = 'newest', issue = '', number = 0
} = {}) => {
const params = new URLSearchParams();
if (all) {
params.set('all', '1');
Expand All @@ -8,6 +10,10 @@ export const commentQuery = ({offset = 0, limit = 20, anchor = '', all = false,
}
if (anchor) params.set('anchor', anchor);
if (sort === 'donations') params.set('sort', 'donations');
if (['open', 'done', 'any'].includes(issue)) {
params.set('issue', issue);
if (Number(number) > 0) params.set('number', String(Math.floor(Number(number))));
}
return params.toString();
};

Expand Down
44 changes: 44 additions & 0 deletions src/community/comment-issues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {sameUser} from './format';

export const ISSUE_FILTERS = ['open', 'done'];

export const commentIssueState = comment => {
const state = comment && comment.issue && comment.issue.state;
return state === 'open' || state === 'done' ? state : '';
};

export const commentIssueNumber = comment => {
if (!commentIssueState(comment)) return 0;
const number = Number(comment.issue.number);
return Number.isFinite(number) && number > 0 ? number : 0;
};

export const issueTitle = (content, limit = 120) => {
const line = String(content || '').split('\n')
.map(part => part.trim())
.find(Boolean) || '';
return line.length > limit ? `${line.slice(0, limit - 1).trimEnd()}…` : line;
};

export const canChangeIssue = (comment, user, canTriage) => Boolean(user && comment && !comment.parent) &&
(Boolean(canTriage) || sameUser(comment.author, user.username));

export const mergeCommentUpdate = (comment, update) => {
const next = {...comment, ...update};
if (!update || !update.issue) delete next.issue;
return next;
};

export const issueThreads = comments => {
const replies = new Map();
for (const comment of comments || []) {
if (!comment.parent) continue;
if (!replies.has(comment.parent)) replies.set(comment.parent, []);
replies.get(comment.parent).push(comment);
}
for (const list of replies.values()) list.sort((a, b) => (a.created || 0) - (b.created || 0));
return (comments || [])
.filter(comment => !comment.parent && commentIssueState(comment))
.sort((a, b) => commentIssueNumber(b) - commentIssueNumber(a))
.map(root => ({root, replies: replies.get(root.id) || []}));
};
93 changes: 88 additions & 5 deletions src/community/components/CommentThread.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import {getCommunityLocale} from '../locale.js';
import {useCommunityIntl as useCommunityText} from '../i18n.jsx';
import React, {useEffect, useState, useCallback, useMemo, useRef} from 'react';
import {Link} from 'react-router-dom';
import {Reply, Search, MoreHorizontal, MessageSquare, Pencil, Flag, Trash2, Coins, Pin, Trophy} from 'lucide-react';
import {
Reply, Search, MoreHorizontal, MessageSquare, Pencil, Flag, Trash2, Coins, Pin, Trophy, CircleDot, CircleCheck,
CircleSlash, RotateCcw
} from 'lucide-react';
import {useUser} from '../UserContext.jsx';
import useAfterLogin from '../use-after-login.js';
import Avatar from './Avatar.jsx';
Expand All @@ -21,6 +24,7 @@ import {timeAgo, sameUser, formatPlaytime} from '../format';
import {payWithRotur} from '../../lib/rotur/payment-window.js';
import useLatest from '../use-latest.js';
import {readSessionDraft, writeSessionDraft} from '../session-draft.js';
import {commentIssueNumber, commentIssueState, mergeCommentUpdate} from '../comment-issues.js';
import styles from './CommentThread.module.css';

const commentKindOptions = text => [
Expand Down Expand Up @@ -87,10 +91,25 @@ const kindLabel = (kind, text) => commentKindOptions(text).find(item => item.val
const CommentRow = ({
comment, onReply, onDelete, onEdit, onSaveEdit, onCancelEdit, onReact, onPin, onReport, canReply, canDelete,
canEdit, canPin, canReport, deleting, editing, editText, editBusy, onEditTextChange, reacting, pinning,
isReply, id, authorBadge
isReply, id, authorBadge, canIssue, canTrackIssue, onIssue, issueBusy, issueHref
}) => {
const {text: communityText} = useCommunityText();
const hasMenu = canEdit || canPin || canReport || canDelete;
const issueState = commentIssueState(comment);
const issueNumber = commentIssueNumber(comment);
const showIssueActions = Boolean(canIssue && (issueState || canTrackIssue));
const hasMenu = canEdit || canPin || canReport || canDelete || showIssueActions;
const issueLabel = issueState === 'done' ?
communityText('Done #{value1}', {value1: issueNumber}) :
communityText('Issue #{value1}', {value1: issueNumber});
const issueBadge = issueState ? (
<React.Fragment>
{issueState === 'done' ?
<CircleCheck size={11} aria-hidden="true" /> :
<CircleDot size={11} aria-hidden="true" />}
{issueLabel}
</React.Fragment>
) : null;
const issueClass = `${styles.issue} ${issueState === 'done' ? styles.issueDone : ''}`;
const donationTier = commentDonationTier(donationAmount(comment));
return (
<div
Expand Down Expand Up @@ -143,6 +162,9 @@ const CommentRow = ({
{communityText('Edited')}
</span>
) : null}
{issueState && issueHref ? (
<Link className={issueClass} to={issueHref(issueNumber)}>{issueBadge}</Link>
) : issueState ? <span className={issueClass}>{issueBadge}</span> : null}
{comment.pinned ? (
<span className={styles.pinned} title={communityText('Pinned comment')}>
<Pin size={11} />
Expand Down Expand Up @@ -191,6 +213,33 @@ const CommentRow = ({
<Pin size={14} />
{comment.pinned ? communityText('Unpin') : communityText('Pin to top')}
</DropdownItem> : null}
{showIssueActions && canTrackIssue && !issueState ? <DropdownItem
disabled={issueBusy}
onClick={() => {
close(); onIssue('open');
}}
><CircleDot size={14} />{communityText('Track as issue')}</DropdownItem> : null}
{showIssueActions && canTrackIssue && issueState === 'open' ? <DropdownItem
disabled={issueBusy}
onClick={() => {
close(); onIssue('done');
}}
><CircleCheck size={14} />{communityText('Mark as done')}</DropdownItem> : null}
{showIssueActions && canTrackIssue && issueState === 'done' ? <DropdownItem
disabled={issueBusy}
onClick={() => {
close(); onIssue('open');
}}
><RotateCcw size={14} />{communityText('Reopen issue')}</DropdownItem> : null}
{showIssueActions && issueState ? <DropdownItem
disabled={issueBusy}
onClick={() => {
close(); onIssue('none');
}}
>
<CircleSlash size={14} />
{communityText('Stop tracking as issue')}
</DropdownItem> : null}
{canReport ? <DropdownItem
onClick={() => {
close(); onReport();
Expand Down Expand Up @@ -327,7 +376,7 @@ const InlineComposer = ({

const CommentThread = ({
source, canModerate, canPin = false, disabled, disabledReason, reportContext, projectComments = false,
composerAction, onCountChange = null, donationRecipient = '', draftKey = '', authorBadges = null
composerAction, onCountChange = null, donationRecipient = '', draftKey = '', authorBadges = null, issues = null
}) => {
const {text: communityText} = useCommunityText();
const {user} = useUser();
Expand Down Expand Up @@ -358,6 +407,7 @@ const CommentThread = ({
const [editBusy, setEditBusy] = useState(false);
const [reactingIds, setReactingIds] = useState({});
const [pinningIds, setPinningIds] = useState({});
const [issueIds, setIssueIds] = useState({});
const [rootLimit, setRootLimit] = useState(ROOT_PAGE);
const [totalRoots, setTotalRoots] = useState(0);
const [nextOffset, setNextOffset] = useState(0);
Expand Down Expand Up @@ -532,7 +582,7 @@ const CommentThread = ({
}
if (event.type === 'comment_edited' && event.comment) {
setComments(current => current.map(comment => (
comment.id === event.comment.id ? {...comment, ...event.comment} : comment
comment.id === event.comment.id ? mergeCommentUpdate(comment, event.comment) : comment
)));
return;
}
Expand Down Expand Up @@ -773,6 +823,32 @@ const CommentThread = ({
}
};

const setIssue = async (commentId, state) => {
if (!source.issue || !user) return;
const actionSource = source;
const actionViewer = viewerName;
const releaseAction = beginAction(actionSource, actionViewer, `issue:${commentId}`);
if (!releaseAction) return;
markPending(setIssueIds, commentId, true);
setError(null);
try {
const result = await actionSource.issue(commentId, state);
if (sourceRef.current !== actionSource || viewerRef.current !== actionViewer) return;
if (result && result.comment) {
setComments(cs => cs.map(c => (c.id === commentId ? mergeCommentUpdate(c, result.comment) : c)));
}
} catch (e) {
if (sourceRef.current === actionSource && viewerRef.current === actionViewer) {
setError(e.message || communityText('Could not update the issue.'));
}
} finally {
releaseAction();
if (sourceRef.current === actionSource && viewerRef.current === actionViewer) {
markPending(setIssueIds, commentId, false);
}
}
};

const openReply = (rootId, prefill = '') => {
setReplyTo(rootId);
setReplyText(prefill);
Expand All @@ -783,6 +859,8 @@ const CommentThread = ({
(canModerate || user.isAdmin || sameUser(comment.author, user.username));
const canEdit = comment => Boolean(source.edit && user) && sameUser(comment.author, user.username);
const canPinComment = comment => Boolean(canPin && source.pin && user) && !comment.parent;
const canIssueComment = comment => Boolean(issues && source.issue && user) && !comment.parent &&
(Boolean(issues.canTriage) || sameUser(comment.author, user.username));
const canReport = comment => Boolean(user) && !sameUser(comment.author, user.username);
const authorBadgeFor = author => (authorBadges && author ? authorBadges[String(author).toLowerCase()] || '' : '');
const canReply = Boolean(user) && !disabled;
Expand Down Expand Up @@ -936,6 +1014,11 @@ const CommentThread = ({
canDelete={canDelete(comment)}
canEdit={canEdit(comment)}
canPin={canPinComment(comment)}
canIssue={canIssueComment(comment)}
canTrackIssue={Boolean(issues && issues.enabled)}
onIssue={state => setIssue(comment.id, state)}
issueBusy={Boolean(issueIds[comment.id])}
issueHref={issues && issues.href}
editing={editingId === comment.id}
editBusy={editBusy}
canReport={canReport(comment)}
Expand Down
23 changes: 23 additions & 0 deletions src/community/components/CommentThread.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,29 @@
font-size: var(--fs-xs);
}

.issue {
display: inline-flex;
align-items: center;
gap: 3px;
padding: 2px 7px;
border-radius: var(--radius-2xs);
background: color-mix(in srgb, var(--mw-success) 16%, transparent);
color: var(--mw-success);
font-size: var(--fs-2xs);
font-weight: 700;
white-space: nowrap;
text-decoration: none;
}

.issueDone {
background: var(--accent-softer);
color: var(--accent-strong);
}

a.issue:hover {
text-decoration: underline;
}

.pinned {
display: inline-flex;
align-items: center;
Expand Down
3 changes: 3 additions & 0 deletions src/community/pages/ManageProject.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ const ManageProject = () => {
brandingTagline: project.branding?.tagline || '',
remixShare: project.remixShare || 0,
commentsOff: Boolean(project.commentsOff),
issuesOff: Boolean(project.issuesOff),
remixable: project.remixable !== false,
seeInside: project.seeInside !== false,
visibility: project.visibility || (project.shared ? 'public' : 'private')
Expand Down Expand Up @@ -304,6 +305,7 @@ const ManageProject = () => {
tagline: form.brandingTagline.trim()
} : {},
commentsOff: form.commentsOff,
issuesOff: form.issuesOff,
remixable: form.remixable,
seeInside: form.seeInside,
remixShare: Math.max(0, Math.min(50, Number(form.remixShare) || 0))
Expand Down Expand Up @@ -660,6 +662,7 @@ const ManageProject = () => {
<SwitchRow checked={form.seeInside} disabled={saving} label={communityText('Allow people to see inside')} onChange={value => set('seeInside', value)} />
<p className={styles.cardHint}>{communityText('When enabled, See inside gives access to project files and version history.')}</p>
<SwitchRow checked={form.commentsOff} disabled={saving} label={communityText('Turn off comments')} onChange={value => set('commentsOff', value)} />
<SwitchRow checked={form.issuesOff} disabled={saving} label={communityText('Turn off issues')} description={communityText('Stops new comments from being tracked as issues. Existing issues stay readable.')} onChange={value => set('issuesOff', value)} />
</div>
<div className={styles.formActions}>
<span className={styles.formStatus} role="status" aria-live="polite">{status}</span>
Expand Down
1 change: 1 addition & 0 deletions src/community/pages/Project.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ const Project = () => {
edit: (commentId, content) => api.editComment(id, commentId, content),
react: (commentId, type) => api.reactComment(id, commentId, type),
pin: (commentId, pinned) => api.pinComment(id, commentId, pinned),
issue: (commentId, state) => api.setCommentIssue(id, commentId, state),
subscribe: listener => projectRealtime.subscribe(
id,
listener,
Expand Down
Loading