-
Notifications
You must be signed in to change notification settings - Fork 186
Refactor mod loading #1859
Refactor mod loading #1859
Changes from all commits
c0714ce
d2a4cc2
53a3348
76935bd
81a1ecc
b67acea
1b89467
4a9b265
9fbba4e
033e131
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,9 +93,9 @@ export default class extends baseVw { | |
|
||
super(opts); | ||
this.options = opts; | ||
this.excludeIDs = opts.excludeIDs; | ||
this.excludeIDs = [...opts.excludeIDs, app.profile.id]; | ||
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. It seemed a lot smarter just include the user's own profile here, instead of adding it later. We could add a parameter to not exclude it in the future if that use case ever came up. |
||
this.modsToFetch = [...opts.moderatorIDs]; | ||
this.unfetchedMods = []; | ||
this.fetchingMods = []; | ||
this.fetchingVerifiedMods = []; | ||
this.modFetches = []; | ||
this.moderatorsCol = new Moderators(); | ||
|
@@ -172,37 +172,36 @@ 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); | ||
|
||
this.setState({ | ||
loading: true, | ||
noValidModerators: false, | ||
noValidVerifiedModerators: !this.fetchingVerifiedMods.length, | ||
}); | ||
// 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); | ||
|
||
// 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') { | ||
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. This was moved so it wouldn't set the state to loading if there were no mods to fetch. |
||
this.setState({ | ||
loading: true, | ||
noValidModerators: false, | ||
noValidVerifiedModerators: !this.fetchingVerifiedMods.length, | ||
}); | ||
|
||
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) => { | ||
|
@@ -213,13 +212,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); | ||
} | ||
}); | ||
|
@@ -230,9 +231,7 @@ 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: IDs }); | ||
if (!data.length) this.trigger('noModsFound', { guids: this.modsToFetch }); | ||
} | ||
}) | ||
.fail((xhr) => { | ||
|
@@ -259,7 +258,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, | ||
|
@@ -272,7 +271,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. | ||
|
@@ -403,19 +402,16 @@ 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 totalIDs = this.allIDs.length; | ||
const unVerCount = this.modCards.filter(mod => (!state.showOnlyCur || | ||
mod.model.hasModCurrency(state.showOnlyCur)) && !mod.model.isVerified).length; | ||
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. Since a default currency isn't being passed in (removed below), this was updated to be count all the unverified moderators if there is no currency set. |
||
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, | ||
})); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
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. I made this longer since I was seeing the message for no mods appear then mods would load, which was pretty clunky. |
||
} | ||
super.setState(state, options); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}); | ||
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. These three sections of code were removed, they were just duplicating things already handled by the view and creating some weird edge case behavior (like if you loaded moderators, then closed and reopened settings the status bar would appear). |
||
|
||
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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,7 +162,7 @@ export default class extends BaseModal { | |
singleSelect: true, | ||
radioStyle: true, | ||
initialState: { | ||
showOnlyCur: currencies[0], | ||
showOnlyCur: '', | ||
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. This was only showing moderators that accept BTC, I assume it was there because originally we automatically selected the first currency. Since we changed it to require the user to select a currency (none are selected by default) this should also have no default. |
||
showVerifiedOnly: true, | ||
}, | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The placeholder got refactored so the messages below take care of everything with less duplication. This also makes sure there's always a message.