diff --git a/src/app/app.component.html b/src/app/app.component.html index 7bb51a4..6ea4d61 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1 +1 @@ - + diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 1ab201f..711d650 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -8,7 +8,7 @@ import { UsersComponent } from './users/users.component'; import { ProfileComponent } from './profile/profile.component'; import { FollowersComponent } from './profile/followers/followers.component'; import { FollowingComponent } from './profile/following/following.component'; -import { PostsComponent } from './profile/posts/posts.component'; +import { ProfilePostsComponent } from './profile/profile-posts/profile-posts.component'; export const routes: Routes = [ { path: '', redirectTo: '/sign-in', pathMatch: 'full' }, @@ -23,7 +23,7 @@ export const routes: Routes = [ { path: 'profile', component: ProfileComponent, canActivate: [authGuard], children: [ { path: '', redirectTo: 'posts', pathMatch: 'full' }, - { path: 'posts', component: PostsComponent }, + { path: 'posts', component: ProfilePostsComponent }, { path: 'followers', component: FollowersComponent }, { path: 'following', component: FollowingComponent } ] diff --git a/src/app/feed/post-dialog/post-dialog.component.ts b/src/app/feed/post-dialog/post-dialog.component.ts index ab74f85..519fd6f 100644 --- a/src/app/feed/post-dialog/post-dialog.component.ts +++ b/src/app/feed/post-dialog/post-dialog.component.ts @@ -43,6 +43,7 @@ export class PostDialogComponent { timestamp: serverTimestamp() } this.firestore.addPost(post, user!.uid); + this.postContent = ""; this.closeDialog(); } diff --git a/src/app/profile/followers/followers.component.html b/src/app/profile/followers/followers.component.html index c45d622..823f062 100644 --- a/src/app/profile/followers/followers.component.html +++ b/src/app/profile/followers/followers.component.html @@ -1 +1,8 @@ -

followers works!

+@for (user of usersWithFollowStatus$ | async; track $index) { + +} diff --git a/src/app/profile/followers/followers.component.ts b/src/app/profile/followers/followers.component.ts index fe245cf..c992a5e 100644 --- a/src/app/profile/followers/followers.component.ts +++ b/src/app/profile/followers/followers.component.ts @@ -1,12 +1,45 @@ -import { Component } from '@angular/core'; +import { Component, inject } from '@angular/core'; +import { Auth } from '@angular/fire/auth'; +import { UserRelationService } from '../../shared/services/firestore/user-relation.service'; +import { Observable, of } from 'rxjs'; +import { CommonModule } from '@angular/common'; +import { OtherUserComponent } from '../../shared/components/other-user/other-user.component'; +import { User } from '../../shared/types/User'; @Component({ selector: 'app-followers', standalone: true, - imports: [], + imports: [CommonModule, OtherUserComponent], templateUrl: './followers.component.html', styleUrl: './followers.component.scss' }) export class FollowersComponent { + private readonly auth: Auth = inject(Auth); + private readonly userRelations: UserRelationService = inject(UserRelationService); + usersWithFollowStatus$: Observable = of([]); + uid: string | undefined; + + ngOnInit() { + this.checkFollowStatus(); + this.uid = this.auth.currentUser?.uid; + } + + checkFollowStatus() { + if (this.auth.currentUser) { + this.usersWithFollowStatus$ = this.userRelations.getFollowersList(this.auth.currentUser.uid) + } + } + + followUser(followingUser: User) { + if (this.auth.currentUser) { + this.userRelations.followUser(this.auth.currentUser.uid, followingUser); + } + } + + unfollowUser(followingUserId: string) { + if (this.auth.currentUser) { + this.userRelations.unfollowUser(this.auth.currentUser.uid, followingUserId); + } + } } diff --git a/src/app/profile/following/following.component.ts b/src/app/profile/following/following.component.ts index 8ef25e5..fe72652 100644 --- a/src/app/profile/following/following.component.ts +++ b/src/app/profile/following/following.component.ts @@ -1,4 +1,8 @@ -import { Component } from '@angular/core'; +import { Component, inject } from '@angular/core'; +import { Auth } from '@angular/fire/auth'; +import { Observable, of } from 'rxjs'; +import { UserRelationService } from '../../shared/services/firestore/user-relation.service'; +import { User } from '../../shared/types/User'; @Component({ selector: 'app-following', @@ -9,4 +13,31 @@ import { Component } from '@angular/core'; }) export class FollowingComponent { + private readonly auth: Auth = inject(Auth); + private readonly userRelations: UserRelationService = inject(UserRelationService); + usersWithFollowStatus$: Observable = of([]); + uid: string | undefined; + ngOnInit() { + this.checkFollowStatus(); + this.uid = this.auth.currentUser?.uid; + } + + checkFollowStatus() { + if (this.auth.currentUser) { + this.usersWithFollowStatus$ = this.userRelations.getUsersWithFollowingStatus(this.auth.currentUser.uid) + } + } + + followUser(followingUser: User) { + if (this.auth.currentUser) { + this.userRelations.followUser(this.auth.currentUser.uid, followingUser); + } + } + + unfollowUser(followingUserId: string) { + if (this.auth.currentUser) { + this.userRelations.unfollowUser(this.auth.currentUser.uid, followingUserId); + } + } + } diff --git a/src/app/profile/posts/posts.component.html b/src/app/profile/posts/posts.component.html deleted file mode 100644 index 2c30d20..0000000 --- a/src/app/profile/posts/posts.component.html +++ /dev/null @@ -1 +0,0 @@ -

posts works!

diff --git a/src/app/profile/posts/posts.component.ts b/src/app/profile/posts/posts.component.ts deleted file mode 100644 index 488f158..0000000 --- a/src/app/profile/posts/posts.component.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Component } from '@angular/core'; - -@Component({ - selector: 'app-posts', - standalone: true, - imports: [], - templateUrl: './posts.component.html', - styleUrl: './posts.component.scss' -}) -export class PostsComponent { - -} diff --git a/src/app/profile/profile-posts/profile-posts.component.html b/src/app/profile/profile-posts/profile-posts.component.html new file mode 100644 index 0000000..d2f2083 --- /dev/null +++ b/src/app/profile/profile-posts/profile-posts.component.html @@ -0,0 +1,3 @@ +@for (post of posts; track $index) { + +} diff --git a/src/app/profile/posts/posts.component.scss b/src/app/profile/profile-posts/profile-posts.component.scss similarity index 100% rename from src/app/profile/posts/posts.component.scss rename to src/app/profile/profile-posts/profile-posts.component.scss diff --git a/src/app/profile/profile-posts/profile-posts.component.spec.ts b/src/app/profile/profile-posts/profile-posts.component.spec.ts new file mode 100644 index 0000000..ad04405 --- /dev/null +++ b/src/app/profile/profile-posts/profile-posts.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ProfilePostsComponent } from './profile-posts.component'; + +describe('ProfilePostsComponent', () => { + let component: ProfilePostsComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ProfilePostsComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(ProfilePostsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/profile/profile-posts/profile-posts.component.ts b/src/app/profile/profile-posts/profile-posts.component.ts new file mode 100644 index 0000000..9e02609 --- /dev/null +++ b/src/app/profile/profile-posts/profile-posts.component.ts @@ -0,0 +1,37 @@ +import { Component, inject } from '@angular/core'; +import { Auth } from '@angular/fire/auth'; +import { Post } from '../../shared/types/Post'; +import { PostsComponent } from '../../shared/components/posts/posts.component'; +import { UserRelationService } from '../../shared/services/firestore/user-relation.service'; +import { SnackbarService } from '../../shared/components/snackbar/snackbar.service'; + +@Component({ + selector: 'app-profile-posts', + standalone: true, + imports: [PostsComponent], + templateUrl: './profile-posts.component.html', + styleUrl: './profile-posts.component.scss' +}) +export class ProfilePostsComponent { + + private readonly auth: Auth = inject(Auth); + private readonly userRelations: UserRelationService = inject(UserRelationService); + private readonly snack: SnackbarService = inject(SnackbarService) + + posts: Post[] = []; + + + ngOnInit() { + if (this.auth.currentUser) { + this.userRelations.getPostsFromFollowing(this.auth.currentUser.uid) + .subscribe({ + next: (posts) => { + this.posts = posts; + }, + error: (error) => { + this.snack.show(error); + } + }); + } + } +} diff --git a/src/app/profile/profile.component.html b/src/app/profile/profile.component.html index d2d98ca..e9212cf 100644 --- a/src/app/profile/profile.component.html +++ b/src/app/profile/profile.component.html @@ -1,7 +1,9 @@
@if (userDetails) {