This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #676 from OpenBazaar/follow-refactor
Follow refactor
- Loading branch information
Showing
19 changed files
with
615 additions
and
266 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,33 +1,39 @@ | ||
import { Collection } from 'backbone'; | ||
import UserShort from '../models/UserCard'; | ||
/* Used for lists of followers and following */ | ||
|
||
import app from '../app'; | ||
import { Collection } from 'backbone'; | ||
import Follower from '../models/Follower'; | ||
|
||
export default class extends Collection { | ||
constructor(models = [], options = {}) { | ||
super(models, options); | ||
|
||
module.exports = Collection.extend({ | ||
/* we have to use the older style for this collection, the ES6 style creates a bug where models | ||
cannot be removed using their ids */ | ||
const types = ['followers', 'following']; | ||
if (types.indexOf(options.type) === -1) { | ||
throw new Error(`Please provide a type as one of ${types.join(', ')}`); | ||
} | ||
|
||
initialize(models, options) { | ||
if (!options.type) { | ||
throw new Error('You must provide a type to the collection'); | ||
if (!options.peerId) { | ||
throw new Error('Please provide a peerId'); | ||
} | ||
|
||
this.guid = options.guid; | ||
this.type = options.type; | ||
}, | ||
this.options = options; | ||
} | ||
|
||
url() { | ||
return app.getServerUrl(this.guid === app.profile.id || !this.guid ? | ||
`ob/${this.type}` : `ipns/${this.guid}/${this.type}`); | ||
}, | ||
model(attrs, options) { | ||
return new Follower(attrs, options); | ||
} | ||
|
||
modelId(attrs) { | ||
return attrs.peerId; | ||
} | ||
|
||
model: UserShort, | ||
url() { | ||
return app.getServerUrl(`ob/${this.options.type === 'followers' ? 'followers' : 'following'}` + | ||
`${app.profile.id === this.options.peerId ? '' : `/${this.options.peerId}`}`); | ||
} | ||
|
||
parse(response) { | ||
return response.map((guid) => { | ||
// if a plain guid was passed in, convert it to an object | ||
if (typeof guid === 'string') return { guid }; | ||
return guid; | ||
}); | ||
}, | ||
}); | ||
return response.map(peerId => ({ peerId })); | ||
} | ||
} |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
/* Used as a list item of both follower and following lists */ | ||
|
||
import BaseModel from './BaseModel'; | ||
|
||
export default class extends BaseModel { | ||
// this model will only be { guid: exampleguid } | ||
|
||
get idAttribute() { | ||
return 'guid'; | ||
return 'peerId'; | ||
} | ||
} | ||
|
This file contains 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
This file contains 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
This file contains 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,2 @@ | ||
<div class="js-userCardsContainer userCardsContainer flexRow"></div> | ||
<div class="js-followLoadingContainer followLoadingContainer"></div> |
This file contains 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,13 @@ | ||
<% if (ob.isFetching) { %> | ||
<div class="loadingSpinnerWrap"> | ||
<% print(ob.spinner({ className: 'spinnerMd' })) %> | ||
</div> | ||
<% } else if (ob.fetchFailed) { %> | ||
<p><%= ob.fetchErrorTitle %></p> | ||
<% if (ob.fetchErrorMsg) { %> | ||
<p><%= ob.fetchErrorMsg %></p> | ||
<% } %> | ||
<button class="btn normalBtn clrP clrBr js-retry"><%= ob.polyT('userPage.followTab.btnRetry') %></button> | ||
<% } else if (ob.noResults) { %> | ||
<p><%= ob.noResultsMsg %></p> | ||
<% } %> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.