Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

User page buttons tweaks #522

Merged
merged 3 commits into from
Jun 19, 2017
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
4 changes: 3 additions & 1 deletion js/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,9 @@
"listingNotFoundMsg": "%{listing} could not be found.",
"pageNotFoundTitle": "This Page Could Not Be Found",
"pageNotFoundMsg": "Check the address bar to make sure the URL is correct.",
"genericErrorTitle": "There Was An Error"
"genericErrorTitle": "There Was An Error",
"listingErrorTitle": "Unable To Fetch Listing",
"listingErrorMsg": "There was an error fetching listing %{listing}"
},
"bitcoinCurrencyUnits": {
"BTC": "BTC",
Expand Down
65 changes: 42 additions & 23 deletions js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,15 @@ export default class ObRouter extends Router {
}

user(guid, state, ...args) {
let pageState = state || 'store';
const pageState = state || 'store';
const deepRouteParts = args.filter(arg => arg !== null);

if (!state) {
this.navigate(`${guid}/store${deepRouteParts ? deepRouteParts.join('/') : ''}`, {
replace: true,
});
}

if (!this.isValidUserRoute(guid, pageState, ...deepRouteParts)) {
this.pageNotFound();
return;
Expand Down Expand Up @@ -187,23 +193,29 @@ export default class ObRouter extends Router {
this.once('will-route', onWillRoute);

$.whenAll(profileFetch, listingFetch).done(() => {
if (state === 'store' && !profile.get('vendor') && guid !== app.profile.id) {
this.pageNotFound();
} else {
if (!state) {
pageState = (!profile.get('vendor') && guid !== app.profile.id) ? 'home' : 'store';
this.navigate(`${guid}/${pageState}${deepRouteParts ? deepRouteParts.join('/') : ''}`, {
replace: true,
});
if (pageState === 'store' && !profile.get('vendor') && guid !== app.profile.id) {
// the user does not have an active store and this is not our own node
if (state) {
// You've explicitly tried to navigate to the store tab. Since it's not
// available, we'll re-route to page-not-found
this.pageNotFound();
return;
}
this.loadPage(
new UserPage({
model: profile,
state: pageState,
listing,
}).render()
);

// You've attempted to find a user with no particular tab. Since store is not available
// we'll take you to the home tab.
this.navigate(`${guid}/home${deepRouteParts ? deepRouteParts.join('/') : ''}`, {
replace: true,
});
}

this.loadPage(
new UserPage({
model: profile,
state: pageState,
listing,
}).render()
);
}).fail(() => {
if (profileFetch.statusText === 'abort' ||
profileFetch.statusText === 'abort') return;
Expand All @@ -213,6 +225,7 @@ export default class ObRouter extends Router {
if (profileFetch.state() === 'rejected') {
this.userNotFound(guid);
} else if (listingFetch.state() === 'rejected') {
// this.listingError(listingFetch, listing.get('slug'), `#${guid}/store`)
this.listingNotFound(deepRouteParts[0], `${guid}/${pageState}`);
}
})
Expand Down Expand Up @@ -268,7 +281,9 @@ export default class ObRouter extends Router {

pageNotFound() {
this.loadPage(
new TemplateOnly({ template: 'error-pages/pageNotFound.html' }).render()
new TemplateOnly({
template: 'error-pages/pageNotFound.html',
}).render()
);
}

Expand All @@ -278,25 +293,29 @@ export default class ObRouter extends Router {
);
}

listingError(failedXhr, listing, store) {
listingError(failedXhr, listing, storeUrl) {
if (!failedXhr) {
throw new Error('Please provide the failed Xhr request');
}

if (failedXhr.status === 404) {
this.listingNotFound(listing, store);
this.listingNotFound(listing, storeUrl);
} else {
const link = `<a href="${store}">${app.polyglot.t('errorPage.listingNotFoundLink')}</a>`;
let content = app.polyglot.t('errorPage.listingNotFoundMsg', { listing, link });
let failErr = '';

if (failedXhr.responseText) {
const reason = failedXhr.responseJSON && failedXhr.responseJSON.reason ||
failedXhr.responseText;
content += `\n\n${reason}`;
failErr += `\n\n${reason}`;
}

this.loadPage(
new TemplateOnly({ template: 'error-pages/genericError.html' }).render(content)
new TemplateOnly({ template: 'error-pages/listingError.html' })
.render({
listing,
storeUrl,
failErr,
})
);
}
}
Expand Down
12 changes: 12 additions & 0 deletions js/templates/error-pages/listingError.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="tx5">
<h1 class="txCtr"><%= ob.polyT('errorPage.listingErrorTitle') %></h1>
<% if (ob.listing) { %>
<p class="txCtr"><%= ob.polyT('errorPage.listingErrorMsg', { listing: ob.listing }) %></p>
<% } %>
<% if (ob.failErr) { %>
<p class="txCtr"><%= ob.failErr %></p>
<% } %>
<% if (ob.storeUrl) { %>
<p class="txCtr"><a href="<%= ob.storeUrl %>"><%= ob.polyT('errorPage.listingNotFoundLink') %></a></p>
<% } %>
</div>
4 changes: 2 additions & 2 deletions js/views/ListingCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class extends baseVw {
// If a vendor object is available (part of proposed search API), please pass it in.
this.ownerGuid = this.model.get('vendor').peerID;
} else {
// Otherwise please provide a boolean indicating ownListing.
// Otherwise please provide the store owner's guid.
this.ownerGuid = opts.ownerGuid;
}

Expand Down Expand Up @@ -158,7 +158,7 @@ export default class extends baseVw {
app.loadingModal.close();
})
.fail((xhr) => {
app.router.listingError(xhr, this.model.get('slug'), this.options.listingBaseUrl);
app.router.listingError(xhr, this.model.get('slug'), `#${this.ownerGuid}/store`);
});
}
}
Expand Down