Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update uri -> url in the front end + examples #2006

Merged
merged 2 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ package-lock.json
/.next
/build
/coverage
**/*.md
2 changes: 1 addition & 1 deletion doc/TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Downloads, ...) and add your badge:
keywords: [
'some-search-keyword'
],
previewUri: '/test/subject/STATUS.svg',
previewUrl: '/test/subject/STATUS.svg',
},
```

Expand Down
44 changes: 22 additions & 22 deletions frontend/components/badge-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import resolveBadgeUrl from '../lib/badge-url'

const Badge = ({
title,
exampleUri,
previewUri,
exampleUrl,
previewUrl,
urlPattern,
documentation,
baseUri,
baseUrl,
longCache,
shouldDisplay = () => true,
onClick,
Expand All @@ -19,26 +19,26 @@ const Badge = ({
? () =>
onClick({
title,
exampleUri,
previewUri,
exampleUrl,
previewUrl,
urlPattern,
documentation,
})
: undefined

const previewImage = previewUri ? (
const previewImage = previewUrl ? (
<img
className={classNames('badge-img', { clickable: onClick })}
onClick={handleClick}
src={resolveBadgeUrl(previewUri, baseUri, { longCache })}
src={resolveBadgeUrl(previewUrl, baseUrl, { longCache })}
alt=""
/>
) : (
'\u00a0'
) // non-breaking space
const resolvedExampleUri = resolveBadgeUrl(
urlPattern || previewUri,
baseUri,
const resolvedExampleUrl = resolveBadgeUrl(
urlPattern || previewUrl,
baseUrl,
{ longCache: false }
)

Expand All @@ -57,7 +57,7 @@ const Badge = ({
className={classNames({ clickable: onClick })}
onClick={handleClick}
>
{resolvedExampleUri}
{resolvedExampleUrl}
</code>
</td>
</tr>
Expand All @@ -67,17 +67,17 @@ const Badge = ({
}
Badge.propTypes = {
title: PropTypes.string.isRequired,
exampleUri: PropTypes.string,
previewUri: PropTypes.string,
exampleUrl: PropTypes.string,
previewUrl: PropTypes.string,
urlPattern: PropTypes.string,
documentation: PropTypes.string,
baseUri: PropTypes.string,
baseUrl: PropTypes.string,
longCache: PropTypes.bool.isRequired,
shouldDisplay: PropTypes.func,
onClick: PropTypes.func.isRequired,
}

const Category = ({ category, examples, baseUri, longCache, onClick }) => {
const Category = ({ category, examples, baseUrl, longCache, onClick }) => {
if (examples.filter(example => example.shouldDisplay()).length === 0) {
return null
}
Expand All @@ -92,7 +92,7 @@ const Category = ({ category, examples, baseUri, longCache, onClick }) => {
<Badge
key={badgeData.key}
{...badgeData}
baseUri={baseUri}
baseUrl={baseUrl}
longCache={longCache}
onClick={onClick}
/>
Expand All @@ -110,24 +110,24 @@ Category.propTypes = {
examples: PropTypes.arrayOf(
PropTypes.shape({
title: PropTypes.string.isRequired,
exampleUri: PropTypes.string,
previewUri: PropTypes.string,
exampleUrl: PropTypes.string,
previewUrl: PropTypes.string,
urlPattern: PropTypes.string,
documentation: PropTypes.string,
})
).isRequired,
baseUri: PropTypes.string,
baseUrl: PropTypes.string,
longCache: PropTypes.bool.isRequired,
onClick: PropTypes.func.isRequired,
}

const BadgeExamples = ({ categories, baseUri, longCache, onClick }) => (
const BadgeExamples = ({ categories, baseUrl, longCache, onClick }) => (
<div>
{categories.map((categoryData, i) => (
<Category
key={i}
{...categoryData}
baseUri={baseUri}
baseUrl={baseUrl}
longCache={longCache}
onClick={onClick}
/>
Expand All @@ -141,7 +141,7 @@ BadgeExamples.propTypes = {
examples: Category.propTypes.examples,
})
),
baseUri: PropTypes.string,
baseUrl: PropTypes.string,
longCache: PropTypes.bool.isRequired,
onClick: PropTypes.func.isRequired,
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/components/dynamic-badge-maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { dynamicBadgeUrl } from '../lib/badge-url'

export default class DynamicBadgeMaker extends React.Component {
static propTypes = {
baseUri: PropTypes.string,
baseUrl: PropTypes.string,
}

state = {
Expand All @@ -17,9 +17,9 @@ export default class DynamicBadgeMaker extends React.Component {
suffix: '',
}

makeBadgeUri() {
makeBadgeUrl() {
const { datatype, label, url, query, color, prefix, suffix } = this.state
const { baseUri: baseUrl = document.location.href } = this.props
const { baseUrl: baseUrl = document.location.href } = this.props
return dynamicBadgeUrl(baseUrl, datatype, label, url, query, {
color,
prefix,
Expand All @@ -29,7 +29,7 @@ export default class DynamicBadgeMaker extends React.Component {

handleSubmit(e) {
e.preventDefault()
document.location = this.makeBadgeUri()
document.location = this.makeBadgeUrl()
}

get isValid() {
Expand Down
10 changes: 5 additions & 5 deletions frontend/components/examples-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SearchResults from './search-results'
import MarkupModal from './markup-modal'
import Usage from './usage'
import Footer from './footer'
import { baseUri, longCache } from '../constants'
import { baseUrl, longCache } from '../constants'

export default class ExamplesPage extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -78,24 +78,24 @@ export default class ExamplesPage extends React.Component {
onRequestClose={() => {
this.setState({ example: null })
}}
baseUri={baseUri}
baseUrl={baseUrl}
/>
<section>
<SuggestionAndSearch
queryChanged={this.searchQueryChanged}
onBadgeClick={example => {
this.setState({ example })
}}
baseUri={baseUri}
baseUrl={baseUrl}
longCache={longCache}
/>
<a className="donate" href="https://opencollective.com/shields">
donate
</a>
</section>
{this.renderSearchResults()}
<Usage baseUri={baseUri} longCache={longCache} />
<Footer baseUri={baseUri} />
<Usage baseUrl={baseUrl} longCache={longCache} />
<Footer baseUrl={baseUrl} />
<style jsx>{`
.donate {
text-decoration: none;
Expand Down
10 changes: 5 additions & 5 deletions frontend/components/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import resolveUrl from '../lib/resolve-url'

const Footer = ({ baseUri }) => (
const Footer = ({ baseUrl }) => (
<section>
<h2 id="like-this">Like This?</h2>

Expand All @@ -18,7 +18,7 @@ const Footer = ({ baseUri }) => (
<object
data={resolveUrl(
'/twitter/follow/shields_io.svg?style=social&label=Follow',
baseUri
baseUrl
)}
alt="Follow @shields_io"
/>{' '}
Expand All @@ -34,15 +34,15 @@ const Footer = ({ baseUri }) => (
<object
data={resolveUrl(
'/github/forks/badges/shields.svg?style=social&label=Fork',
baseUri
baseUrl
)}
alt="Fork on GitHub"
/>{' '}
{}
<object
data={resolveUrl(
'/discord/308323056592486420.svg?style=social&label=Chat&link=https://discord.gg/HjJCwm5',
baseUri
baseUrl
)}
alt="chat on Discord"
/>
Expand All @@ -59,5 +59,5 @@ const Footer = ({ baseUri }) => (
)
export default Footer
Footer.propTypes = {
baseUri: PropTypes.string.isRequired,
baseUrl: PropTypes.string.isRequired,
}
42 changes: 21 additions & 21 deletions frontend/components/markup-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ export default class MarkupModal extends React.Component {
static propTypes = {
example: PropTypes.shape({
title: PropTypes.string.isRequired,
exampleUri: PropTypes.string,
previewUri: PropTypes.string,
exampleUrl: PropTypes.string,
previewUrl: PropTypes.string,
urlPattern: PropTypes.string,
documentation: PropTypes.string,
link: PropTypes.string,
}),
baseUri: PropTypes.string.isRequired,
baseUrl: PropTypes.string.isRequired,
onRequestClose: PropTypes.func.isRequired,
}

state = {
exampleUri: null,
badgeUri: null,
exampleUrl: null,
badgeUrl: null,
link: null,
style: 'flat',
}
Expand All @@ -32,34 +32,34 @@ export default class MarkupModal extends React.Component {
}

componentWillReceiveProps(nextProps) {
const { example, baseUri } = nextProps
const { example, baseUrl } = nextProps

if (!example) {
return
}

// Transfer `badgeUri` and `link` into state so they can be edited by the
// Transfer `badgeUrl` and `link` into state so they can be edited by the
// user.
const { exampleUri, urlPattern, previewUri, link } = example
const { exampleUrl, urlPattern, previewUrl, link } = example
this.setState({
exampleUri: exampleUri
? resolveBadgeUrl(exampleUri, baseUri || window.location.href)
exampleUrl: exampleUrl
? resolveBadgeUrl(exampleUrl, baseUrl || window.location.href)
: null,
badgeUri: resolveBadgeUrl(
urlPattern || previewUri,
baseUri || window.location.href
badgeUrl: resolveBadgeUrl(
urlPattern || previewUrl,
baseUrl || window.location.href
),
link,
})
}

generateCompleteBadgeUrl() {
const { baseUri } = this.props
const { badgeUri, style } = this.state
const { baseUrl } = this.props
const { badgeUrl, style } = this.state

return resolveBadgeUrl(
badgeUri,
baseUri || window.location.href,
badgeUrl,
baseUrl || window.location.href,
// Default style doesn't need to be specified.
style === 'flat' ? undefined : { style }
)
Expand Down Expand Up @@ -124,21 +124,21 @@ export default class MarkupModal extends React.Component {
Image&nbsp;
<input
type="url"
value={this.state.badgeUri}
value={this.state.badgeUrl}
onChange={event => {
this.setState({ badgeUri: event.target.value })
this.setState({ badgeUrl: event.target.value })
}}
/>
</label>
</p>
{this.state.exampleUri && (
{this.state.exampleUrl && (
<p>
Example&nbsp;
<ClickToSelect>
<input
className="code clickable"
readOnly
value={this.state.exampleUri}
value={this.state.exampleUrl}
/>
</ClickToSelect>
</p>
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/search-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
import { BadgeExamples } from './badge-examples'
import badgeExampleData from '../../badge-examples.json'
import { prepareExamples, predicateFromQuery } from '../lib/prepare-examples'
import { baseUri, longCache } from '../constants'
import { baseUrl, longCache } from '../constants'

export default class SearchResults extends React.Component {
static propTypes = {
Expand All @@ -25,7 +25,7 @@ export default class SearchResults extends React.Component {
<BadgeExamples
categories={this.preparedExamples}
onClick={this.props.clickHandler}
baseUri={baseUri}
baseUrl={baseUrl}
longCache={longCache}
/>
)
Expand Down
10 changes: 5 additions & 5 deletions frontend/components/static-badge-maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { staticBadgeUrl } from '../lib/badge-url'

export default class StaticBadgeMaker extends React.Component {
static propTypes = {
baseUri: PropTypes.string,
baseUrl: PropTypes.string,
}

state = {
Expand All @@ -16,16 +16,16 @@ export default class StaticBadgeMaker extends React.Component {
handleSubmit(e) {
e.preventDefault()

const { baseUri } = this.props
const { baseUrl } = this.props
const { subject, status, color } = this.state
const badgeUri = staticBadgeUrl(
baseUri || window.location.href,
const badgeUrl = staticBadgeUrl(
baseUrl || window.location.href,
subject,
status,
color
)

document.location = badgeUri
document.location = badgeUrl
}

render() {
Expand Down
Loading