From c0714ce59e5a9dc5d199cb893737ac757f1d6db4 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Thu, 9 Jan 2020 17:00:44 -0500 Subject: [PATCH 1/9] fixLoadingStates --- .../components/moderators/moderators.html | 15 +++---- .../components/moderators/status.html | 2 +- js/views/components/moderators/Moderators.js | 40 +++++++++---------- js/views/components/moderators/Status.js | 2 +- js/views/modals/purchase/Purchase.js | 2 +- 5 files changed, 27 insertions(+), 34 deletions(-) diff --git a/js/templates/components/moderators/moderators.html b/js/templates/components/moderators/moderators.html index 5137ae87b..3f478c37d 100644 --- a/js/templates/components/moderators/moderators.html +++ b/js/templates/components/moderators/moderators.html @@ -1,12 +1,5 @@
- <% // placeholder so border collapse doesn't erase the table border when there are no table cells %> - <% if (ob.placeholder) { %> -
-
-
-
- <% } %> - <% if (ob.totalIDs && !ob.totalShown) { %> + <% if (!ob.totalShown) { %>
@@ -15,10 +8,12 @@ const showOnlyCur = ob.showOnlyCur ? 'Matching' : ''; const opts = ob.showOnlyCur ? { coin: ob.showOnlyCur } : {}; const msgPath = `moderators.noModsMsg.no${showOnlyCur}${showOnlyVer}Moderators`; + const title = ob.loading ? + ob.polyT('moderators.moderatorsLoading') : ob.polyT(`${msgPath}.title`, opts); %> -

<%= ob.polyT(`${msgPath}.title`, opts) %>

+

<%= title %>

<% // The section below is only relevant if the moderators are loaded in a purchasing context. %> - <% if (ob.purchase) { %> + <% if (ob.purchase && !ob.loading) { %>
<%= ob.polyT(`${msgPath}.body`) %>
<% if (showOnlyVer) { %>
<% // just a spacer %>
diff --git a/js/templates/components/moderators/status.html b/js/templates/components/moderators/status.html index 98a9d476a..5d8581e32 100644 --- a/js/templates/components/moderators/status.html +++ b/js/templates/components/moderators/status.html @@ -2,7 +2,7 @@ <% if (ob.showSpinner && ob.loading) { %> <%= ob.spinner({ className: 'spinnerTxt js-spinner' }) %> <% } %> - + <% if (ob.mode === 'loaded') { print(ob.polyT('moderators.moderatorsLoaded', { total: ob.total, smart_count: ob.total })); } else if (ob.mode === 'loadingXofY') { diff --git a/js/views/components/moderators/Moderators.js b/js/views/components/moderators/Moderators.js index abee9a9e0..987e9f075 100644 --- a/js/views/components/moderators/Moderators.js +++ b/js/views/components/moderators/Moderators.js @@ -94,8 +94,8 @@ export default class extends baseVw { super(opts); this.options = opts; this.excludeIDs = opts.excludeIDs; + this.modsToFetch = [...opts.moderatorIDs]; this.unfetchedMods = []; - this.fetchingMods = []; this.fetchingVerifiedMods = []; this.modFetches = []; this.moderatorsCol = new Moderators(); @@ -171,17 +171,16 @@ export default class extends baseVw { throw new Error('Please provide the list of moderators as an array.'); } - // don't get any that have already been added or excluded, or the user's own id. - const excluded = [app.profile.id, ...this.allIDs, ...this.excludeIDs]; - const IDs = _.without(op.moderatorIDs, excluded); const includeString = op.include ? `&include=${op.include}` : ''; const urlString = `ob/${op.apiPath}?async=${op.async}${includeString}&usecache=${op.useCache}`; const url = app.getServerUrl(urlString); - this.unfetchedMods = IDs; - this.fetchingMods = IDs; - this.fetchingVerifiedMods = app.verifiedMods.matched(IDs); + // don't get any that have already been added or excluded, or the user's own id. + const excluded = [app.profile.id, ...this.allIDs, ...this.excludeIDs]; + this.modsToFetch = _.without(op.moderatorIDs, excluded); + this.unfetchedMods = [...this.modsToFetch]; + this.fetchingVerifiedMods = app.verifiedMods.matched(this.modsToFetch); this.setState({ loading: true, @@ -190,18 +189,18 @@ export default class extends baseVw { }); // Either a list of IDs can be posted, or any available moderators can be retrieved with GET - if (IDs.length || op.method === 'GET') { + if (this.modsToFetch.length || op.method === 'GET') { this.moderatorsStatus.setState({ hidden: false, loaded: 0, - toLoad: IDs.length, + toLoad: this.modsToFetch.length, total: this.modCount, loading: true, }); const fetch = $.ajax({ url, - data: JSON.stringify(IDs), + data: JSON.stringify(this.modsToFetch), method: op.method, }) .done((data) => { @@ -212,13 +211,15 @@ export default class extends baseVw { const eventData = event.jsonData; if (eventData.error) { // errors don't have a message id, check to see if the peerID matches - if (IDs.includes(eventData.peerId)) { - // provide the expected capitalization of peerID - eventData.peerID = eventData.peerId; - delete eventData.peerId; + if (this.modsToFetch.includes(eventData.peerID)) { this.processMod(eventData); } - } else if (eventData.id === socketID && !excluded.includes(eventData.peerId)) { + } else if ( + eventData.id && + eventData.peerId && + eventData.id === socketID && + !excluded.includes(eventData.peerId) + ) { this.processMod(eventData.profile); } }); @@ -231,7 +232,7 @@ export default class extends baseVw { }); this.unfetchedMods = []; this.checkNotFetched(); - if (!data.length) this.trigger('noModsFound', { guids: IDs }); + if (!data.length) this.trigger('noModsFound', { guids: this.modsToFetch }); } }) .fail((xhr) => { @@ -258,7 +259,7 @@ export default class extends baseVw { } checkNotFetched() { - if (this.unfetchedMods.length === 0 && this.fetchingMods.length) { + if (this.unfetchedMods.length === 0) { // All ids have been fetched and ids existed to fetch. this.moderatorsStatus.setState({ loading: false, @@ -271,7 +272,7 @@ export default class extends baseVw { // Either ids are still fetching, or this is an open fetch with no set ids. this.moderatorsStatus.setState({ loaded: this.moderatorsCol.length, // not shown if open fetch - toLoad: this.fetchingMods.length, // not shown if open fetch + toLoad: this.modsToFetch.length, // not shown if open fetch total: this.modCount, }); // re-render to show the unverified moderators button if needed. @@ -404,17 +405,14 @@ export default class extends baseVw { const showMods = this.modCards.filter(mod => this.modShouldRender(mod.model)); const unVerCount = this.modCards.filter(mod => mod.model.hasModCurrency(state.showOnlyCur) && !mod.model.isVerified).length; - const totalIDs = this.allIDs.length; clearTimeout(this.renderTimer); this.renderTimer = null; loadTemplate('components/moderators/moderators.html', t => { this.$el.html(t({ wrapperClasses: this.options.wrapperClasses, - placeholder: !showMods.length && (this.unfetchedMods.length || !totalIDs), purchase: this.options.purchase, totalShown: showMods.length, - totalIDs, unVerCount, ...state, })); diff --git a/js/views/components/moderators/Status.js b/js/views/components/moderators/Status.js index 32f577e8c..109556768 100644 --- a/js/views/components/moderators/Status.js +++ b/js/views/components/moderators/Status.js @@ -38,7 +38,7 @@ export default class extends BaseVw { let mode = this.getState().mode; if (mode === 'loadingXofY') mode = 'loadingXofYTimedOut'; this.setState({ showSpinner: false, mode }); - }, 10000); + }, 60000); } super.setState(state, options); } diff --git a/js/views/modals/purchase/Purchase.js b/js/views/modals/purchase/Purchase.js index 8e04f485b..3f762f48c 100644 --- a/js/views/modals/purchase/Purchase.js +++ b/js/views/modals/purchase/Purchase.js @@ -162,7 +162,7 @@ export default class extends BaseModal { singleSelect: true, radioStyle: true, initialState: { - showOnlyCur: currencies[0], + showOnlyCur: '', showVerifiedOnly: true, }, }); From 53a334833a9ce2f14722650165e7bb267058ab66 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Mon, 13 Jan 2020 11:13:11 -0500 Subject: [PATCH 2/9] refactor excluding own peerID --- js/views/components/moderators/Moderators.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/js/views/components/moderators/Moderators.js b/js/views/components/moderators/Moderators.js index c17319e5d..889ad3286 100644 --- a/js/views/components/moderators/Moderators.js +++ b/js/views/components/moderators/Moderators.js @@ -18,6 +18,7 @@ export default class extends baseVw { * @param {boolean} options.useCache - Use cached data for faster speed. * @param {array} options.moderatorIDs - list of moderators to retrieve. If none get all. * @param {array} options.excludeIDs - list of moderators to not use. + * @param {boolean} options.includeSelf - allow fetching of the user as a moderator. * @param {string} options.method - POST or GET * @param {string} options.include - If apiPath is moderator, set to 'profile' or only * the peerIDs of each moderator are returned. @@ -48,6 +49,7 @@ export default class extends baseVw { useCache: true, moderatorIDs: [], excludeIDs: [], + includeSelf: false, method: 'POST', include: '', purchase: false, @@ -93,7 +95,8 @@ export default class extends baseVw { super(opts); this.options = opts; - this.excludeIDs = opts.excludeIDs; + this.excludeIDs = opts.includeSelf ? + [...opts.excludeIDs] : [...opts.excludeIDs, app.profile.id]; this.modsToFetch = [...opts.moderatorIDs]; this.unfetchedMods = []; this.fetchingVerifiedMods = []; @@ -177,8 +180,8 @@ export default class extends baseVw { `ob/${op.apiPath}?async=${op.async}${includeString}&usecache=${op.useCache}`; const url = app.getServerUrl(urlString); - // don't get any that have already been added or excluded, or the user's own id. - const excluded = [app.profile.id, ...this.allIDs, ...this.excludeIDs]; + // don't get any that have already been added or excluded. + const excluded = [...this.allIDs, ...this.excludeIDs]; this.modsToFetch = _.without(op.moderatorIDs, excluded); this.unfetchedMods = [...this.modsToFetch]; this.fetchingVerifiedMods = app.verifiedMods.matched(this.modsToFetch); From 76935bd4470c3e62c7a57d322dc5ab211424c2df Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Tue, 14 Jan 2020 09:56:44 -0500 Subject: [PATCH 3/9] only set loading state if actually loading --- js/views/components/moderators/Moderators.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/views/components/moderators/Moderators.js b/js/views/components/moderators/Moderators.js index 889ad3286..7943aba64 100644 --- a/js/views/components/moderators/Moderators.js +++ b/js/views/components/moderators/Moderators.js @@ -186,14 +186,14 @@ export default class extends baseVw { this.unfetchedMods = [...this.modsToFetch]; this.fetchingVerifiedMods = app.verifiedMods.matched(this.modsToFetch); - this.setState({ - loading: true, - noValidModerators: false, - noValidVerifiedModerators: !this.fetchingVerifiedMods.length, - }); - // Either a list of IDs can be posted, or any available moderators can be retrieved with GET if (this.modsToFetch.length || op.method === 'GET') { + this.setState({ + loading: true, + noValidModerators: false, + noValidVerifiedModerators: !this.fetchingVerifiedMods.length, + }); + this.moderatorsStatus.setState({ hidden: false, loaded: 0, From 81a1ecc21c3ff8f8dd8d2bba55afdf5dc2f12a24 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Tue, 14 Jan 2020 11:14:32 -0500 Subject: [PATCH 4/9] clean up language --- js/languages/en_US.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/languages/en_US.json b/js/languages/en_US.json index fdcf39202..b9e109a3c 100644 --- a/js/languages/en_US.json +++ b/js/languages/en_US.json @@ -1517,20 +1517,20 @@ "moderatorsLoaded": "%{total} moderator loaded |||| %{total} moderators loaded.", "noModsMsg": { "noModerators": { - "title": "No Valid Moderators Are Available.", - "body": "None of the loaded moderators are valid. This order will be a direct payment." + "title": "No moderators have been loaded.", + "body": "This order will be a direct payment." }, "noVerifiedModerators": { - "title": "No Verified Moderators Available", + "title": "No verified moderators have been loaded.", "body": "Try viewing unverified moderators." }, "noMatchingModerators": { - "title": "No moderators that accept %{coin} are available.", + "title": "No moderators that accept %{coin} have been loaded.", "body": "Moderators are available on one or more of the other currencies accepted by this listing." }, "noMatchingVerifiedModerators": { "title": "No verified moderators that accept %{coin} have been loaded.", - "body": "Try viewing unverified moderators." + "body": "Try viewing unverified moderators or using another currency." } }, "showUnverified": "Show Unverified Moderators", @@ -5740,4 +5740,4 @@ "zu": "Zulu", "zu-ZA": "Zulu (South Africa)" } -} \ No newline at end of file +} From b67aceaceec8b493bce589ee4b484f390a0b4a9f Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Tue, 14 Jan 2020 11:20:28 -0500 Subject: [PATCH 5/9] remove unneccessary calls --- js/views/components/moderators/Moderators.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/views/components/moderators/Moderators.js b/js/views/components/moderators/Moderators.js index 7943aba64..9346e1316 100644 --- a/js/views/components/moderators/Moderators.js +++ b/js/views/components/moderators/Moderators.js @@ -234,8 +234,6 @@ export default class extends baseVw { data.forEach(mod => { if (!excluded.includes(mod.peerId)) this.processMod(mod.profile); }); - this.unfetchedMods = []; - this.checkNotFetched(); if (!data.length) this.trigger('noModsFound', { guids: this.modsToFetch }); } }) From 1b894679580534a490065f474bf38e1987a38153 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Tue, 14 Jan 2020 11:55:43 -0500 Subject: [PATCH 6/9] tweak language --- js/languages/en_US.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/languages/en_US.json b/js/languages/en_US.json index b9e109a3c..82e2b1060 100644 --- a/js/languages/en_US.json +++ b/js/languages/en_US.json @@ -1517,7 +1517,7 @@ "moderatorsLoaded": "%{total} moderator loaded |||| %{total} moderators loaded.", "noModsMsg": { "noModerators": { - "title": "No moderators have been loaded.", + "title": "No valid moderators have been loaded.", "body": "This order will be a direct payment." }, "noVerifiedModerators": { From 4a9b265844d4bb2c2dc4b53b695aed1befa3d339 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Tue, 14 Jan 2020 12:25:35 -0500 Subject: [PATCH 7/9] remove cleverness with excluded id, fix bug when no currency set --- js/views/components/moderators/Moderators.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/js/views/components/moderators/Moderators.js b/js/views/components/moderators/Moderators.js index 9346e1316..d7c035829 100644 --- a/js/views/components/moderators/Moderators.js +++ b/js/views/components/moderators/Moderators.js @@ -18,7 +18,6 @@ export default class extends baseVw { * @param {boolean} options.useCache - Use cached data for faster speed. * @param {array} options.moderatorIDs - list of moderators to retrieve. If none get all. * @param {array} options.excludeIDs - list of moderators to not use. - * @param {boolean} options.includeSelf - allow fetching of the user as a moderator. * @param {string} options.method - POST or GET * @param {string} options.include - If apiPath is moderator, set to 'profile' or only * the peerIDs of each moderator are returned. @@ -95,8 +94,7 @@ export default class extends baseVw { super(opts); this.options = opts; - this.excludeIDs = opts.includeSelf ? - [...opts.excludeIDs] : [...opts.excludeIDs, app.profile.id]; + this.excludeIDs = [...opts.excludeIDs, app.profile.id]; this.modsToFetch = [...opts.moderatorIDs]; this.unfetchedMods = []; this.fetchingVerifiedMods = []; @@ -185,7 +183,7 @@ export default class extends baseVw { this.modsToFetch = _.without(op.moderatorIDs, excluded); this.unfetchedMods = [...this.modsToFetch]; this.fetchingVerifiedMods = app.verifiedMods.matched(this.modsToFetch); - + // Either a list of IDs can be posted, or any available moderators can be retrieved with GET if (this.modsToFetch.length || op.method === 'GET') { this.setState({ @@ -405,8 +403,8 @@ export default class extends baseVw { render() { const state = this.getState(); const showMods = this.modCards.filter(mod => this.modShouldRender(mod.model)); - const unVerCount = this.modCards.filter(mod => - mod.model.hasModCurrency(state.showOnlyCur) && !mod.model.isVerified).length; + const unVerCount = this.modCards.filter(mod => (!state.showOnlyCur || + mod.model.hasModCurrency(state.showOnlyCur)) && !mod.model.isVerified).length; clearTimeout(this.renderTimer); this.renderTimer = null; From 9fbba4ed10141221adc575c534bbed84aad344c6 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Tue, 14 Jan 2020 15:34:54 -0500 Subject: [PATCH 8/9] remove superfluous code --- js/views/modals/Settings/Store.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/js/views/modals/Settings/Store.js b/js/views/modals/Settings/Store.js index f813700cd..672271468 100644 --- a/js/views/modals/Settings/Store.js +++ b/js/views/modals/Settings/Store.js @@ -286,22 +286,11 @@ export default class extends baseVw { const remAvail = this.modsAvailable.removeModeratorsByID(this.modsAvailable.selectedIDs); this.modsByID.excludeIDs = this.currentMods; - this.modsByID.moderatorsStatus.setState({ - hidden: true, - }); this.modsSelected.moderatorsCol.add([...remByID, ...remAvail]); - this.modsSelected.moderatorsStatus.setState({ - hidden: true, - }); this.modsAvailable.excludeIDs = this.currentMods; this.modsAvailable.moderatorsCol.add(remSel); - this.modsAvailable.moderatorsStatus.setState({ - hidden: false, - total: this.modsAvailable.modCount, - showSpinner: false, - }); // If any of the mods moved to the available collect are unverified, show them if (app.verifiedMods.matched(unSel).length !== unSel.length) { From 033e1317504c76dcee19e614604ae31df3705cb3 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Tue, 14 Jan 2020 16:16:31 -0500 Subject: [PATCH 9/9] cleanup --- js/views/components/moderators/Moderators.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/views/components/moderators/Moderators.js b/js/views/components/moderators/Moderators.js index d7c035829..b77a1eaac 100644 --- a/js/views/components/moderators/Moderators.js +++ b/js/views/components/moderators/Moderators.js @@ -48,7 +48,6 @@ export default class extends baseVw { useCache: true, moderatorIDs: [], excludeIDs: [], - includeSelf: false, method: 'POST', include: '', purchase: false, @@ -183,7 +182,7 @@ export default class extends baseVw { this.modsToFetch = _.without(op.moderatorIDs, excluded); this.unfetchedMods = [...this.modsToFetch]; this.fetchingVerifiedMods = app.verifiedMods.matched(this.modsToFetch); - + // Either a list of IDs can be posted, or any available moderators can be retrieved with GET if (this.modsToFetch.length || op.method === 'GET') { this.setState({