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

Commit

Permalink
feat: loading recover
Browse files Browse the repository at this point in the history
  • Loading branch information
Candinya committed Oct 10, 2021
1 parent e9b5d9d commit 7c8db26
Show file tree
Hide file tree
Showing 3 changed files with 54 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 @@ -79,7 +79,7 @@ async function walletConnect(skipSign?: boolean) {
return rss3;
}

async function visitor() {
async function visitor(): Promise<RSS3> {
if (rss3) {
return rss3;
} else {
Expand Down
40 changes: 26 additions & 14 deletions src/views/Followers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default class Followers extends Vue {
ethAddress: string = '';
lastRoute: string = '';
isPageActive: boolean = false;
loadingNo: number = 0;
async setupAddress() {
const address = <string>this.$route.params.address;
Expand All @@ -86,6 +87,7 @@ 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');
Expand All @@ -102,21 +104,29 @@ export default class Followers extends Vue {
rns: '',
});
}
setTimeout(async () => {
for (const item of this.followerList) {
if (this.isPageActive) {
try {
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);
}
}
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.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;
}
}
}
Expand Down Expand Up @@ -168,6 +178,8 @@ export default class Followers extends Vue {
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);
}
Expand Down
42 changes: 27 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 @@ -71,6 +71,7 @@ export default class Followings extends Vue {
ethAddress: string = '';
lastRoute: string = '';
isPageActive: boolean = false;
loadingNo: number = 0;
async setupAddress() {
const address = <string>this.$route.params.address;
Expand All @@ -86,6 +87,7 @@ 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 || [];
Expand All @@ -102,21 +104,29 @@ export default class Followings extends Vue {
rns: '',
});
}
setTimeout(async () => {
for (const item of this.followingList) {
if (this.isPageActive) {
try {
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);
}
}
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.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;
}
}
}
Expand Down Expand Up @@ -168,6 +178,8 @@ export default class Followings extends Vue {
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);
}
Expand Down

0 comments on commit 7c8db26

Please sign in to comment.