Skip to content

Commit

Permalink
Add baseURL to links
Browse files Browse the repository at this point in the history
Derive a base URL for links from the type of project resource.
  • Loading branch information
eatyourgreens committed Aug 27, 2022
1 parent d72f46a commit 0ee5d93
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
5 changes: 3 additions & 2 deletions app/talk/board-preview.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ module.exports = createReactClass
boardLink: ->
{owner, name} = @props.params
boardId = @props.data.id
baseURL = @props.project?._type._name

if @props.project
<Link to="/projects/#{owner}/#{name}/talk/#{boardId}">
if baseURL
<Link to="/#{baseURL}/#{owner}/#{name}/talk/#{boardId}">
{@props.data.title}
</Link>
else
Expand Down
3 changes: 2 additions & 1 deletion app/talk/board.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ module.exports = createReactClass
</label>

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

Expand Down Expand Up @@ -299,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="/projects/#{@props.params.owner}/#{@props.params.name}/talk/recents/#{@props.params.board}">
<Link className="sidebar-link" to="/#{baseURL}/#{@props.params.owner}/#{@props.params.name}/talk/recents/#{@props.params.board}">
Recent Comments
</Link>}
</h3>
Expand Down
3 changes: 2 additions & 1 deletion app/talk/breadcrumbs.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module.exports = createReactClass
rootTalkPath: ->
if @props.project
[owner, name] = @props.project.slug.split('/')
"/projects/#{owner}/#{name}/talk"
baseURL = @props.project._type._name
"/#{baseURL}/#{owner}/#{name}/talk"
else
"/talk"

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 @@ -20,14 +20,14 @@ module.exports = createReactClass

discussionLink: ->
{discussion} = @props
baseURL = @props.project?._type._name

if (@props.params?.owner and @props.params?.name) # get from url if possible
if (baseURL && @props.params?.owner and @props.params?.name) # get from url if possible
{owner, name} = @props.params
"/projects/#{owner}/#{name}/talk/#{discussion.board_id}/#{discussion.id}"
"/#{baseURL}/#{owner}/#{name}/talk/#{discussion.board_id}/#{discussion.id}"

else if @props.project.slug # otherwise fetch from project
[owner, name] = @props.project.slug.split('/')
"/projects/#{owner}/#{name}/talk/#{discussion.board_id}/#{discussion.id}"
else if (baseURL && @props.project.slug) # otherwise fetch from project
"/#{baseURL}/#{@props.project.slug}/talk/#{discussion.board_id}/#{discussion.id}"

else # link to zooniverse main talk
"/talk/#{discussion.board_id}/#{discussion.id}"
Expand Down
3 changes: 2 additions & 1 deletion app/talk/init.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ module.exports = createReactClass
@setBoards()

render: ->
baseURL = @props.project?._type._name
<div className="talk-home">
{if @props.user?
<div className="talk-moderation">
Expand Down Expand Up @@ -200,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="/projects/#{@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.params.owner}/#{@props.params.name}/talk/recents">Recent Comments</Link>
}
</h3>
</section>
Expand Down
8 changes: 5 additions & 3 deletions app/talk/latest-comment-link.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ 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 @props.params?.owner and @props.params?.name
if baseURL and @props.params?.owner and @props.params?.name
{owner, name} = @props.params
locationObject.pathname = "/projects/#{owner}/#{name}" + locationObject.pathname
locationObject.pathname = "/#{baseURL}/#{owner}/#{name}" + locationObject.pathname

<Link className={className} onClick={logClick?.bind(this, childtext)} to={@context.router.createHref(locationObject)}>
{childtext}
Expand All @@ -74,7 +75,8 @@ module.exports = createReactClass

baseLink = "/"
if @props.project? and @props.project.slug?
baseLink += "projects/#{@props.project.slug}/"
baseURL = @props.project?._type._name
baseLink += "#{baseURL}/#{@props.project.slug}/"

<div className="talk-latest-comment-link">
<div className="talk-discussion-link">
Expand Down

0 comments on commit 0ee5d93

Please sign in to comment.