Skip to content

Commit

Permalink
Move baseURL into a helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Mar 23, 2020
1 parent fec5057 commit 84995c2
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 32 deletions.
6 changes: 3 additions & 3 deletions app/talk/board-preview.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -17,10 +18,9 @@ module.exports = createReactClass
boardLink: ->
{owner, name} = @props.params
boardId = @props.data.id
baseURL = @props.project?._type._name

if baseURL
<Link to="/#{baseURL}/#{owner}/#{name}/talk/#{boardId}">
if @props.project
<Link to="/#{baseURL(@props.project)}/#{owner}/#{name}/talk/#{boardId}">
{@props.data.title}
</Link>
else
Expand Down
6 changes: 3 additions & 3 deletions app/talk/board.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -211,7 +212,6 @@ module.exports = createReactClass
</label>

render: ->
baseURL = @props.project?._type._name
{board} = @state
discussionsMeta = @state.discussions[0]?.getMeta()

Expand All @@ -233,7 +233,7 @@ module.exports = createReactClass
<h2>Moderator Zone:</h2>

{if @props.section isnt 'zooniverse'
<Link to="/projects/#{@props.params?.owner}/#{@props.params?.name}/talk/moderations">View Reported Comments</Link>
<Link to="/baseURL(@props.project)/#{@props.params?.owner}/#{@props.params?.name}/talk/moderations">View Reported Comments</Link>
else
<Link to="/talk/moderations">View Reported Comments</Link>
}
Expand Down Expand Up @@ -300,7 +300,7 @@ module.exports = createReactClass
{if @props.section is 'zooniverse'
<Link className="sidebar-link" to="/talk/recents/#{@props.params.board}">Recent Comments</Link>
else
<Link className="sidebar-link" to="/#{baseURL}/#{@props.params.owner}/#{@props.params.name}/talk/recents/#{@props.params.board}">
<Link className="sidebar-link" to="/#{baseURL(@props.project)}/#{@props.params.owner}/#{@props.params.name}/talk/recents/#{@props.params.board}">
Recent Comments
</Link>}
</h3>
Expand Down
4 changes: 2 additions & 2 deletions app/talk/comment-link.cjsx
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
Expand Down
13 changes: 5 additions & 8 deletions app/talk/comment.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
<Link to="/#{baseURL}/#{owner}/#{name}/talk/subjects/#{comment.focus_id}" onClick={@logItemClick.bind this, "view-subject-direct"}>
<Link to="/#{baseURL(@props.project)}/#{owner}/#{name}/talk/subjects/#{comment.focus_id}" onClick={@logItemClick.bind this, "view-subject-direct"}>
Subject {subject.id}
</Link>
else
Expand All @@ -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}/"
<div key={comment.id} className="comment-reply-line" ref="comment-reply-#{comment.id}">
<p>
<Link to="#{baseLink}users/#{comment.user_login}">{comment.user_display_name}</Link>
Expand Down Expand Up @@ -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 ""
<div className="talk-comment #{activeClass} #{isDeleted}">
<div className="talk-comment-author">
Expand All @@ -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}"
<div className="talk-comment-reply">
{if @state.replies.length
<div>
Expand Down
10 changes: 5 additions & 5 deletions app/talk/discussion-preview.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';`
Expand All @@ -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}"
Expand Down
6 changes: 3 additions & 3 deletions app/talk/init.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -139,7 +140,6 @@ module.exports = createReactClass
@setBoards()

render: ->
baseURL = @props.project?._type._name
<div className="talk-home">
{if @props.user?
<div className="talk-moderation">
Expand All @@ -165,7 +165,7 @@ module.exports = createReactClass
</button>
</ZooniverseTeam>
{if @props.section isnt 'zooniverse'
<Link to="/projects/#{@props.params?.owner}/#{@props.params?.name}/talk/moderations">
<Link to="/#{baseURL(@props.project)}/#{@props.params?.owner}/#{@props.params?.name}/talk/moderations">
View Reported Comments
</Link>
else
Expand Down Expand Up @@ -201,7 +201,7 @@ module.exports = createReactClass
{if @props.section is 'zooniverse'
<Link className="sidebar-link" onClick={@logTalkClick.bind this, 'recent-comments-sidebar'} to="/talk/recents">Recent Comments</Link>
else
<Link className="sidebar-link" onClick={@logTalkClick.bind this, 'recent-comments-sidebar'} to="/#{baseURL}/#{@props.params.owner}/#{@props.params.name}/talk/recents">Recent Comments</Link>
<Link className="sidebar-link" onClick={@logTalkClick.bind this, 'recent-comments-sidebar'} to="/#{baseURL(@props.project)}/#{@props.params.owner}/#{@props.params.name}/talk/recents">Recent Comments</Link>
}
</h3>
</section>
Expand Down
9 changes: 4 additions & 5 deletions app/talk/latest-comment-link.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

<Link className={className} onClick={logClick?.bind(this, childtext)} to={@context.router.createHref(locationObject)}>
{childtext}
Expand All @@ -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}/"

<div className="talk-latest-comment-link">
<div className="talk-discussion-link">
Expand Down
1 change: 1 addition & 0 deletions app/talk/lib/base-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default resource => resource && resource._type._name
3 changes: 2 additions & 1 deletion app/talk/popular-tags.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { Link } from 'react-router';

const ProjectTag = (props) => {
const tag = props.tag.name;
const baseURL = props.project._type._name;
return (
<div className="truncated">
<Link to={`/projects/${props.project.slug}/talk/tags/${tag}`} onClick={props.onClick} >
<Link to={`/${baseURL}/${props.project.slug}/talk/tags/${tag}`} onClick={props.onClick} >
{tag}
</Link>
{' '}
Expand Down
4 changes: 2 additions & 2 deletions app/talk/recents.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,9 +115,8 @@ module.exports = createReactClass
commentTitle: (comment) ->
<span>
{if @props.params.owner and @props.params.name
baseURL = @props.project?._type._name
{owner, name} = @props.params
<Link to="/#{baseURL}/#{owner}/#{name}/talk/#{comment.board_id}/#{comment.discussion_id}?comment=#{comment.id}">
<Link to="/#{baseURL(@props.project)}/#{owner}/#{name}/talk/#{comment.board_id}/#{comment.discussion_id}?comment=#{comment.id}">
{comment.discussion_title} on {comment.board_title}
</Link>
else
Expand Down

0 comments on commit 84995c2

Please sign in to comment.