order posts by publishing date
This commit is contained in:
parent
dfe4b1b00d
commit
d3246d082c
@ -20,7 +20,7 @@ export class PostService {
|
||||
let result: Array<Post> = new Array<Post>();
|
||||
let currentUser = await this.usersvc.getCurrentUser();
|
||||
|
||||
let posts = await firstValueFrom(this.afs.collection('post').valueChanges({ idField: 'id' }));
|
||||
let posts = await firstValueFrom(this.afs.collection('post', ref => ref.orderBy('date', 'desc')).valueChanges({ idField: 'id' }));
|
||||
posts.forEach(async post=>{
|
||||
let user = await firstValueFrom(this.afs.doc((post as any).user).valueChanges()) as User;
|
||||
|
||||
@ -51,7 +51,7 @@ export class PostService {
|
||||
// /user -> currentUser
|
||||
let user = await this.usersvc.getCurrentUser();
|
||||
let userRef = this.afs.doc('/user/' + user.username).ref;
|
||||
let posts = (await firstValueFrom(this.afs.collection<Post>('post', ref => ref.where('user', '==', userRef)).valueChanges({ idField: 'id' })));
|
||||
let posts = (await firstValueFrom(this.afs.collection<Post>('post', ref => ref.where('user', '==', userRef).orderBy('date', 'desc')).valueChanges({ idField: 'id' })));
|
||||
posts.forEach(async (post) => {
|
||||
let likes = await firstValueFrom(this.afs.collection('like', ref => ref.where('post', '==', this.afs.doc('/post/' + post.id).ref)).valueChanges());
|
||||
result.push({
|
||||
@ -70,7 +70,7 @@ export class PostService {
|
||||
let user = await this.usersvc.getUser(username);
|
||||
let userRef = this.afs.doc('/user/' + user.username).ref;
|
||||
let currentUser = await this.usersvc.getCurrentUser();
|
||||
let posts = (await firstValueFrom(this.afs.collection<Post>('post', ref => ref.where('user', '==', userRef)).valueChanges({ idField: 'id' })));
|
||||
let posts = (await firstValueFrom(this.afs.collection<Post>('post', ref => ref.where('user', '==', userRef).orderBy('date', 'desc')).valueChanges({ idField: 'id' })));
|
||||
posts.forEach(async (post) => {
|
||||
let likes = await firstValueFrom(this.afs.collection('like', ref => ref.where('post', '==', this.afs.doc('/post/' + post.id).ref)).valueChanges());
|
||||
result.push({
|
||||
@ -96,7 +96,8 @@ export class PostService {
|
||||
this.afs.collection('post').add({
|
||||
user: this.afs.doc('/user/' + user.username).ref,
|
||||
content: content,
|
||||
image: image
|
||||
image: image,
|
||||
date: Date.now()
|
||||
})
|
||||
.then(() => resolve())
|
||||
.catch(() => reject())
|
||||
|
Loading…
Reference in New Issue
Block a user