mirror of
https://github.com/block-core/blockcore-notes.git
synced 2024-09-29 06:20:42 +00:00
Load profiles on profile page and cache circles
This commit is contained in:
parent
0d3a94cdcc
commit
2d7e39d354
@ -14,6 +14,8 @@ export class CircleService {
|
||||
|
||||
private table;
|
||||
|
||||
circles: Circle[] = [];
|
||||
|
||||
cache = new CacheService();
|
||||
|
||||
items$ = from(liveQuery(() => this.items()));
|
||||
@ -44,6 +46,11 @@ export class CircleService {
|
||||
if (!defaultCircle) {
|
||||
await this.putCircle(CircleService.DEFAULT);
|
||||
}
|
||||
|
||||
// Cache the circle so we can lookup quickly.
|
||||
this.items$.subscribe((circles) => {
|
||||
this.circles = circles;
|
||||
});
|
||||
}
|
||||
|
||||
// async #filter(predicate: (value: Circle, key: string) => boolean): Promise<Circle[]> {
|
||||
@ -81,11 +88,16 @@ export class CircleService {
|
||||
// }
|
||||
|
||||
async getCircle(id?: number) {
|
||||
if (!id) {
|
||||
if (id == null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return this.table.get(id);
|
||||
// Use the cache if loaded already.
|
||||
if (this.circles.length > 0) {
|
||||
return this.circles.find((c) => c.id == id);
|
||||
} else {
|
||||
return this.table.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
async putCircle(document: Circle | any) {
|
||||
|
@ -92,32 +92,35 @@ export class UserComponent {
|
||||
}
|
||||
|
||||
this.pubkey = pubkey;
|
||||
// this.profile = await this.profiles.getProfile(pubkey);
|
||||
|
||||
if (!this.profile) {
|
||||
this.profile = this.profiles.emptyProfile(pubkey);
|
||||
this.circle = undefined;
|
||||
}
|
||||
this.profiles.getProfile(pubkey).subscribe(async (profile) => {
|
||||
this.profile = profile;
|
||||
|
||||
this.npub = this.utilities.getNostrIdentifier(pubkey);
|
||||
|
||||
if (!this.profile.name) {
|
||||
this.profile.name = this.npub;
|
||||
}
|
||||
|
||||
this.profileName = this.profile.name;
|
||||
|
||||
if (this.profileName)
|
||||
if (!this.profile.display_name) {
|
||||
this.profile.display_name = this.profileName;
|
||||
if (!this.profile) {
|
||||
this.profile = this.profiles.emptyProfile(pubkey);
|
||||
this.circle = undefined;
|
||||
}
|
||||
|
||||
this.imagePath = this.profile.picture || '/assets/profile.png';
|
||||
this.npub = this.utilities.getNostrIdentifier(pubkey);
|
||||
|
||||
this.circle = await this.circleService.getCircle(this.profile.circle);
|
||||
|
||||
// If the user has name in their profile, show that and not pubkey.
|
||||
this.appState.title = `@${this.profile.name}`;
|
||||
if (!this.profile.name) {
|
||||
this.profile.name = this.npub;
|
||||
}
|
||||
|
||||
this.profileName = this.profile.name;
|
||||
|
||||
if (this.profileName)
|
||||
if (!this.profile.display_name) {
|
||||
this.profile.display_name = this.profileName;
|
||||
}
|
||||
|
||||
this.imagePath = this.profile.picture || '/assets/profile.png';
|
||||
|
||||
this.circle = await this.circleService.getCircle(this.profile.circle);
|
||||
|
||||
// If the user has name in their profile, show that and not pubkey.
|
||||
this.appState.title = `@${this.profile.name}`;
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user