From 674f584b3be5513ffe71ee4bfb8912639350146c Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Mon, 23 Mar 2020 14:40:32 +0000 Subject: [PATCH] Move baseURL into a helper function --- app/talk/board-preview.cjsx | 6 +++--- app/talk/board.cjsx | 6 +++--- app/talk/comment-link.cjsx | 4 ++-- app/talk/comment.cjsx | 13 +++++-------- app/talk/discussion-preview.cjsx | 10 +++++----- app/talk/init.cjsx | 6 +++--- app/talk/latest-comment-link.cjsx | 9 ++++----- app/talk/lib/base-url.js | 1 + app/talk/popular-tags.jsx | 3 ++- app/talk/recents.cjsx | 4 ++-- 10 files changed, 30 insertions(+), 32 deletions(-) create mode 100644 app/talk/lib/base-url.js diff --git a/app/talk/board-preview.cjsx b/app/talk/board-preview.cjsx index 1616a921de..e9f2b578f4 100644 --- a/app/talk/board-preview.cjsx +++ b/app/talk/board-preview.cjsx @@ -4,6 +4,7 @@ createReactClass = require 'create-react-class' {Link} = require 'react-router' resourceCount = require './lib/resource-count' LatestCommentLink = require './latest-comment-link' +baseURL = require('./lib/base-url').default module.exports = createReactClass displayName: 'TalkBoardDisplay' @@ -17,10 +18,9 @@ module.exports = createReactClass boardLink: -> {owner, name} = @props.params boardId = @props.data.id - baseURL = @props.project?._type._name - if baseURL - + if @props.project + {@props.data.title} else diff --git a/app/talk/board.cjsx b/app/talk/board.cjsx index 0f32734ba5..85a85baf8c 100644 --- a/app/talk/board.cjsx +++ b/app/talk/board.cjsx @@ -20,6 +20,7 @@ merge = require 'lodash/merge' talkConfig = require './config' SignInPrompt = require '../partials/sign-in-prompt' alert = require('../lib/alert').default +baseURL = require('./lib/base-url').default `import ActiveUsers from './active-users';` ProjectLinker = require './lib/project-linker' @@ -211,7 +212,6 @@ module.exports = createReactClass render: -> - baseURL = @props.project?._type._name {board} = @state discussionsMeta = @state.discussions[0]?.getMeta() @@ -233,7 +233,7 @@ module.exports = createReactClass

Moderator Zone:

{if @props.section isnt 'zooniverse' - View Reported Comments + View Reported Comments else View Reported Comments } @@ -300,7 +300,7 @@ module.exports = createReactClass {if @props.section is 'zooniverse' Recent Comments else - + Recent Comments } diff --git a/app/talk/comment-link.cjsx b/app/talk/comment-link.cjsx index d55c0b76ef..0a428ece97 100644 --- a/app/talk/comment-link.cjsx +++ b/app/talk/comment-link.cjsx @@ -1,6 +1,7 @@ React = require 'react' PropTypes = require 'prop-types' createReactClass = require 'create-react-class' +baseURL = require('./lib/base-url').default talkConfig = require './config' {Link} = require 'react-router' @@ -20,9 +21,8 @@ module.exports = createReactClass @props.comment.section isnt 'zooniverse' projectCommentUrl: -> - baseURL = @props.project?._type._name {comment, project} = @props - "/#{baseURL}/#{project.slug}/talk/#{comment.board_id}/#{comment.discussion_id}?comment=#{comment.id}" + "/#{baseURL(project)}/#{project.slug}/talk/#{comment.board_id}/#{comment.discussion_id}?comment=#{comment.id}" mainTalkCommentUrl: -> {comment} = @props diff --git a/app/talk/comment.cjsx b/app/talk/comment.cjsx index dd6acdf05c..7b80b2f83b 100644 --- a/app/talk/comment.cjsx +++ b/app/talk/comment.cjsx @@ -18,6 +18,7 @@ SubjectViewer = require '../components/subject-viewer' SingleSubmitButton = require '../components/single-submit-button' DisplayRoles = require './lib/display-roles' CommentContextIcon = require './lib/comment-context-icon' +baseURL = require('./lib/base-url').default `import WrappedMarkdown from '../components/wrapped-markdown';` DEFAULT_AVATAR = '/assets/simple-avatar.png' @@ -107,9 +108,8 @@ module.exports = createReactClass commentSubjectTitle: (comment, subject) -> {owner, name} = @props.params - baseURL = @props.project?._type._name if (comment.focus_type is 'Subject') and (owner and name) - + Subject {subject.id} else @@ -131,8 +131,7 @@ module.exports = createReactClass replyLine: (comment) -> baseLink = "/" if @props.project? - baseURL = @props.project?._type._name - baseLink += "#{baseURL}/#{@props.project.slug}/" + baseLink += "#{baseURL(@props.project)}/#{@props.project.slug}/"

{comment.user_display_name} @@ -170,8 +169,7 @@ module.exports = createReactClass isDeleted = if @props.data.is_deleted then 'deleted' else '' profile_link = "/users/#{@props.author?.login}" if @props.project? - baseURL = @props.project._type._name - profile_link = "/#{baseURL}/#{@props.project.slug}#{profile_link}" + profile_link = "/#{baseURL(@props.project)}/#{@props.project.slug}#{profile_link}" author_login = if @props.author?.login then "@#{@props.author.login}" else ""

@@ -191,8 +189,7 @@ module.exports = createReactClass {if @props.data.reply_id profile_link = "/users/#{@props.data.reply_user_login}" if @props.project? - baseURL = @props.project?._type._name - profile_link = "/#{baseURL}/#{@props.project.slug}#{profile_link}" + profile_link = "/#{baseURL(@props.project)}/#{@props.project.slug}#{profile_link}"
{if @state.replies.length
diff --git a/app/talk/discussion-preview.cjsx b/app/talk/discussion-preview.cjsx index 0f8a8a13e1..1ef5cd8791 100644 --- a/app/talk/discussion-preview.cjsx +++ b/app/talk/discussion-preview.cjsx @@ -4,6 +4,7 @@ createReactClass = require 'create-react-class' {Link} = require 'react-router' resourceCount = require './lib/resource-count' LatestCommentLink = require './latest-comment-link' +baseURL = require('./lib/base-url').default getSubjectLocation = require '../lib/get-subject-location' # `import Thumbnail from '../components/thumbnail';` @@ -20,14 +21,13 @@ module.exports = createReactClass discussionLink: -> {discussion, project} = @props - baseURL = project?._type?._name - if (baseURL && @props.params?.owner and @props.params?.name) # get from url if possible + if (project && @props.params?.owner and @props.params?.name) # get from url if possible {owner, name} = @props.params - "/#{baseURL}/#{owner}/#{name}/talk/#{discussion.board_id}/#{discussion.id}" + "/#{baseURL(project)}/#{owner}/#{name}/talk/#{discussion.board_id}/#{discussion.id}" - else if (baseURL && project.slug) # otherwise fetch from project - "/#{baseURL}/#{project.slug}/talk/#{discussion.board_id}/#{discussion.id}" + else if (project && project.slug) # otherwise fetch from project + "/#{baseURL(project)}/#{project.slug}/talk/#{discussion.board_id}/#{discussion.id}" else # link to zooniverse main talk "/talk/#{discussion.board_id}/#{discussion.id}" diff --git a/app/talk/init.cjsx b/app/talk/init.cjsx index a1a71afccb..711cbb9d17 100644 --- a/app/talk/init.cjsx +++ b/app/talk/init.cjsx @@ -14,6 +14,7 @@ Loading = require('../components/loading-indicator').default SingleSubmitButton = require '../components/single-submit-button' ZooniverseTeam = require './lib/zoo-team.cjsx' alert = require('../lib/alert').default +baseURL = require('./lib/base-url').default AddZooTeamForm = require './add-zoo-team-form' DragReorderable = require 'drag-reorderable' Paginator = require './lib/paginator' @@ -139,7 +140,6 @@ module.exports = createReactClass @setBoards() render: -> - baseURL = @props.project?._type._name
{if @props.user?
@@ -165,7 +165,7 @@ module.exports = createReactClass {if @props.section isnt 'zooniverse' - + View Reported Comments else @@ -201,7 +201,7 @@ module.exports = createReactClass {if @props.section is 'zooniverse' Recent Comments else - Recent Comments + Recent Comments } diff --git a/app/talk/latest-comment-link.cjsx b/app/talk/latest-comment-link.cjsx index 3c67dd2c6d..bd4c281612 100644 --- a/app/talk/latest-comment-link.cjsx +++ b/app/talk/latest-comment-link.cjsx @@ -3,6 +3,7 @@ PropTypes = require 'prop-types' createReactClass = require 'create-react-class' talkClient = require 'panoptes-client/lib/talk-client' {timeAgo} = require './lib/time' +baseURL = require('./lib/base-url').default DisplayRoles = require './lib/display-roles' Avatar = require '../partials/avatar' {Link} = require 'react-router' @@ -49,15 +50,14 @@ module.exports = createReactClass @setState({latestCommentText}) if latestCommentText discussionLink: (childtext = '', query = {}, className = '') -> - baseURL = @props.project?._type._name if className is "latest-comment-time" logClick = @context.geordi?.makeHandler? 'discussion-time' locationObject = pathname: "/talk/#{@props.discussion.board_id}/#{@props.discussion.id}" query: query - if baseURL and @props.params?.owner and @props.params?.name + if @props.project and @props.params?.owner and @props.params?.name {owner, name} = @props.params - locationObject.pathname = "/#{baseURL}/#{owner}/#{name}" + locationObject.pathname + locationObject.pathname = "/#{baseURL(@props.project)}/#{owner}/#{name}" + locationObject.pathname {childtext} @@ -75,8 +75,7 @@ module.exports = createReactClass baseLink = "/" if @props.project? and @props.project.slug? - baseURL = @props.project?._type._name - baseLink += "#{baseURL}/#{@props.project.slug}/" + baseLink += "#{baseURL(@props.project)}/#{@props.project.slug}/"
diff --git a/app/talk/lib/base-url.js b/app/talk/lib/base-url.js new file mode 100644 index 0000000000..085d2f4ffe --- /dev/null +++ b/app/talk/lib/base-url.js @@ -0,0 +1 @@ +export default resource => resource && resource._type._name \ No newline at end of file diff --git a/app/talk/popular-tags.jsx b/app/talk/popular-tags.jsx index 1ee21f5ff4..118937c367 100644 --- a/app/talk/popular-tags.jsx +++ b/app/talk/popular-tags.jsx @@ -6,9 +6,10 @@ import { Link } from 'react-router'; const ProjectTag = (props) => { const tag = props.tag.name; + const baseURL = props.project._type._name; return (
- + {tag} {' '} diff --git a/app/talk/recents.cjsx b/app/talk/recents.cjsx index c4e2063bc6..e42270adc0 100644 --- a/app/talk/recents.cjsx +++ b/app/talk/recents.cjsx @@ -9,6 +9,7 @@ Paginator = require './lib/paginator' projectSection = require './lib/project-section' updateQueryParams = require './lib/update-query-params' Loading = require('../components/loading-indicator').default +baseURL = require('./lib/base-url').default talkConfig = require './config' module.exports = createReactClass @@ -114,9 +115,8 @@ module.exports = createReactClass commentTitle: (comment) -> {if @props.params.owner and @props.params.name - baseURL = @props.project?._type._name {owner, name} = @props.params - + {comment.discussion_title} on {comment.board_title} else