diff --git a/functions/_middleware.js b/functions/_middleware.js index 2ce4cd88338..1062329b693 100644 --- a/functions/_middleware.js +++ b/functions/_middleware.js @@ -59,10 +59,6 @@ const STATIC_META = { title: 'Themes - MistWarp', description: 'Browse community-made editor themes for MistWarp.' }, - '/groups': { - title: 'Groups - MistWarp', - description: 'Organisations that share projects, spaces, members, and funding on MistWarp.' - }, '/posts': { title: 'Posts - MistWarp', description: 'Popular posts from claw, the Rotur social network, on MistWarp.' @@ -293,8 +289,27 @@ const vanityPullMeta = async (slug, index) => { return pullMeta(data.id, index); }; +const orgMeta = async name => { + const data = await apiJson(`/orgs/${encodeURIComponent(name)}`); + const org = data && data.org; + if (!org) return null; + const username = org.username || name; + const title = org.displayName || username; + return { + title: `${title} - MistWarp`, + description: flatten(org.bio) || + `${title} has shared ${(data.projects || []).length} projects on MistWarp.`, + image: `${AVATARS}/${encodeURIComponent(username.toLowerCase())}`, + card: 'summary' + }; +}; + +const ownedByOrg = data => (data.projects || []).some(project => project && project.ownerType === 'org'); + const userMeta = async (name, suffix) => { const data = await apiJson(`/users/${encodeURIComponent(name)}`); + const org = (!data || data.exists !== true || ownedByOrg(data)) && !suffix ? await orgMeta(name) : null; + if (org) return org; if (!data || data.exists !== true) { return { title: 'Profile - MistWarp', @@ -337,25 +352,6 @@ const spaceMeta = async id => { }; }; -const groupMeta = async tag => { - const data = await apiJson(`/groups/${encodeURIComponent(tag)}`); - const group = data && data.group; - if (!group) { - return { - title: 'Group - MistWarp', - description: 'View this MistWarp group.' - }; - } - const projects = data.projects || []; - return { - title: `${group.name || tag} - MistWarp`, - description: flatten(group.description) || - `${group.name || tag} has shared ${projects.length} projects on MistWarp.`, - image: group.icon_url || DEFAULT_IMAGE, - card: 'summary' - }; -}; - const newsMeta = async id => { const data = await apiJson(`/news/${encodeURIComponent(id)}`); const item = data && data.item; @@ -452,6 +448,15 @@ const legacyEmbedRedirect = url => { return permanent(`${url.origin}/embed${url.search}#${/^\d+$/.test(id) ? id : `mw-${id}`}`); }; +const ORG_PAGE = /^\/orgs\/([^/]+)$/; +const GROUP_PAGE = /^\/groups(?:\/[^/]+)?$/; + +const renamedPagePath = path => { + const org = path.match(ORG_PAGE); + if (org) return `/users/${org[1]}`; + return GROUP_PAGE.test(path) ? '/explore' : path; +}; + const editorHostRoute = url => { const path = pagePath(url.pathname); if (path === '/' || path === '/editor') { @@ -463,18 +468,18 @@ const editorHostRoute = url => { return project ? {asset: PROJECT_PAGE_ASSETS[project[1]] || '/player'} : {asset: null}; } if (isFilePath(url.pathname)) return {asset: null}; - return {redirect: `${ACCOUNT_ORIGIN}${path}${url.search}`}; + return {redirect: `${ACCOUNT_ORIGIN}${renamedPagePath(path)}${url.search}`}; }; const accountHostRoute = url => { - const path = pagePath(url.pathname); + const path = renamedPagePath(pagePath(url.pathname)); if (path === '/editor') return `${EDITOR_ORIGIN}/${url.search}`; if (MOVED_APP_PAGES.has(path) || PROJECT_PAGE.test(path)) return `${EDITOR_ORIGIN}${path}${url.search}`; return path === url.pathname ? null : `${url.origin}${path}${url.search}`; }; const otherHostRoute = url => { - const path = pagePath(url.pathname); + const path = renamedPagePath(pagePath(url.pathname)); return path === url.pathname ? null : `${url.origin}${path}${url.search}`; }; @@ -549,12 +554,6 @@ const metaForPath = pathname => { return NOT_FOUND_META; } - match = normalizedPath.match(/^\/groups\/([^/]+)$/); - if (match) { - const tag = decodeSegment(match[1]); - return tag === null ? NOT_FOUND_META : groupMeta(tag); - } - match = normalizedPath.match(/^\/news\/([^/]+)$/); if (match) { const id = decodeSegment(match[1]); diff --git a/package.json b/package.json index f4baae8a2b3..c1cc9e20a35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scratch-gui", - "version": "3.14.0", + "version": "3.15.0", "private": true, "description": "MistWarp editor, player, and community site", "author": "MistWarp contributors", diff --git a/src/community/App.jsx b/src/community/App.jsx index 39ff9738f33..f8d3c287025 100644 --- a/src/community/App.jsx +++ b/src/community/App.jsx @@ -32,7 +32,8 @@ const PullRequests = lazy(() => import('./pages/PullRequests.jsx')); const Commit = lazy(() => import('./pages/Commit.jsx')); const ProjectCode = lazy(() => import('./pages/ProjectCode.jsx')); const RemixTree = lazy(() => import('./pages/RemixTree.jsx')); -const Profile = lazy(() => import('./pages/Profile.jsx')); +const Account = lazy(() => import('./pages/Account.jsx')); +const OrgRedirect = lazy(() => import('./pages/Account.jsx').then(module => ({default: module.OrgRedirect}))); const UserLibrary = lazy(() => import('./pages/UserLibrary.jsx')); const Following = lazy(() => import('./pages/Following.jsx')); const Settings = lazy(() => import('./pages/Settings.jsx')); @@ -58,8 +59,6 @@ const Status = lazy(() => import('./pages/Status.jsx')); const PaidPerks = lazy(() => import('./pages/PaidPerks.jsx')); const Themes = lazy(() => import('./pages/Themes.jsx')); const Theme = lazy(() => import('./pages/Theme.jsx')); -const Groups = lazy(() => import('./pages/Groups.jsx')); -const Group = lazy(() => import('./pages/Group.jsx')); const Classroom = lazy(() => import('./pages/Classroom.jsx')); const ClassroomClass = lazy(() => import('./pages/ClassroomClass.jsx')); const ClassroomStudent = lazy(() => import('./pages/ClassroomStudent.jsx')); @@ -78,8 +77,6 @@ const ROUTE_TITLES = [ ['/random', 'Random project'], ['/themes/', 'Theme'], ['/themes', 'Themes'], - ['/groups/', 'Group'], - ['/groups', 'Groups'], ['/classroom/join', 'Student sign-in'], ['/classroom/claim', 'Move to your own account'], ['/classroom/school', 'School'], @@ -110,6 +107,7 @@ const ROUTE_TITLES = [ ['/status', 'Service status'], ['/admin', 'Admin'], ['/users/', 'Profile'], + ['/orgs/', 'Organisation'], ['/p/', 'Project'], ['/project/', 'Project'] ]; @@ -246,8 +244,6 @@ const App = () => { } /> } /> } /> - } /> - } /> }> } /> } /> @@ -276,7 +272,8 @@ const App = () => { } /> } /> } /> - } /> + } /> + } /> } /> { setUser(normalizeUser(baseUser ? { ...baseUser, isNew: isNewAccount(me), - group_tag: roturProfile?.group_tag || '', subscription: roturProfile?.subscription || baseUser.subscription || '' } : null)); }, []); @@ -127,7 +126,6 @@ const UserProvider = ({children}) => { const nextUser = normalizeUser({ ...user, ...(me || {}), - group_tag: roturProfile?.group_tag || '', subscription: roturProfile?.subscription || (me && me.subscription) || user.subscription || '' }); setUser(nextUser); diff --git a/src/community/api/users.js b/src/community/api/users.js index b97249d2e2f..7cf7f1aa785 100644 --- a/src/community/api/users.js +++ b/src/community/api/users.js @@ -8,5 +8,6 @@ export default { request(`/users/${encodeURIComponent(name)}/projects?offset=${offset}&limit=${limit}`), searchUsers: (q, {limit = 8} = {}) => request(`/search/users?q=${encodeURIComponent(q)}&limit=${limit}`), activity: users => request(`/activity?users=${encodeURIComponent(users.join(','))}`), - group: tag => request(`/groups/${encodeURIComponent(tag)}`) + org: name => request(`/orgs/${encodeURIComponent(name)}`), + myOrgs: () => request('/me/orgs', {cache: false}) }; diff --git a/src/community/components/CommentThread.jsx b/src/community/components/CommentThread.jsx index a0bc70675e3..a33944adc07 100644 --- a/src/community/components/CommentThread.jsx +++ b/src/community/components/CommentThread.jsx @@ -18,7 +18,6 @@ import Notice from './ui/Notice.jsx'; import StatusMessage from './ui/StatusMessage.jsx'; import SelectMenu from './ui/SelectMenu.jsx'; import RichText from './RichText.jsx'; -import GroupTag from './GroupTag.jsx'; import Dropdown, {DropdownItem} from './ui/Dropdown.jsx'; import {timeAgo, sameUser, formatPlaytime} from '../format'; import {payWithRotur} from '../../lib/rotur/payment-window.js'; @@ -130,7 +129,6 @@ const CommentRow = ({ to={`/users/${comment.author}`} className={styles.author} >{comment.author} - {authorBadge ? (