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

Commit

Permalink
Merge pull request #70 from NaturalSelectionLabs/feature/stop-axios-r…
Browse files Browse the repository at this point in the history
…equests
  • Loading branch information
DIYgod committed Oct 10, 2021
2 parents e0ccf0b + 7c8db26 commit b1960b0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/common/rss3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function walletConnect(skipSign?: boolean) {
return rss3;
}

async function visitor() {
async function visitor(): Promise<RSS3> {
if (rss3) {
return rss3;
} else {
Expand Down
51 changes: 37 additions & 14 deletions src/views/Followers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export default class Followers extends Vue {
rns: string = '';
ethAddress: string = '';
lastRoute: string = '';
isPageActive: boolean = false;
loadingNo: number = 0;
async setupAddress() {
const address = <string>this.$route.params.address;
Expand All @@ -85,32 +87,46 @@ export default class Followers extends Vue {
async initLoad() {
this.lastRoute = this.$route.fullPath;
this.followerList = [];
this.loadingNo = 0;
const rss3 = await RSS3.visitor();
const initFollowersList = await rss3.backlinks.get(this.ethAddress, 'following');
const followersList = _.reverse(initFollowersList);
if (rss3 && followersList) {
for (const item of followersList) {
this.followerList.push({
avatar: config.defaultAvatar,
username: '',
bio: '',
address: item,
displayAddress: this.filter(item),
rns: '',
});
}
setTimeout(() => {
this.loadDetails(rss3);
}, 0);
}
}
async loadDetails(rss3: IRSS3) {
const startNo = this.loadingNo;
const endNo = this.followerList.length;
for (let i = startNo; i < endNo; i++) {
if (this.isPageActive) {
const item = this.followerList[i];
try {
const profile = (await rss3.profile.get(item)) || {};
this.followerList.push({
avatar: profile.avatar?.[0] || config.defaultAvatar,
username: profile.name || '',
bio: profile.bio || '',
address: item,
displayAddress: this.filter(item),
rns: '',
});
const profile = (await rss3.profile.get(item.address)) || {};
item.avatar = profile.avatar?.[0] || config.defaultAvatar;
item.username = profile.name || '';
item.bio = profile.bio || '';
item.rns = (await RNSUtils.addr2Name(item.address)).replace(config.rns.suffix, '');
} catch (e) {
console.log(item, e);
}
this.loadingNo = i;
}
setTimeout(async () => {
for (const item of this.followerList) {
item.rns = (await RNSUtils.addr2Name(item.address)).replace(config.rns.suffix, '');
}
});
}
}
Expand Down Expand Up @@ -154,16 +170,23 @@ export default class Followers extends Vue {
}
async activated() {
this.isPageActive = true;
await this.setupAddress();
setTimeout(async () => {
await this.setupTheme();
await this.setPageTitleFavicon();
if (this.lastRoute !== this.$route.fullPath) {
await this.setProfile();
await this.initLoad();
} else if (this.loadingNo < this.followerList.length) {
await this.loadDetails(await RSS3.visitor());
}
}, 0);
}
async deactivated() {
this.isPageActive = false;
}
}
</script>

Expand Down
53 changes: 38 additions & 15 deletions src/views/Followings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { Options, Vue } from 'vue-class-component';
import Button from '@/components/Button.vue';
import ImgHolder from '@/components/ImgHolder.vue';
import FollowerCard from '@/components/FollowerCard.vue';
import RSS3 from '@/common/rss3';
import RSS3, { IRSS3 } from '@/common/rss3';
import RNSUtils from '@/common/rns';
import config from '@/config';
import * as _ from 'lodash';
Expand Down Expand Up @@ -70,6 +70,8 @@ export default class Followings extends Vue {
rns: string = '';
ethAddress: string = '';
lastRoute: string = '';
isPageActive: boolean = false;
loadingNo: number = 0;
async setupAddress() {
const address = <string>this.$route.params.address;
Expand All @@ -85,32 +87,46 @@ export default class Followings extends Vue {
async initLoad() {
this.lastRoute = this.$route.fullPath;
this.followingList = [];
this.loadingNo = 0;
const rss3 = await RSS3.visitor();
const initFollowersList = (await rss3.links.get(this.ethAddress, 'following'))?.list || [];
const followersList = _.reverse(initFollowersList);
if (rss3 && followersList) {
for (const item of followersList) {
this.followingList.push({
avatar: config.defaultAvatar,
username: '',
bio: '',
address: item,
displayAddress: this.filter(item),
rns: '',
});
}
setTimeout(() => {
this.loadDetails(rss3);
}, 0);
}
}
async loadDetails(rss3: IRSS3) {
const startNo = this.loadingNo;
const endNo = this.followingList.length;
for (let i = startNo; i < endNo; i++) {
if (this.isPageActive) {
const item = this.followingList[i];
try {
const profile = await rss3.profile.get(item);
this.followingList.push({
avatar: profile?.avatar?.[0] || config.defaultAvatar,
username: profile?.name || '',
bio: profile.bio || '',
address: item,
displayAddress: this.filter(item),
rns: '',
});
const profile = (await rss3.profile.get(item.address)) || {};
item.avatar = profile.avatar?.[0] || config.defaultAvatar;
item.username = profile.name || '';
item.bio = profile.bio || '';
item.rns = (await RNSUtils.addr2Name(item.address)).replace(config.rns.suffix, '');
} catch (e) {
console.log(item, e);
}
this.loadingNo = i;
}
setTimeout(async () => {
for (const item of this.followingList) {
item.rns = (await RNSUtils.addr2Name(item.address)).replace(config.rns.suffix, '');
}
});
}
}
Expand Down Expand Up @@ -154,16 +170,23 @@ export default class Followings extends Vue {
}
async activated() {
this.isPageActive = true;
await this.setupAddress();
setTimeout(async () => {
await this.setupTheme();
await this.setPageTitleFavicon();
if (this.lastRoute !== this.$route.fullPath) {
await this.setProfile();
await this.initLoad();
} else if (this.loadingNo < this.followingList.length) {
await this.loadDetails(await RSS3.visitor());
}
}, 0);
}
async deactivated() {
this.isPageActive = false;
}
}
</script>

Expand Down

0 comments on commit b1960b0

Please sign in to comment.