From db407fc24fd9aa52d0b4cb583e6a546ca0ee4a4b Mon Sep 17 00:00:00 2001 From: marktechson <2554588+MarkTechson@users.noreply.github.com> Date: Thu, 7 Mar 2024 17:10:35 -0600 Subject: [PATCH 01/10] add refactor of code to use ngFor and ngIf as well as become standalone --- angularfire-start/src/app/app.component.ts | 4 ++ angularfire-start/src/app/app.config.ts | 12 ++++ angularfire-start/src/app/app.module.ts | 43 -------------- angularfire-start/src/app/app.routes.ts | 32 ++++++++++ .../components/header/header.component.html | 59 ++++++++++--------- .../app/components/header/header.component.ts | 1 + .../pages/chat-page/chat-page.component.html | 34 +++++++---- .../pages/chat-page/chat-page.component.ts | 1 + .../pages/login-page/login-page.component.ts | 1 + angularfire-start/src/main.ts | 12 ++-- 10 files changed, 108 insertions(+), 91 deletions(-) create mode 100644 angularfire-start/src/app/app.config.ts delete mode 100644 angularfire-start/src/app/app.module.ts create mode 100644 angularfire-start/src/app/app.routes.ts diff --git a/angularfire-start/src/app/app.component.ts b/angularfire-start/src/app/app.component.ts index e45e9d8ca..678855ded 100644 --- a/angularfire-start/src/app/app.component.ts +++ b/angularfire-start/src/app/app.component.ts @@ -1,9 +1,13 @@ import { Component } from '@angular/core'; +import { HeaderComponent } from './components/header/header.component'; +import { RouterModule } from '@angular/router'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], + standalone: true, + imports: [HeaderComponent, RouterModule], }) export class AppComponent { title = 'friendlychat'; diff --git a/angularfire-start/src/app/app.config.ts b/angularfire-start/src/app/app.config.ts new file mode 100644 index 000000000..5f405a3c6 --- /dev/null +++ b/angularfire-start/src/app/app.config.ts @@ -0,0 +1,12 @@ +import { ApplicationConfig } from "@angular/core"; +import { initializeApp, provideFirebaseApp } from '@angular/fire/app'; +import { environment } from '../environments/environment'; +import { provideAuth, getAuth, connectAuthEmulator } from '@angular/fire/auth'; +import { provideFirestore, getFirestore, connectFirestoreEmulator } from '@angular/fire/firestore'; +import { provideFunctions, getFunctions, connectFunctionsEmulator } from '@angular/fire/functions'; +import { provideMessaging, getMessaging } from '@angular/fire/messaging'; +import { provideStorage, getStorage, connectStorageEmulator } from '@angular/fire/storage'; + +export const appConfig: ApplicationConfig = { + providers: [], +} \ No newline at end of file diff --git a/angularfire-start/src/app/app.module.ts b/angularfire-start/src/app/app.module.ts deleted file mode 100644 index a46708965..000000000 --- a/angularfire-start/src/app/app.module.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { NgModule } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -import { CommonModule } from '@angular/common'; -import { FormsModule } from '@angular/forms'; - -import { AppRoutingModule } from './app-routing.module'; -import { AppComponent } from './app.component'; -import { initializeApp, provideFirebaseApp } from '@angular/fire/app'; -import { environment } from '../environments/environment'; -import { provideAuth, getAuth, connectAuthEmulator } from '@angular/fire/auth'; -import { - provideFirestore, - getFirestore, - connectFirestoreEmulator, -} from '@angular/fire/firestore'; -import { - provideFunctions, - getFunctions, - connectFunctionsEmulator, -} from '@angular/fire/functions'; -import { provideMessaging, getMessaging } from '@angular/fire/messaging'; -import { - provideStorage, - getStorage, - connectStorageEmulator, -} from '@angular/fire/storage'; - -import { LoginPageComponent } from './pages/login-page/login-page.component'; -import { ChatPageComponent } from './pages/chat-page/chat-page.component'; -import { HeaderComponent } from './components/header/header.component'; - -@NgModule({ - declarations: [ - AppComponent, - LoginPageComponent, - ChatPageComponent, - HeaderComponent, - ], - imports: [BrowserModule, AppRoutingModule, CommonModule, FormsModule], - providers: [], - bootstrap: [AppComponent], -}) -export class AppModule {} diff --git a/angularfire-start/src/app/app.routes.ts b/angularfire-start/src/app/app.routes.ts new file mode 100644 index 000000000..1d386138e --- /dev/null +++ b/angularfire-start/src/app/app.routes.ts @@ -0,0 +1,32 @@ +import { RouterModule, Routes } from '@angular/router'; +import { + AuthGuard, + redirectLoggedInTo, + redirectUnauthorizedTo, +} from '@angular/fire/auth-guard'; +import { LoginPageComponent } from './pages/login-page/login-page.component'; +import { ChatPageComponent } from './pages/chat-page/chat-page.component'; + +const redirectUnauthorizedToLogin = () => redirectUnauthorizedTo(['login']); +const redirectLoggedInToHome = () => redirectLoggedInTo(['chat']); + +export const routes: Routes = [ + { + path: '', + component: LoginPageComponent, + canActivate: [AuthGuard], + data: { authGuardPipe: redirectLoggedInToHome }, + }, + { + path: 'login', + component: LoginPageComponent, + canActivate: [AuthGuard], + data: { authGuardPipe: redirectLoggedInToHome }, + }, + { + path: 'chat', + component: ChatPageComponent, + canActivate: [AuthGuard], + data: { authGuardPipe: redirectUnauthorizedToLogin }, + }, +]; diff --git a/angularfire-start/src/app/components/header/header.component.html b/angularfire-start/src/app/components/header/header.component.html index dec33c9c8..88303f04b 100644 --- a/angularfire-start/src/app/components/header/header.component.html +++ b/angularfire-start/src/app/components/header/header.component.html @@ -7,37 +7,38 @@ Friendly Chat -