-
Notifications
You must be signed in to change notification settings - Fork 34
rewrite series sales block to react #1439
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
Merged
php-coder
merged 1 commit into
php-coder:master
from
bahoss:rewrite-series-sales-block-to-React
Jun 28, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// | ||
// IMPORTANT: | ||
// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file! | ||
// | ||
|
||
class SeriesSalesList extends React.PureComponent { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
sales: [], | ||
hasServerError: false, | ||
}; | ||
this.loadSales = this.loadSales.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
this.loadSales(); | ||
} | ||
|
||
loadSales() { | ||
this.setState({ | ||
hasServerError: false, | ||
sales: [] | ||
}); | ||
|
||
axios.get(this.props.url) | ||
.then(response => { | ||
const data = response.data; | ||
this.setState({ sales: data }); | ||
|
||
}) | ||
.catch(error => { | ||
console.error(error); | ||
this.setState({ hasServerError: true }); | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<SeriesSalesListView | ||
l10n={this.props.l10n} | ||
hasServerError={this.state.hasServerError} | ||
sales={this.state.sales} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
class SeriesSalesListView extends React.PureComponent { | ||
render() { | ||
const { hasServerError, l10n, sales } = this.props; | ||
|
||
return ( | ||
<div className="row"> | ||
<div className="col-sm-12"> | ||
<h5>{ l10n['t_who_selling_series'] || 'Who was selling/buying this series' }</h5> | ||
<div className="row"> | ||
<div id="loading-series-sales-failed-msg" | ||
className={ `alert alert-danger text-center col-sm-8 col-sm-offset-2 ${hasServerError ? '' : 'hidden'}` }> | ||
{ l10n['t_server_error'] || 'Server error' } | ||
</div> | ||
</div> | ||
<ul> | ||
{ sales.map((sale, index) => ( | ||
<SeriesSaleItem | ||
key={sale.id} | ||
l10n={this.props.l10n} | ||
sale={sale} | ||
index={index + 1} | ||
/> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
class SeriesSaleItem extends React.PureComponent { | ||
render() { | ||
const { sale, index, l10n } = this.props; | ||
const hasBuyer = !!sale.buyerName; | ||
const hasCondition = !!sale.condition; | ||
const hasDate = !!sale.date; | ||
const hasTransactionUrl = !!sale.transactionUrl; | ||
const hasSecondPrice = !!sale.secondPrice; | ||
|
||
return ( | ||
<li id={ `series-sale-${index}-info` }> | ||
{ hasDate && sale.date } | ||
{' '} | ||
<ParticipantLink url={sale.sellerUrl} name={sale.sellerName} /> | ||
{' '} | ||
{ hasBuyer ? | ||
(l10n['t_sold_to'] || 'sold to') | ||
: (l10n['t_was_selling'] || 'was selling for') | ||
} | ||
{' '} | ||
{ hasBuyer && (<ParticipantLink url={sale.buyerUrl} name={sale.buyerName} />) } | ||
{' '} | ||
{ hasBuyer && (l10n['t_sold_for'] || 'for') } | ||
{' '} | ||
{ hasTransactionUrl ? | ||
<a href={sale.transactionUrl} id={ `series-sale-${index}-transaction` } rel="nofollow"> | ||
{ `${sale.firstPrice}\u00A0${sale.firstCurrency}` } | ||
{ hasSecondPrice && `(${sale.secondPrice}\u00A0${sale.secondCurrency})` } | ||
</a> | ||
: <React.Fragment> | ||
{ `${sale.firstPrice}\u00A0${sale.firstCurrency}` } | ||
{ hasSecondPrice && `(${sale.secondPrice}\u00A0${sale.secondCurrency})` } | ||
</React.Fragment> | ||
} | ||
{' '} | ||
{ hasCondition && (sale.condition !== 'CANCELLED' ? sale.condition : (l10n['t_cancelled'] || 'cancelled')) } | ||
</li> | ||
) | ||
} | ||
} | ||
|
||
class ParticipantLink extends React.PureComponent { | ||
render() { | ||
const { name, url } = this.props; | ||
const hasUrl = !!url; | ||
return ( | ||
hasUrl ? | ||
<a href={url} rel="nofollow">{ name }</a> | ||
: name | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ public final class ResourceUrl { | |
// MUST be updated when any of our resources were modified | ||
public static final String RESOURCES_VERSION = "v0.4.3.12"; | ||
|
||
// CheckStyle: ignore LineLength for next 15 lines | ||
// CheckStyle: ignore LineLength for next 18 lines | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 18? You added a one line, so I'd expect that it should be 16 |
||
private static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/CatalogUtils.min.js"; | ||
private static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js"; | ||
private static final String DATE_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/DateUtils.min.js"; | ||
|
@@ -49,6 +49,8 @@ public final class ResourceUrl { | |
private static final String CATALOG_PRICE_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCatalogPriceForm.js"; | ||
private static final String CATALOG_NUMBERS_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCatalogNumbersForm.js"; | ||
private static final String RELEASE_YEAR_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddReleaseYearForm.js"; | ||
private static final String SERIES_SALES_LIST_JS = "/public/js/" + RESOURCES_VERSION + "/components/SeriesSalesList.js"; | ||
bahoss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private static final String BOOTSTRAP_LANGUAGE = "https://cdn.jsdelivr.net/gh/usrz/bootstrap-languages@3ac2a3d2b27ac43a471cd99e79d378a03b2c6b5f/languages.min.css"; | ||
private static final String FAVICON_ICO = "/favicon.ico"; | ||
|
||
|
@@ -88,6 +90,8 @@ public static void exposeResourcesToView(Map<String, String> resources, String h | |
put(resources, host, "CATALOG_PRICE_FORM_JS", CATALOG_PRICE_FORM_JS); | ||
put(resources, host, "CATALOG_NUMBERS_FORM_JS", CATALOG_NUMBERS_FORM_JS); | ||
put(resources, host, "RELEASE_YEAR_FORM_JS", RELEASE_YEAR_FORM_JS); | ||
put(resources, host, "SERIES_SALES_LIST_JS", SERIES_SALES_LIST_JS); | ||
|
||
} | ||
|
||
// see also MvcConfig.addResourceHandlers() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.