diff --git a/package.json b/package.json index 45d4b45069b..f4baae8a2b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scratch-gui", - "version": "3.13.0", + "version": "3.14.0", "private": true, "description": "MistWarp editor, player, and community site", "author": "MistWarp contributors", diff --git a/src/community/api/git.js b/src/community/api/git.js index 43c7e5d2d2d..42d33e3ae37 100644 --- a/src/community/api/git.js +++ b/src/community/api/git.js @@ -7,7 +7,7 @@ const updateCommit = (id, sha, patch) => request( ); export default { - commits: id => request(`/projects/${id}/commits`), + commits: id => request(`/projects/${id}/commits`, {cache: false}), branches: id => request(`/projects/${id}/branches`), createBranch: (id, name, from) => request(`/projects/${id}/branches`, { method: 'POST', @@ -66,7 +66,7 @@ export default { updateCommit, setCommitCoAuthors: (id, sha, coAuthors) => updateCommit(id, sha, {coAuthors}), pulls: id => request(`/projects/${id}/pulls`), - getPull: (id, index) => request(`/projects/${id}/pulls/${index}`), + getPull: (id, index) => request(`/projects/${id}/pulls/${index}`, {cache: false}), pullTimeline: (id, index) => request(`/projects/${id}/pulls/${index}/timeline`), addPullComment: (id, index, content) => request(`/projects/${id}/pulls/${index}/comments`, {method: 'POST', body: {content}}), @@ -82,8 +82,11 @@ export default { }), mergePull: (id, index) => request(`/projects/${id}/pulls/${index}/merge`, {method: 'POST'}), closePull: (id, index) => request(`/projects/${id}/pulls/${index}/close`, {method: 'POST'}), - uploadPullMerge: (id, {sb3, mergeTree, expectedHead, pullId}) => - uploadProject(id, sb3, null, null, {mergeTree, expectedHead, pullId}), + uploadPullMerge: (id, {sb3, mergeTree, expectedHead, pullId, sourceHead}) => + uploadProject(id, sb3, null, null, {mergeTree, expectedHead, pullId, mergeSourceHead: sourceHead}), + syncRemix: id => request(`/projects/${id}/remix/sync`, {method: 'POST', timeoutMs: SLOW_GET_TIMEOUT}), + uploadRemixSync: (id, {sb3, mergeTree, expectedHead, syncHead}) => + uploadProject(id, sb3, null, null, {mergeTree, expectedHead, syncHead}), uploadBranchMerge: (id, {sb3, mergeTree, sourceBranch, targetBranch, sourceHead, targetHead}) => uploadProject(id, sb3, null, null, { mergeTree, diff --git a/src/community/components/ForkStatus.jsx b/src/community/components/ForkStatus.jsx new file mode 100644 index 00000000000..127b4eac5e6 --- /dev/null +++ b/src/community/components/ForkStatus.jsx @@ -0,0 +1,115 @@ +import PropTypes from 'prop-types'; +import React from 'react'; +import {Link} from 'react-router-dom'; +import {GitFork, RefreshCw} from 'lucide-react'; +import {useCommunityIntl as useCommunityText} from '../i18n.jsx'; +import {remixDivergenceSentence, remixParentLabel, remixSyncUnknown} from '../remix-origin.js'; +import MergeConflicts from './MergeConflicts.jsx'; +import Button from './ui/Button.jsx'; +import Notice from './ui/Notice.jsx'; +import styles from './ForkStatus.module.css'; + +const ForkStatus = ({canContribute, canSync, contributeHref, gitHead, hasUncommitted, projectId, remixFrom, sync}) => { + const {text: communityText} = useCommunityText(); + const {busy, error, notice, session, cancel, chooseBinary, dismissNotice, resolve, updateText} = sync; + const startSync = sync.sync; + const original = remixParentLabel(remixFrom); + const hintId = `fork-sync-hint-${projectId}`; + const showSync = canSync && (remixFrom.behind > 0 || remixSyncUnknown(remixFrom, gitHead)) && !session; + // eslint-disable-next-line max-len + const conflictLead = communityText('This remix and {value1} changed the same files. Edit the text conflicts and choose which version of each asset to keep.', {value1: original}); + + return ( +
+
+

+

+ {canContribute ? ( + + {communityText('Contribute')} + + ) : null} + {showSync ? ( + + ) : null} +
+ {showSync && hasUncommitted ? ( +

+ {communityText('Commit your saved changes in the editor before syncing, so they are not replaced.')} +

+ ) : null} + {error && !session ? {error} : null} + {notice ? {notice} : null} + {session ? ( + + {communityText('Cancel')} + + )} + /> + ) : null} +
+ ); +}; + +ForkStatus.propTypes = { + canContribute: PropTypes.bool, + canSync: PropTypes.bool, + contributeHref: PropTypes.string, + gitHead: PropTypes.string, + hasUncommitted: PropTypes.bool, + projectId: PropTypes.string.isRequired, + remixFrom: PropTypes.shape({ + ahead: PropTypes.number, + behind: PropTypes.number, + head: PropTypes.string, + owner: PropTypes.string, + title: PropTypes.string + }).isRequired, + sync: PropTypes.shape({ + busy: PropTypes.bool, + error: PropTypes.string, + notice: PropTypes.string, + session: PropTypes.object, + sync: PropTypes.func, + resolve: PropTypes.func, + cancel: PropTypes.func, + updateText: PropTypes.func, + chooseBinary: PropTypes.func, + dismissNotice: PropTypes.func + }).isRequired +}; + +export default ForkStatus; diff --git a/src/community/components/ForkStatus.module.css b/src/community/components/ForkStatus.module.css new file mode 100644 index 00000000000..59c0a02cf2e --- /dev/null +++ b/src/community/components/ForkStatus.module.css @@ -0,0 +1,49 @@ +.forkStatusGroup { + display: grid; + gap: var(--space-2); +} + +.forkStatus { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: var(--space-2) var(--space-3); + padding: var(--space-3) var(--space-4); + border-radius: var(--radius-sm); + background: var(--bg-card); + box-shadow: var(--card-shadow); + color: var(--text-dim); + font-size: var(--fs-sm); +} + +.forkMessage { + display: flex; + flex: 1 1 260px; + align-items: flex-start; + gap: var(--space-2); + min-width: 0; + margin: 0; +} + +.forkMessage svg { + flex: none; + margin-top: 2px; + color: var(--text-faint); +} + +.forkAction { + flex: none; + color: var(--accent-strong); + font-weight: 600; +} + +.forkAction:hover { + text-decoration: underline; +} + +.hint { + margin: 0; + padding: 0 var(--space-4); + color: var(--text-dim); + font-size: var(--fs-sm); +} diff --git a/src/community/components/MergeConflicts.jsx b/src/community/components/MergeConflicts.jsx new file mode 100644 index 00000000000..51b625126bd --- /dev/null +++ b/src/community/components/MergeConflicts.jsx @@ -0,0 +1,136 @@ +import PropTypes from 'prop-types'; +import React, {useEffect, useRef} from 'react'; +import {GitMerge} from 'lucide-react'; +import Button from './ui/Button.jsx'; +import Notice from './ui/Notice.jsx'; +import SectionHeading from './ui/SectionHeading.jsx'; +import styles from './MergeConflicts.module.css'; + +let nextConflictId = 0; + +const MergeConflicts = ({ + actions, + binaryConflicts, + busy, + busyLabel, + conflicts, + error, + focusOnMount, + headingLevel, + keepLabel, + lead, + onChoose, + onSubmit, + onTextChange, + submitLabel, + title, + useLabel +}) => { + const sectionRef = useRef(null); + const idPrefix = useRef(null); + if (idPrefix.current === null) { + nextConflictId += 1; + idPrefix.current = `merge-conflicts-${nextConflictId}`; + } + useEffect(() => { + if (focusOnMount && sectionRef.current) sectionRef.current.focus(); + }, []); + const submit = ( + + ); + return ( +
+ + {conflicts.map(file => ( +