├── .gitignore ├── README.md ├── angular.json ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.e2e.json ├── ionic.config.json ├── package-lock.json ├── package.json ├── src ├── app │ ├── add-task-modal │ │ ├── add-task-modal.component.html │ │ ├── add-task-modal.component.scss │ │ ├── add-task-modal.component.spec.ts │ │ └── add-task-modal.component.ts │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── home │ │ ├── home.module.ts │ │ ├── home.page.html │ │ ├── home.page.scss │ │ ├── home.page.spec.ts │ │ └── home.page.ts │ └── store │ │ ├── firestore-services.ts │ │ ├── main-actions.ts │ │ ├── main-effects.ts │ │ └── main-reducer.ts ├── assets │ └── icon │ │ └── favicon.png ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── global.scss ├── index.html ├── karma.conf.js ├── main.ts ├── polyfills.ts ├── test.ts ├── theme │ └── variables.scss ├── tsconfig.app.json └── tsconfig.spec.json ├── tsconfig.json └── tslint.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Specifies intentionally untracked files to ignore when using Git 2 | # http://git-scm.com/docs/gitignore 3 | 4 | *~ 5 | *.sw[mnpcod] 6 | *.log 7 | *.tmp 8 | *.tmp.* 9 | log.txt 10 | *.sublime-project 11 | *.sublime-workspace 12 | .vscode/ 13 | npm-debug.log* 14 | 15 | .idea/ 16 | .ionic/ 17 | .sourcemaps/ 18 | .sass-cache/ 19 | .tmp/ 20 | .versions/ 21 | coverage/ 22 | www/ 23 | node_modules/ 24 | tmp/ 25 | temp/ 26 | platforms/ 27 | plugins/ 28 | plugins/android.json 29 | plugins/ios.json 30 | $RECYCLE.BIN/ 31 | 32 | .DS_Store 33 | Thumbs.db 34 | UserInterfaceState.xcuserstate 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ionic4 Firebase Firestore w/ state management using ngrx 2 | > Should be complete 3 | ## A basic application for Ionic 4 4 | 5 | - Login with email address & password 6 | - Automatically login if a session already exists 7 | - Create accounts 8 | - Login with Account 9 | - Integration of ngrx/store & ngrx/effects to manage state 10 | - Query List Objects 11 | - Find a specific List Object 12 | 13 | 14 | ``` 15 | Ionic: 16 | 17 | ionic (Ionic CLI) : 4.1.1 (/Users/aaronsaunders/.nvm/versions/node/v9.3.0/lib/node_modules/ionic) 18 | Ionic Framework : @ionic/angular 4.0.0-beta.3 19 | @angular-devkit/core : 0.7.5 20 | @angular-devkit/schematics : 0.7.5 21 | @angular/cli : 6.1.5 22 | @ionic/ng-toolkit : 1.0.7 23 | @ionic/schematics-angular : 1.0.5 24 | 25 | System: 26 | 27 | NodeJS : v9.3.0 (/Users/aaronsaunders/.nvm/versions/node/v9.3.0/bin/node) 28 | npm : 6.4.0 29 | OS : macOS High Sierra 30 | ``` 31 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json", 3 | "version": 1, 4 | "defaultProject": "app", 5 | "projects": { 6 | "app": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "progress": false, 17 | "outputPath": "www", 18 | "index": "src/index.html", 19 | "main": "src/main.ts", 20 | "polyfills": "src/polyfills.ts", 21 | "tsConfig": "src/tsconfig.app.json", 22 | "assets": [ 23 | { 24 | "glob": "**/*", 25 | "input": "src/assets", 26 | "output": "assets" 27 | }, 28 | { 29 | "glob": "**/*.svg", 30 | "input": "node_modules/@ionic/angular/dist/ionic/svg", 31 | "output": "./svg" 32 | } 33 | ], 34 | "styles": [ 35 | { 36 | "input": "src/theme/variables.scss" 37 | }, 38 | { 39 | "input": "src/global.scss" 40 | } 41 | ], 42 | "scripts": [] 43 | }, 44 | "configurations": { 45 | "production": { 46 | "fileReplacements": [ 47 | { 48 | "replace": "src/environments/environment.ts", 49 | "with": "src/environments/environment.prod.ts" 50 | } 51 | ], 52 | "optimization": true, 53 | "outputHashing": "all", 54 | "sourceMap": false, 55 | "extractCss": true, 56 | "namedChunks": false, 57 | "aot": true, 58 | "extractLicenses": true, 59 | "vendorChunk": false, 60 | "buildOptimizer": true 61 | } 62 | } 63 | }, 64 | "serve": { 65 | "builder": "@angular-devkit/build-angular:dev-server", 66 | "options": { 67 | "browserTarget": "app:build" 68 | }, 69 | "configurations": { 70 | "production": { 71 | "browserTarget": "app:build:production" 72 | } 73 | } 74 | }, 75 | "extract-i18n": { 76 | "builder": "@angular-devkit/build-angular:extract-i18n", 77 | "options": { 78 | "browserTarget": "app:build" 79 | } 80 | }, 81 | "test": { 82 | "builder": "@angular-devkit/build-angular:karma", 83 | "options": { 84 | "main": "src/test.ts", 85 | "polyfills": "src/polyfills.ts", 86 | "tsConfig": "src/tsconfig.spec.json", 87 | "karmaConfig": "src/karma.conf.js", 88 | "styles": [ 89 | "styles.css" 90 | ], 91 | "scripts": [], 92 | "assets": [ 93 | { 94 | "glob": "favicon.ico", 95 | "input": "src/", 96 | "output": "/" 97 | }, 98 | { 99 | "glob": "**/*", 100 | "input": "src/assets", 101 | "output": "/assets" 102 | } 103 | ] 104 | } 105 | }, 106 | "lint": { 107 | "builder": "@angular-devkit/build-angular:tslint", 108 | "options": { 109 | "tsConfig": [ 110 | "src/tsconfig.app.json", 111 | "src/tsconfig.spec.json" 112 | ], 113 | "exclude": [ 114 | "**/node_modules/**" 115 | ] 116 | } 117 | }, 118 | "ionic-cordova-build": { 119 | "builder": "@ionic/ng-toolkit:cordova-build", 120 | "options": { 121 | "browserTarget": "app:build" 122 | }, 123 | "configurations": { 124 | "production": { 125 | "browserTarget": "app:build:production" 126 | } 127 | } 128 | }, 129 | "ionic-cordova-serve": { 130 | "builder": "@ionic/ng-toolkit:cordova-serve", 131 | "options": { 132 | "cordovaBuildTarget": "app:ionic-cordova-build", 133 | "devServerTarget": "app:serve" 134 | }, 135 | "configurations": { 136 | "production": { 137 | "cordovaBuildTarget": "app:ionic-cordova-build:production", 138 | "devServerTarget": "app:serve:production" 139 | } 140 | } 141 | } 142 | } 143 | }, 144 | "app-e2e": { 145 | "root": "e2e/", 146 | "projectType": "application", 147 | "architect": { 148 | "e2e": { 149 | "builder": "@angular-devkit/build-angular:protractor", 150 | "options": { 151 | "protractorConfig": "e2e/protractor.conf.js", 152 | "devServerTarget": "app:serve" 153 | } 154 | }, 155 | "lint": { 156 | "builder": "@angular-devkit/build-angular:tslint", 157 | "options": { 158 | "tsConfig": "e2e/tsconfig.e2e.json", 159 | "exclude": [ 160 | "**/node_modules/**" 161 | ] 162 | } 163 | } 164 | } 165 | } 166 | }, 167 | "cli": { 168 | "defaultCollection": "@ionic/schematics-angular" 169 | }, 170 | "schematics": { 171 | "@ionic/schematics-angular:component": { 172 | "styleext": "scss" 173 | }, 174 | "@ionic/schematics-angular:page": { 175 | "styleext": "scss" 176 | } 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('new App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toContain('The world is your oyster.'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.deepCss('app-root ion-content')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ionic.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic4-ngrx-angularfire", 3 | "integrations": {}, 4 | "type": "angular" 5 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic4-ngrx-angularfire", 3 | "version": "0.0.1", 4 | "author": "Ionic Framework", 5 | "homepage": "http://ionicframework.com/", 6 | "scripts": { 7 | "ng": "ng", 8 | "start": "ng serve", 9 | "build": "ng build", 10 | "test": "ng test", 11 | "lint": "ng lint", 12 | "e2e": "ng e2e" 13 | }, 14 | "private": true, 15 | "dependencies": { 16 | "@angular/common": "~6.1.1", 17 | "@angular/core": "~6.1.1", 18 | "@angular/forms": "~6.1.1", 19 | "@angular/http": "~6.1.1", 20 | "@angular/platform-browser": "~6.1.1", 21 | "@angular/platform-browser-dynamic": "~6.1.1", 22 | "@angular/router": "~6.1.1", 23 | "@ionic-native/core": "5.0.0-beta.14", 24 | "@ionic-native/splash-screen": "5.0.0-beta.14", 25 | "@ionic-native/status-bar": "5.0.0-beta.14", 26 | "@ionic/angular": "^4.0.0-beta.0", 27 | "@ngrx/effects": "^6.1.0", 28 | "@ngrx/store": "^6.1.0", 29 | "@ngrx/store-devtools": "^6.1.0", 30 | "core-js": "^2.5.3", 31 | "firebase": "^5.4.1", 32 | "rxjs": "6.2.2", 33 | "zone.js": "^0.8.26" 34 | }, 35 | "devDependencies": { 36 | "@angular/cli": "~6.1.1", 37 | "@angular/compiler": "~6.1.1", 38 | "@angular/compiler-cli": "~6.1.1", 39 | "@angular/language-service": "~6.1.1", 40 | "@angular-devkit/architect": "~0.7.2", 41 | "@angular-devkit/build-angular": "~0.7.2", 42 | "@angular-devkit/core": "~0.7.2", 43 | "@angular-devkit/schematics": "~0.7.2", 44 | "@ionic/ng-toolkit": "^1.0.0", 45 | "@ionic/schematics-angular": "^1.0.0", 46 | "@types/jasmine": "~2.8.6", 47 | "@types/jasminewd2": "~2.0.3", 48 | "@types/node": "~10.7.1", 49 | "codelyzer": "~4.4.2", 50 | "jasmine-core": "~2.99.1", 51 | "jasmine-spec-reporter": "~4.2.1", 52 | "karma": "~3.0.0", 53 | "karma-chrome-launcher": "~2.2.0", 54 | "karma-coverage-istanbul-reporter": "~2.0.0", 55 | "karma-jasmine": "~1.1.1", 56 | "karma-jasmine-html-reporter": "^0.2.2", 57 | "protractor": "~5.4.0", 58 | "ts-node": "~7.0.0", 59 | "tslint": "~5.11.0", 60 | "typescript": "~2.7.2" 61 | }, 62 | "description": "An Ionic project" 63 | } 64 | -------------------------------------------------------------------------------- /src/app/add-task-modal/add-task-modal.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Super Modal 4 | 5 | 6 | 7 |

Task Entry

8 | 9 | Floating Label 10 | 11 | 12 | 13 | Floating Label 14 | 15 | 16 | 17 | Action Sheet 18 | 20 | HIGH 21 | MEDIUM 22 | LOW 23 | 24 | 25 | SAVE 26 | CANCEL 27 |
-------------------------------------------------------------------------------- /src/app/add-task-modal/add-task-modal.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronksaunders/ionic4-ngrx-firebase/79381b3392d3077245a85db26d0372dddcaef1f0/src/app/add-task-modal/add-task-modal.component.scss -------------------------------------------------------------------------------- /src/app/add-task-modal/add-task-modal.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AddTaskModalComponent } from './add-task-modal.component'; 4 | 5 | describe('AddTaskModalComponent', () => { 6 | let component: AddTaskModalComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AddTaskModalComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AddTaskModalComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/add-task-modal/add-task-modal.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input } from "@angular/core"; 2 | import { ModalController } from "@ionic/angular"; 3 | 4 | @Component({ 5 | selector: "app-add-task-modal", 6 | templateUrl: "./add-task-modal.component.html", 7 | styleUrls: ["./add-task-modal.component.scss"] 8 | }) 9 | export class AddTaskModalComponent implements OnInit { 10 | customActionSheetOptions: any = { 11 | header: "Colors", 12 | subHeader: "Select your favorite color" 13 | }; 14 | 15 | task = {}; 16 | value: any; 17 | 18 | constructor(public modalController: ModalController) {} 19 | 20 | ngOnInit() { 21 | console.log(this.value); 22 | } 23 | 24 | dismissModal() { 25 | this.modalController.dismiss({ ...this.task }); 26 | } 27 | 28 | cancelModal() { 29 | this.modalController.dismiss({ cancelled: true }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | const routes: Routes = [ 5 | { path: '', redirectTo: 'home', pathMatch: 'full' }, 6 | { path: 'home', loadChildren: './home/home.module#HomePageModule' }, 7 | ]; 8 | 9 | @NgModule({ 10 | imports: [RouterModule.forRoot(routes)], 11 | exports: [RouterModule] 12 | }) 13 | export class AppRoutingModule { } 14 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 2 | import { TestBed, async } from '@angular/core/testing'; 3 | 4 | import { Platform } from '@ionic/angular'; 5 | import { SplashScreen } from '@ionic-native/splash-screen/ngx'; 6 | import { StatusBar } from '@ionic-native/status-bar/ngx'; 7 | 8 | import { AppComponent } from './app.component'; 9 | 10 | describe('AppComponent', () => { 11 | 12 | let statusBarSpy, splashScreenSpy, platformReadySpy, platformSpy; 13 | 14 | beforeEach(async(() => { 15 | statusBarSpy = jasmine.createSpyObj('StatusBar', ['styleDefault']); 16 | splashScreenSpy = jasmine.createSpyObj('SplashScreen', ['hide']); 17 | platformReadySpy = Promise.resolve(); 18 | platformSpy = jasmine.createSpyObj('Platform', { ready: platformReadySpy }); 19 | 20 | TestBed.configureTestingModule({ 21 | declarations: [AppComponent], 22 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 23 | providers: [ 24 | { provide: StatusBar, useValue: statusBarSpy }, 25 | { provide: SplashScreen, useValue: splashScreenSpy }, 26 | { provide: Platform, useValue: platformSpy }, 27 | ], 28 | }).compileComponents(); 29 | })); 30 | 31 | it('should create the app', () => { 32 | const fixture = TestBed.createComponent(AppComponent); 33 | const app = fixture.debugElement.componentInstance; 34 | expect(app).toBeTruthy(); 35 | }); 36 | 37 | it('should initialize the app', async () => { 38 | TestBed.createComponent(AppComponent); 39 | expect(platformSpy.ready).toHaveBeenCalled(); 40 | await platformReadySpy; 41 | expect(statusBarSpy.styleDefault).toHaveBeenCalled(); 42 | expect(splashScreenSpy.hide).toHaveBeenCalled(); 43 | }); 44 | 45 | // TODO: add more tests! 46 | 47 | }); 48 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from "@angular/core"; 2 | 3 | import { Platform } from "@ionic/angular"; 4 | import { SplashScreen } from "@ionic-native/splash-screen/ngx"; 5 | import { StatusBar } from "@ionic-native/status-bar/ngx"; 6 | 7 | @Component({ 8 | selector: "app-root", 9 | templateUrl: "app.component.html" 10 | }) 11 | export class AppComponent { 12 | constructor( 13 | private platform: Platform, 14 | private splashScreen: SplashScreen, 15 | private statusBar: StatusBar 16 | ) { 17 | this.initializeApp(); 18 | } 19 | 20 | initializeApp() { 21 | this.platform.ready().then(() => { 22 | this.statusBar.styleDefault(); 23 | this.splashScreen.hide(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from "@angular/core"; 2 | import { BrowserModule } from "@angular/platform-browser"; 3 | import { RouterModule, RouteReuseStrategy, Routes } from "@angular/router"; 4 | 5 | import { IonicModule, IonicRouteStrategy } from "@ionic/angular"; 6 | import { SplashScreen } from "@ionic-native/splash-screen/ngx"; 7 | import { StatusBar } from "@ionic-native/status-bar/ngx"; 8 | 9 | import { AppComponent } from "./app.component"; 10 | import { AppRoutingModule } from "./app-routing.module"; 11 | 12 | // FORMS 13 | import { FormsModule, ReactiveFormsModule } from "@angular/forms"; 14 | 15 | // NGRX 16 | import { StoreModule } from "@ngrx/store"; 17 | import { mainAppStoreReducer } from '../app/store/main-reducer'; 18 | import { StoreDevtoolsModule } from '@ngrx/store-devtools'; 19 | import { EffectsModule } from "@ngrx/effects"; 20 | import { MainEffects } from "./store/main-effects"; 21 | import { AddTaskModalComponent } from './add-task-modal/add-task-modal.component'; 22 | 23 | 24 | @NgModule({ 25 | declarations: [AppComponent, AddTaskModalComponent], 26 | entryComponents: [ 27 | AddTaskModalComponent 28 | ], 29 | imports: [ 30 | FormsModule, 31 | ReactiveFormsModule, 32 | BrowserModule, 33 | StoreModule.forRoot({ app: mainAppStoreReducer }), 34 | IonicModule.forRoot(), 35 | AppRoutingModule, 36 | EffectsModule.forRoot([MainEffects]), 37 | StoreDevtoolsModule.instrument() 38 | ], 39 | providers: [ 40 | StatusBar, 41 | SplashScreen, 42 | { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } 43 | ], 44 | bootstrap: [AppComponent] 45 | }) 46 | export class AppModule {} 47 | -------------------------------------------------------------------------------- /src/app/home/home.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { IonicModule } from '@ionic/angular'; 4 | import { FormsModule } from '@angular/forms'; 5 | import { RouterModule } from '@angular/router'; 6 | 7 | import { HomePage } from './home.page'; 8 | 9 | @NgModule({ 10 | imports: [ 11 | CommonModule, 12 | FormsModule, 13 | IonicModule, 14 | RouterModule.forChild([ 15 | { 16 | path: '', 17 | component: HomePage 18 | } 19 | ]) 20 | ], 21 | declarations: [HomePage] 22 | }) 23 | export class HomePageModule {} 24 | -------------------------------------------------------------------------------- /src/app/home/home.page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | AngularFire Ionic4 NGRX 4 | 5 | 6 | ADD 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |

Error: {{ (storeInfo | async)?.error }}

20 |
21 |
22 |
23 |
24 | 25 |
26 |
27 | 28 | Username 29 | 31 | 32 | 33 |

35 | Username is required 36 |

37 | 38 | 39 | Password 40 | 42 | 43 | 44 |

46 | Password is required 47 |

48 | 49 | 50 | 51 | Login 52 | 53 | 54 | Create 55 | User 56 | 57 | 58 | 59 | 60 |
61 |
62 |
63 | 64 | LOGOUT 65 | 66 | 67 | 68 | 69 |
{{item | json }}
70 | DELETE 71 |
72 |
73 |
74 |
75 |
-------------------------------------------------------------------------------- /src/app/home/home.page.scss: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/app/home/home.page.spec.ts: -------------------------------------------------------------------------------- 1 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | 4 | import { HomePage } from './home.page'; 5 | 6 | describe('HomePage', () => { 7 | let component: HomePage; 8 | let fixture: ComponentFixture; 9 | 10 | beforeEach(async(() => { 11 | TestBed.configureTestingModule({ 12 | declarations: [ HomePage ], 13 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 14 | }) 15 | .compileComponents(); 16 | })); 17 | 18 | beforeEach(() => { 19 | fixture = TestBed.createComponent(HomePage); 20 | component = fixture.componentInstance; 21 | fixture.detectChanges(); 22 | }); 23 | 24 | it('should create', () => { 25 | expect(component).toBeTruthy(); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /src/app/home/home.page.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from "@angular/core"; 2 | import { FormGroup } from "@angular/forms"; 3 | 4 | // NGRX 5 | import { Store, select } from "@ngrx/store"; 6 | import { 7 | AppState, 8 | selectUser, 9 | selectData, 10 | selectDataAction 11 | } from "../store/main-reducer"; 12 | import { 13 | All, 14 | CREATE_FIREBASE_OBJECT_SUCCESS, 15 | DELETE_FIREBASE_OBJECT_SUCCESS, 16 | UPDATE_FIREBASE_OBJECT_SUCCESS 17 | } from "../store/main-actions"; 18 | import { ModalController, ToastController } from "@ionic/angular"; 19 | import { AddTaskModalComponent } from "../add-task-modal/add-task-modal.component"; 20 | 21 | @Component({ 22 | selector: "app-home", 23 | templateUrl: "home.page.html", 24 | styleUrls: ["home.page.scss"] 25 | }) 26 | export class HomePage { 27 | loginForm: FormGroup; 28 | storeInfo; 29 | credentials: { email?: string; password?: string } = {}; 30 | cu$; 31 | data$; 32 | 33 | /** 34 | * 35 | * @param store 36 | */ 37 | constructor( 38 | public store: Store, 39 | public modalController: ModalController, 40 | public toastController: ToastController 41 | ) { 42 | // use the object in the template since it is an observable 43 | this.storeInfo = this.store.select("app"); 44 | 45 | // dispatch action to see if we have a current user 46 | this.store.dispatch(new All().checkAuthAction()); 47 | 48 | // create observable for user and for data array 49 | // that are contained in the store 50 | this.cu$ = this.store.pipe(select(selectUser)); 51 | this.data$ = this.store.pipe(select(selectData)); 52 | 53 | // check and see if we have a user, if so then get the data 54 | // for the display 55 | this.store.pipe(select(selectUser)).subscribe(currentUser => { 56 | if (currentUser) { 57 | this.store.dispatch(new All().fetchFirebaseArrayAction("new-test")); 58 | } 59 | }); 60 | 61 | // check and see if we have successfully added an object, if so 62 | // display success alert and clear flag on state 63 | this.store.pipe(select(selectDataAction)).subscribe(action => { 64 | if (action) { 65 | console.log(action); 66 | 67 | if (action.action) { 68 | let message = ""; 69 | switch (action.action) { 70 | case CREATE_FIREBASE_OBJECT_SUCCESS: 71 | message = "Object Created Successfully"; 72 | break; 73 | 74 | case DELETE_FIREBASE_OBJECT_SUCCESS: 75 | message = "Object Deleted Successfully"; 76 | break; 77 | 78 | case UPDATE_FIREBASE_OBJECT_SUCCESS: 79 | message = "Object Updated Successfully"; 80 | break; 81 | 82 | default: 83 | break; 84 | } 85 | this.doToast(message); 86 | this.store.dispatch(new All().clearSuccessAction()); 87 | } 88 | } 89 | }); 90 | } 91 | 92 | async doToast(_message) { 93 | const toast = await this.toastController.create({ 94 | message: _message, 95 | duration: 2000 96 | }); 97 | toast.present(); 98 | } 99 | doLogout() { 100 | this.store.dispatch(new All().logoutAction()); 101 | } 102 | 103 | doLogin(_credentials) { 104 | if (_credentials.valid) { 105 | this.store.dispatch(new All().loginAction(_credentials.value)); 106 | } 107 | } 108 | 109 | doCreateUser(_credentials) { 110 | if (_credentials.valid) { 111 | this.store.dispatch(new All().createUserAction(_credentials.value)); 112 | } 113 | } 114 | 115 | doCreateObject(_inputData) { 116 | this.store.dispatch( 117 | new All().createFirebaseObject({ 118 | objectType: "new-test", 119 | objectData: { 120 | ..._inputData, 121 | created: new Date() 122 | } 123 | }) 124 | ); 125 | } 126 | 127 | doDeleteObject(_inputData) { 128 | this.store.dispatch( 129 | new All().deleteFirebaseObject({ 130 | objectType: "new-test", 131 | objectId: _inputData.id 132 | }) 133 | ); 134 | } 135 | 136 | async presentModal() { 137 | const modal = await this.modalController.create({ 138 | component: AddTaskModalComponent, 139 | componentProps: { value: 123, next : 'foo' } 140 | }); 141 | modal.onDidDismiss().then((d: any) => this.handleModalDismiss(d)); 142 | return await modal.present(); 143 | } 144 | 145 | handleModalDismiss = ({ data }) => { 146 | if (data.cancelled) { 147 | // alert that user cancelled 148 | } else { 149 | //save the data 150 | this.doCreateObject(data); 151 | } 152 | }; 153 | } 154 | -------------------------------------------------------------------------------- /src/app/store/firestore-services.ts: -------------------------------------------------------------------------------- 1 | import * as firebase from "firebase"; 2 | //require('firebase/firestore') 3 | 4 | firebase.initializeApp({ 5 | 6 | }); 7 | 8 | const firestore = firebase.firestore(); 9 | const settings = { 10 | /* your settings... */ 11 | timestampsInSnapshots: true 12 | }; 13 | firestore.settings(settings); 14 | 15 | const db = firebase.firestore(); 16 | const tasks = db.collection("tasks"); 17 | 18 | // Getting Real time feeds 19 | // tasks.onSnapshot(querySnapshot => { 20 | // const myTasks = [] 21 | // querySnapshot.forEach(doc => { 22 | // myTasks.push({ 23 | // id: doc.id, 24 | // ...doc.data() 25 | // }) 26 | // }) 27 | // store.commit('watchTasks', myTasks) 28 | // }) 29 | 30 | export default { 31 | authCheck: () => { 32 | return new Promise(resolve => { 33 | firebase.auth().onAuthStateChanged(_currentUser => { 34 | if (_currentUser) { 35 | console.log( 36 | "User " + 37 | _currentUser.uid + 38 | " is logged in with " + 39 | _currentUser.email 40 | ); 41 | resolve(); 42 | } else { 43 | console.log("User is logged out"); 44 | resolve(); 45 | } 46 | }); 47 | }); 48 | }, 49 | 50 | auth: ({ email, password }) => { 51 | return firebase 52 | .auth() 53 | .signInWithEmailAndPassword(email, password) 54 | .catch(function(error) { 55 | return { error }; 56 | }); 57 | }, 58 | 59 | signOut: () => { 60 | return firebase 61 | .auth() 62 | .signOut() 63 | .catch(function(error) { 64 | return { error }; 65 | }); 66 | }, 67 | 68 | createUser: ({ email, password }) => { 69 | return firebase 70 | .auth() 71 | .createUserWithEmailAndPassword(email, password) 72 | .catch(function(error) { 73 | return { error }; 74 | }); 75 | }, 76 | 77 | checkAuth: async () => { 78 | return new Promise(resolve => { 79 | firebase.auth().onAuthStateChanged(_currentUser => { 80 | if (_currentUser) { 81 | console.log( 82 | "User " + 83 | _currentUser.uid + 84 | " is logged in with " + 85 | _currentUser.email 86 | ); 87 | resolve(firebase.auth().currentUser); 88 | } else { 89 | console.log("User is logged out"); 90 | resolve(firebase.auth().currentUser); 91 | } 92 | }); 93 | }); 94 | }, 95 | 96 | fetchTasks: () => { 97 | return tasks.get(); 98 | }, 99 | 100 | addTask: entry => { 101 | return tasks.add(entry); 102 | }, 103 | 104 | updateTask: entry => { 105 | let inputData = { 106 | ...entry, 107 | updated: new Date() 108 | }; 109 | delete inputData["id"]; 110 | return tasks.doc(entry.id).update(inputData); 111 | }, 112 | 113 | removeTask: id => { 114 | return tasks.doc(id).delete(); 115 | }, 116 | 117 | addObject: (_type, _data) => { 118 | return db.collection(_type).add({ ..._data }); 119 | }, 120 | 121 | fetchObjects: _type => { 122 | return db.collection(_type).get(); 123 | }, 124 | 125 | removeObject: (_type, _id) => { 126 | return db 127 | .collection(_type) 128 | .doc(_id) 129 | .delete(); 130 | } 131 | }; 132 | -------------------------------------------------------------------------------- /src/app/store/main-actions.ts: -------------------------------------------------------------------------------- 1 | export const LOGIN: string = "LOGIN"; 2 | export const LOGIN_SUCCESS: string = "LOGIN_SUCCESS"; 3 | export const LOGIN_FAILED: string = "LOGIN_FAILED"; 4 | export const LOGOUT: string = "LOGOUT"; 5 | export const LOGOUT_SUCCESS: string = "LOGOUT_SUCCESS"; 6 | export const LOGOUT_FAILED: string = "LOGOUT_FAILED"; 7 | 8 | export const CREATE_USER: string = "CREATE_USER"; 9 | export const CREATE_USER_SUCCESS: string = "CREATE_USER_SUCCESS"; 10 | export const CREATE_USER_FAILED: string = "CREATE_USER_FAILED"; 11 | 12 | export const GET_FIREBASE_ARRAY: string = "GET_FIREBASE_ARRAY"; 13 | export const GET_FIREBASE_ARRAY_SUCCESS: string = "GET_FIREBASE_ARRAY_SUCCESS"; 14 | export const GET_FIREBASE_ARRAY_FAILED: string = "GET_FIREBASE_ARRAY_FAILED"; 15 | 16 | export const GET_FIREBASE_OBJECT: string = "GET_FIREBASE_OBJECT"; 17 | export const GET_FIREBASE_OBJECT_SUCCESS: string = 18 | "GET_FIREBASE_OBJECT_SUCCESS"; 19 | export const GET_FIREBASE_OBJECT_FAILED: string = "GET_FIREBASE_OBJECT_FAILED"; 20 | 21 | export const CREATE_FIREBASE_OBJECT: string = "CREATE_FIREBASE_OBJECT"; 22 | export const CREATE_FIREBASE_OBJECT_SUCCESS: string = 23 | "CREATE_FIREBASE_OBJECT_SUCCESS"; 24 | export const CREATE_FIREBASE_OBJECT_FAILED: string = 25 | "CREATE_FIREBASE_OBJECT_FAILED"; 26 | 27 | export const DELETE_FIREBASE_OBJECT: string = "DELETE_FIREBASE_OBJECT"; 28 | export const DELETE_FIREBASE_OBJECT_SUCCESS: string = 29 | "DELETE_FIREBASE_OBJECT_SUCCESS"; 30 | export const DELETE_FIREBASE_OBJECT_FAILED: string = 31 | "DELETE_FIREBASE_OBJECT_FAILED"; 32 | 33 | export const UPDATE_FIREBASE_OBJECT: string = "UPDATE_FIREBASE_OBJECT"; 34 | export const UPDATE_FIREBASE_OBJECT_SUCCESS: string = 35 | "UPDATE_FIREBASE_OBJECT_SUCCESS"; 36 | export const UPDATE_FIREBASE_OBJECT_FAILED: string = 37 | "UPDATE_FIREBASE_OBJECT_FAILED"; 38 | 39 | export const CHECK_AUTH: string = "CHECK_AUTH"; 40 | export const CHECK_AUTH_SUCCESS: string = "CHECK_AUTH_SUCCESS"; 41 | export const CHECK_AUTH_NO_USER: string = "CHECK_AUTH_NO_USER"; 42 | export const CHECK_AUTH_FAILED: string = "CHECK_AUTH_FAILED"; 43 | 44 | export const CLEAR_SUCCESS_ACTION: string = "CLEAR_SUCCESS_ACTION"; 45 | export class All { 46 | clearSuccessAction = () => { 47 | return { type: CLEAR_SUCCESS_ACTION }; 48 | }; 49 | checkAuthAction = () => { 50 | return { type: CHECK_AUTH }; 51 | }; 52 | logoutAction = () => { 53 | return { type: LOGOUT }; 54 | }; 55 | loginAction = credentials => { 56 | return { 57 | type: LOGIN, 58 | payload: credentials 59 | }; 60 | }; 61 | createUserAction = credentials => { 62 | return { 63 | type: CREATE_USER, 64 | payload: credentials 65 | }; 66 | }; 67 | 68 | createFirebaseObject = params => { 69 | return { 70 | type: CREATE_FIREBASE_OBJECT, 71 | payload: params 72 | }; 73 | }; 74 | 75 | deleteFirebaseObject = ({ objectId, objectType }) => { 76 | return { 77 | type: DELETE_FIREBASE_OBJECT, 78 | payload: { objectId, objectType } 79 | }; 80 | }; 81 | 82 | fetchFirebaseArrayAction = (collection: string) => { 83 | return { 84 | type: GET_FIREBASE_ARRAY, 85 | payload: { objectType: collection } 86 | }; 87 | }; 88 | 89 | fetchFirebaseObjectAction = params => { 90 | return { 91 | type: GET_FIREBASE_OBJECT, 92 | payload: params 93 | }; 94 | }; 95 | } 96 | -------------------------------------------------------------------------------- /src/app/store/main-effects.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@angular/core"; 2 | 3 | import * as actions from "./main-actions"; 4 | 5 | import { of, from } from "rxjs"; 6 | import { Observable } from "rxjs"; 7 | // import "rxjs/Rx"; 8 | import { Actions, Effect, ofType } from "@ngrx/effects"; 9 | import { catchError, map, mergeMap, tap, switchMap } from "rxjs/operators"; 10 | import { Action } from "@ngrx/store"; 11 | import API from "./firestore-services"; 12 | 13 | @Injectable() 14 | export class MainEffects { 15 | constructor( 16 | private action$: Actions // public auth$: AngularFireAuth, // public af: AngularFireDatabase 17 | ) { 18 | //console.log(this.auth$.auth.currentUser); 19 | } 20 | // @Effect({ dispatch: false }) 21 | // logActions$ = this.action$.do(action => { 22 | // console.log("logActions$", action); 23 | // }); 24 | 25 | @Effect() 26 | login: Observable = this.action$.ofType(actions.LOGIN).pipe( 27 | map((action: any) => ({ ...action.payload })), 28 | switchMap(({ email, password }) => { 29 | return from(API.auth({ email, password })).pipe( 30 | map((authData: any) => { 31 | if (authData && authData.error) throw authData.error; 32 | return { type: actions.LOGIN_SUCCESS, payload: authData.user }; 33 | }), 34 | catchError(err => 35 | of({ type: actions.LOGIN_FAILED, payload: err.message }) 36 | ) 37 | ); 38 | }) 39 | ); 40 | 41 | @Effect() 42 | logOut: Observable = this.action$.ofType(actions.LOGOUT).pipe( 43 | //map((action: any) => ({ ...action.payload })), 44 | switchMap(() => { 45 | return from(API.signOut()).pipe( 46 | map((authData: any) => { 47 | if (authData && authData.error) throw authData.error; 48 | return { type: actions.LOGOUT_SUCCESS, payload: authData }; 49 | }), 50 | catchError(err => 51 | of({ type: actions.LOGOUT_FAILED, payload: err.message }) 52 | ) 53 | ); 54 | }) 55 | ); 56 | 57 | @Effect() 58 | createUser: Observable = this.action$ 59 | .ofType(actions.CREATE_USER) 60 | .pipe( 61 | map((action: any) => ({ ...action.payload })), 62 | switchMap(userInfo => { 63 | return from(API.createUser(userInfo)).pipe( 64 | map((authData: any) => { 65 | if (authData && authData.error) throw authData.error; 66 | return { type: actions.CREATE_USER_SUCCESS, payload: authData }; 67 | }), 68 | catchError(err => 69 | of({ type: actions.CREATE_USER_FAILED, payload: err.message }) 70 | ) 71 | ); 72 | }) 73 | ); 74 | 75 | @Effect() 76 | createFBObject$: Observable = this.action$ 77 | // Listen for the 'CREATE_FIREBASE_OBJECT' action 78 | .ofType(actions.CREATE_FIREBASE_OBJECT) 79 | .pipe( 80 | map((action: any) => ({ ...action.payload })), 81 | switchMap(({ objectData, objectType }) => { 82 | return from(API.addObject(objectType, objectData)).pipe( 83 | map((_result: any) => { 84 | return { 85 | type: actions.CREATE_FIREBASE_OBJECT_SUCCESS, 86 | payload: { ...objectData, id: _result.id } 87 | }; 88 | }), 89 | catchError(err => 90 | of({ 91 | type: actions.CREATE_FIREBASE_OBJECT_FAILED, 92 | payload: err.message 93 | }) 94 | ) 95 | ); 96 | }) 97 | ); 98 | 99 | @Effect() 100 | deleteFBObject$: Observable = this.action$ 101 | // Listen for the 'DELETE_FIREBASE_OBJECT' action 102 | .ofType(actions.DELETE_FIREBASE_OBJECT) 103 | .pipe( 104 | map((action: any) => ({ ...action.payload })), 105 | switchMap(({ objectId, objectType }) => { 106 | let lastId = objectId; // save to pass to success... 107 | return from(API.removeObject(objectType, objectId)).pipe( 108 | map((_result: any) => { 109 | debugger; 110 | return { 111 | type: actions.DELETE_FIREBASE_OBJECT_SUCCESS, 112 | payload: { objectId: lastId } 113 | }; 114 | }), 115 | catchError(err => 116 | of({ 117 | type: actions.DELETE_FIREBASE_OBJECT_FAILED, 118 | payload: err.message 119 | }) 120 | ) 121 | ); 122 | }) 123 | ); 124 | 125 | @Effect() 126 | getFBArray$: Observable = this.action$ 127 | // Listen for the 'GET_FIREBASE_ARRAY' action 128 | .ofType(actions.GET_FIREBASE_ARRAY) 129 | .pipe( 130 | map((action: any) => ({ ...action.payload })), 131 | switchMap(({ objectType }) => { 132 | return from(API.fetchObjects(objectType)).pipe( 133 | map(_result => { 134 | let r = []; 135 | 136 | _result.docs.forEach(i => { 137 | r.push({ 138 | id: i.id, 139 | ...i.data() 140 | }); 141 | }); 142 | 143 | return { 144 | type: actions.GET_FIREBASE_ARRAY_SUCCESS, 145 | payload: r 146 | }; 147 | }), 148 | catchError(err => 149 | of({ 150 | type: actions.GET_FIREBASE_ARRAY_FAILED, 151 | payload: err.message 152 | }) 153 | ) 154 | ); 155 | }) 156 | ); 157 | 158 | @Effect() 159 | checkAuth: Observable = this.action$.ofType(actions.CHECK_AUTH).pipe( 160 | // @see https://www.learnrxjs.io/operators/transformation/switchmap.html 161 | switchMap(() => { 162 | // convert promise to observable, then get the results 163 | return from(API.checkAuth()).pipe( 164 | map((authData: any) => { 165 | if (authData && authData.error) throw authData.error; 166 | return { type: actions.CHECK_AUTH_SUCCESS, payload: authData }; 167 | }), 168 | catchError(err => 169 | of({ type: actions.CHECK_AUTH_FAILED, payload: err.message }) 170 | ) 171 | ); 172 | }) 173 | ); 174 | 175 | // @Effect() 176 | // logout$ = this.action$ 177 | // .ofType(actions.LOGOUT) 178 | // .do(action => console.log(`Received ${action.type}`)) 179 | // .switchMap(() => this.auth$.auth.signOut()) 180 | // // If successful, dispatch success action with result 181 | // .map((res: any) => ({ type: actions.LOGOUT_SUCCESS, payload: null })) 182 | // // If request fails, dispatch failed action 183 | // .catch((res: any) => 184 | // Observable.of({ type: actions.LOGOUT_FAILED, payload: res }) 185 | // ); 186 | 187 | // @Effect() 188 | // deleteFBObject$ = this.action$ 189 | // // Listen for the 'DELETE_FIREBASE_OBJECT' action 190 | // .ofType(actions.DELETE_FIREBASE_OBJECT) 191 | // .map(toPayload) 192 | // .switchMap(payload => { 193 | // console.log("in deleteFBObject$", payload); 194 | // return this.doDeleteFirebaseObject(payload); 195 | // }) 196 | // .map(({ $key }) => { 197 | // return { 198 | // type: actions.DELETE_FIREBASE_OBJECT_SUCCESS, 199 | // payload: { $key } 200 | // }; 201 | // }) 202 | // .catch(error => { 203 | // console.log("error", error); 204 | // return of({ 205 | // type: actions.DELETE_FIREBASE_OBJECT_FAILED, 206 | // payload: error 207 | // }); 208 | // }); 209 | 210 | // @Effect() 211 | // getFBArray$ = this.action$ 212 | // .ofType(actions.GET_FIREBASE_ARRAY, actions.CREATE_FIREBASE_OBJECT_SUCCESS) 213 | 214 | // .do(action => console.log(`Received ${action.type}`)) 215 | // .switchMap(payload => { 216 | // return this.doFirebaseLoadArray(payload) 217 | // .map(items => { 218 | // console.log(items); 219 | // return { 220 | // type: actions.GET_FIREBASE_ARRAY_SUCCESS, 221 | // payload: items.map(i => { 222 | // return { 223 | // $key: i.key, 224 | // ...i.payload.val() 225 | // }; 226 | // }) 227 | // }; 228 | // }) 229 | // .catch(error => { 230 | // return of({ 231 | // type: actions.GET_FIREBASE_ARRAY_FAILED, 232 | // payload: error 233 | // }); 234 | // }); 235 | // }); 236 | 237 | // @Effect() 238 | // getFBObject$ = this.action$ 239 | // // Listen for the 'GET_FIREBASE_OBJECT' action 240 | // .ofType(actions.GET_FIREBASE_OBJECT) 241 | // .map(toPayload) 242 | // .switchMap(payload => { 243 | // return this.doFirebaseLoadObject(payload) 244 | // .map(item => { 245 | // console.log(item); 246 | // return { type: actions.GET_FIREBASE_OBJECT_SUCCESS, payload: item }; 247 | // }) 248 | // .catch(error => { 249 | // return of({ 250 | // type: actions.GET_FIREBASE_OBJECT_FAILED, 251 | // payload: error 252 | // }); 253 | // }); 254 | // }); 255 | 256 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 257 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 258 | // 259 | // MOVE ALL OF THIS TO A SEPERATE SERVICE 260 | // 261 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 262 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 263 | // doAuth(_creds) { 264 | // console.log("in do auth", _creds); 265 | // // return this.auth$.auth.signInWithEmailAndPassword( 266 | // // _creds.email, 267 | // // _creds.password 268 | // // ); 269 | // return new Promise(resolve => { 270 | // resolve(true); 271 | // }); 272 | // } 273 | 274 | // doCreateUser(_creds) { 275 | // return this.auth$.auth.createUserWithEmailAndPassword( 276 | // _creds.email, 277 | // _creds.password 278 | // ); 279 | // } 280 | 281 | // /** 282 | // * 283 | // * 284 | // * @param {any} { objectType, objectData } 285 | // * @returns 286 | // * @memberof MainEffects 287 | // */ 288 | // doCreateFirebaseObject({ objectType, objectData }) { 289 | // // key an id for the object 290 | // let key = this.af.database 291 | // .ref() 292 | // .child(objectType) 293 | // .push().key; 294 | 295 | // // create the object as an update with the path 296 | // // and the key info 297 | // var updates = {}; 298 | // updates[`${objectType}/${key}`] = objectData; 299 | 300 | // // update the database 301 | // return this.af.database 302 | // .ref() 303 | // .update(updates) 304 | // .then(() => { 305 | // return { 306 | // objectType, 307 | // objectData, 308 | // key 309 | // }; 310 | // }); 311 | // } 312 | 313 | // doDeleteFirebaseObject({ objectType, $key }) { 314 | // // key an id for the object 315 | // return this.af 316 | // .list(objectType) 317 | // .remove($key) 318 | // .then(() => { 319 | // return { $key }; 320 | // }); 321 | // } 322 | 323 | // doFirebaseLoadArray(_params) { 324 | // var path = _params.payload.path; 325 | // return this.af 326 | // .list(path) 327 | // .snapshotChanges() 328 | // .take(1); 329 | // } 330 | 331 | // doFirebaseLoadObject(_params) { 332 | // return this.af 333 | // .object(_params.path) 334 | // .valueChanges() 335 | // .take(1); 336 | // } 337 | } 338 | -------------------------------------------------------------------------------- /src/app/store/main-reducer.ts: -------------------------------------------------------------------------------- 1 | import * as actions from "./main-actions"; 2 | import { createSelector } from "@ngrx/store"; 3 | 4 | export const intitialState = { 5 | authChecked: true, 6 | currentUser: null, 7 | loading: false, 8 | dataArray: [] 9 | }; 10 | 11 | export interface AppState { 12 | authChecked: boolean; 13 | currentUser: any; 14 | loading: boolean; 15 | error?: any; 16 | dataArray?: Array; 17 | dataObject?: Object; 18 | lastAction?: String; 19 | } 20 | 21 | export function mainAppStoreReducer( 22 | state: AppState = intitialState, 23 | action: any 24 | ) { 25 | switch (action.type) { 26 | case actions.CLEAR_SUCCESS_ACTION: { 27 | return { ...state, lastAction: null }; 28 | } 29 | 30 | case actions.LOGIN: { 31 | return Object.assign({}, state, { 32 | currentCreds: action.payload, 33 | loading: true 34 | }); 35 | } 36 | 37 | case actions.LOGIN_SUCCESS: { 38 | return Object.assign({}, state, { 39 | currentUser: action.payload, 40 | currentCreds: null, 41 | error: null, 42 | loading: false 43 | }); 44 | } 45 | 46 | case actions.LOGIN_FAILED: { 47 | return Object.assign({}, state, { 48 | error: action.payload, 49 | currentUser: null, 50 | authChecked: true, 51 | loading: false 52 | }); 53 | } 54 | 55 | case actions.LOGOUT: { 56 | return Object.assign({}, state, { loading: true, authChecked: false }); 57 | } 58 | 59 | case actions.LOGOUT_SUCCESS: { 60 | return Object.assign({}, intitialState, { authChecked: true }); 61 | } 62 | 63 | case actions.LOGOUT_FAILED: { 64 | return Object.assign({}, state, { 65 | error: action.payload, 66 | loading: false 67 | }); 68 | } 69 | case actions.CHECK_AUTH: { 70 | return Object.assign({}, state, { loading: true }); 71 | } 72 | 73 | case actions.CHECK_AUTH_SUCCESS: { 74 | return Object.assign({}, state, { 75 | currentUser: action.payload, 76 | authChecked: true, 77 | loading: false 78 | }); 79 | } 80 | case actions.CHECK_AUTH_FAILED: { 81 | return Object.assign({}, state, { 82 | error: action.payload, 83 | currentUser: null, 84 | authChecked: true, 85 | loading: false 86 | }); 87 | } 88 | case actions.CHECK_AUTH_NO_USER: { 89 | return Object.assign({}, state, { 90 | currentUser: null, 91 | authChecked: true, 92 | loading: false 93 | }); 94 | } 95 | 96 | // 97 | case actions.CREATE_USER: { 98 | return Object.assign({}, state, { 99 | currentCreds: action.payload, 100 | loading: true 101 | }); 102 | } 103 | 104 | case actions.CREATE_USER_SUCCESS: { 105 | return Object.assign({}, state, { 106 | currentUser: action.payload, 107 | authChecked: true, 108 | loading: false, 109 | lastAction: action.type 110 | }); 111 | } 112 | case actions.CREATE_USER_FAILED: { 113 | return Object.assign({}, state, { 114 | error: action.payload, 115 | currentUser: null, 116 | authChecked: true, 117 | loading: false 118 | }); 119 | } 120 | 121 | case actions.GET_FIREBASE_ARRAY: { 122 | return Object.assign({}, state, { 123 | loading: true 124 | }); 125 | } 126 | case actions.GET_FIREBASE_ARRAY_SUCCESS: { 127 | return Object.assign({}, state, { 128 | dataArray: action.payload, 129 | loading: false, 130 | lastAction: action.type 131 | }); 132 | } 133 | case actions.GET_FIREBASE_ARRAY_FAILED: { 134 | return Object.assign({}, state, { 135 | error: action.payload, 136 | loading: false 137 | }); 138 | } 139 | case actions.GET_FIREBASE_OBJECT: { 140 | return Object.assign({}, state, { 141 | queryParams: action.payload, 142 | loading: true 143 | }); 144 | } 145 | case actions.GET_FIREBASE_OBJECT_SUCCESS: { 146 | return Object.assign({}, state, { 147 | dataObject: action.payload, 148 | loading: false, 149 | lastAction: action.type 150 | }); 151 | } 152 | case actions.GET_FIREBASE_OBJECT_FAILED: { 153 | return Object.assign({}, state, { 154 | error: action.payload, 155 | loading: false 156 | }); 157 | } 158 | 159 | // CREATE AN OBJECT IN THE DATASTORE 160 | case actions.CREATE_FIREBASE_OBJECT: { 161 | return Object.assign({}, state, { 162 | dataObject: action.payload, 163 | loading: true 164 | }); 165 | } 166 | case actions.CREATE_FIREBASE_OBJECT_SUCCESS: { 167 | state.dataArray = [...state.dataArray, action.payload]; 168 | return Object.assign({}, state, { 169 | dataObject: action.payload, 170 | loading: false, 171 | lastAction: action.type 172 | }); 173 | } 174 | case actions.CREATE_FIREBASE_OBJECT_FAILED: { 175 | return Object.assign({}, state, { 176 | error: action.payload, 177 | loading: false 178 | }); 179 | } 180 | 181 | // DELETE AN OBJECT IN THE DATASTORE 182 | case actions.DELETE_FIREBASE_OBJECT: { 183 | return Object.assign({}, state, { loading: true }); 184 | } 185 | case actions.DELETE_FIREBASE_OBJECT_SUCCESS: { 186 | let dataArray = state.dataArray.filter(i => { 187 | return i.id !== action.payload.objectId; 188 | }); 189 | return Object.assign({}, state, { 190 | dataArray, 191 | dataObject: null, 192 | loading: false, 193 | lastAction: action.type 194 | }); 195 | } 196 | case actions.DELETE_FIREBASE_OBJECT_FAILED: { 197 | return Object.assign({}, state, { 198 | error: action.payload, 199 | loading: false 200 | }); 201 | } 202 | 203 | default: { 204 | return state; 205 | } 206 | } 207 | } 208 | 209 | export const selectState = state => state.app; 210 | 211 | // get current user 212 | export const selectUser = createSelector( 213 | selectState, 214 | (state: AppState) => state.currentUser 215 | ); 216 | 217 | // get data 218 | export const selectData = createSelector( 219 | selectState, 220 | (state: AppState) => state.dataArray 221 | ); 222 | 223 | // get success from data CRUD action 224 | export const selectDataAction = createSelector( 225 | selectState, 226 | (state: AppState) => { 227 | return { 228 | action: state.lastAction, 229 | dataArray: state.dataArray, 230 | data: state.dataObject 231 | }; 232 | } 233 | ); 234 | -------------------------------------------------------------------------------- /src/assets/icon/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronksaunders/ionic4-ngrx-firebase/79381b3392d3077245a85db26d0372dddcaef1f0/src/assets/icon/favicon.png -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * In development mode, to ignore zone related error stack frames such as 11 | * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can 12 | * import the following file, but please comment it out in production mode 13 | * because it will have performance impact when throw error 14 | */ 15 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 16 | -------------------------------------------------------------------------------- /src/global.scss: -------------------------------------------------------------------------------- 1 | // http://ionicframework.com/docs/theming/ 2 | @import "~@ionic/angular/css/normalize.css"; 3 | @import "~@ionic/angular/css/structure.css"; 4 | @import "~@ionic/angular/css/typography.css"; 5 | @import "~@ionic/angular/css/colors.css"; 6 | 7 | @import "~@ionic/angular/css/padding.css"; 8 | @import "~@ionic/angular/css/float-elements.css"; 9 | @import "~@ionic/angular/css/text-alignment.css"; 10 | @import "~@ionic/angular/css/text-transformation.css"; 11 | @import "~@ionic/angular/css/flex-utils.css"; 12 | 13 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Ionic App 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, 'coverage'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.log(err)); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** IE10 and IE11 requires the following for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Required to support Web Animations `@angular/platform-browser/animations`. 51 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation 52 | **/ 53 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 54 | 55 | 56 | 57 | /*************************************************************************************************** 58 | * Zone JS is required by Angular itself. 59 | */ 60 | import 'zone.js/dist/zone'; // Included with Angular CLI. 61 | 62 | 63 | 64 | /*************************************************************************************************** 65 | * APPLICATION IMPORTS 66 | */ 67 | 68 | /** 69 | * Date, currency, decimal and percent pipes. 70 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 71 | */ 72 | // import 'intl'; // Run `npm install --save intl`. 73 | /** 74 | * Need to import at least one locale-data with intl. 75 | */ 76 | // import 'intl/locale-data/jsonp/en'; 77 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /src/theme/variables.scss: -------------------------------------------------------------------------------- 1 | // Ionic Variables and Theming. For more info, please see: 2 | // http://ionicframework.com/docs/theming/ 3 | 4 | /** Ionic CSS Variables **/ 5 | :root { 6 | /** primary **/ 7 | --ion-color-primary: #488aff; 8 | --ion-color-primary-rgb: 72,138,255; 9 | --ion-color-primary-contrast: #fff; 10 | --ion-color-primary-contrast-rgb: 255,255,255; 11 | --ion-color-primary-shade: #3f79e0; 12 | --ion-color-primary-tint: #5a96ff; 13 | 14 | /** secondary **/ 15 | --ion-color-secondary: #32db64; 16 | --ion-color-secondary-rgb: 50,219,100; 17 | --ion-color-secondary-contrast: #fff; 18 | --ion-color-secondary-contrast-rgb: 255,255,255; 19 | --ion-color-secondary-shade: #2cc158; 20 | --ion-color-secondary-tint: #47df74; 21 | 22 | /** tertiary **/ 23 | --ion-color-tertiary: #f4a942; 24 | --ion-color-tertiary-rgb: 244,169,66; 25 | --ion-color-tertiary-contrast: #fff; 26 | --ion-color-tertiary-contrast-rgb: 255,255,255; 27 | --ion-color-tertiary-shade: #d7953a; 28 | --ion-color-tertiary-tint: #f5b255; 29 | 30 | /** success **/ 31 | --ion-color-success: #10dc60; 32 | --ion-color-success-rgb: 16,220,96; 33 | --ion-color-success-contrast: #fff; 34 | --ion-color-success-contrast-rgb: 255,255,255; 35 | --ion-color-success-shade: #0ec254; 36 | --ion-color-success-tint: #28e070; 37 | 38 | /** warning **/ 39 | --ion-color-warning: #ffce00; 40 | --ion-color-warning-rgb: 255,206,0; 41 | --ion-color-warning-contrast: #000; 42 | --ion-color-warning-contrast-rgb: 0,0,0; 43 | --ion-color-warning-shade: #e0b500; 44 | --ion-color-warning-tint: #ffd31a; 45 | 46 | /** danger **/ 47 | --ion-color-danger: #f53d3d; 48 | --ion-color-danger-rgb: 245,61,61; 49 | --ion-color-danger-contrast: #fff; 50 | --ion-color-danger-contrast-rgb: 255,255,255; 51 | --ion-color-danger-shade: #d83636; 52 | --ion-color-danger-tint: #f65050; 53 | 54 | /** light **/ 55 | --ion-color-light: #f4f4f4; 56 | --ion-color-light-rgb: 244,244,244; 57 | --ion-color-light-contrast: #000; 58 | --ion-color-light-contrast-rgb: 0,0,0; 59 | --ion-color-light-shade: #d7d7d7; 60 | --ion-color-light-tint: #f5f5f5; 61 | 62 | /** medium **/ 63 | --ion-color-medium: #989aa2; 64 | --ion-color-medium-rgb: 152,154,162; 65 | --ion-color-medium-contrast: #000; 66 | --ion-color-medium-contrast-rgb: 0,0,0; 67 | --ion-color-medium-shade: #86888f; 68 | --ion-color-medium-tint: #a2a4ab; 69 | 70 | /** dark **/ 71 | --ion-color-dark: #222; 72 | --ion-color-dark-rgb: 34,34,34; 73 | --ion-color-dark-contrast: #fff; 74 | --ion-color-dark-contrast-rgb: 255,255,255; 75 | --ion-color-dark-shade: #1e1e1e; 76 | --ion-color-dark-tint: #383838; 77 | } -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "baseUrl": "./", 6 | "module": "es2015" 7 | }, 8 | "exclude": [ 9 | "test.ts", 10 | "**/*.spec.ts" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "types": [ 8 | "jasmine", 9 | "node" 10 | ] 11 | }, 12 | "files": [ 13 | "test.ts" 14 | ], 15 | "include": [ 16 | "polyfills.ts", 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "target": "es5", 11 | "lib": [ 12 | "es2017", 13 | "dom" 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-spacing": true, 20 | "indent": [ 21 | true, 22 | "spaces" 23 | ], 24 | "interface-over-type-literal": true, 25 | "label-position": true, 26 | "max-line-length": [ 27 | true, 28 | 140 29 | ], 30 | "member-access": false, 31 | "member-ordering": [ 32 | true, 33 | { 34 | "order": [ 35 | "static-field", 36 | "instance-field", 37 | "static-method", 38 | "instance-method" 39 | ] 40 | } 41 | ], 42 | "no-arg": true, 43 | "no-bitwise": true, 44 | "no-console": [ 45 | true, 46 | "debug", 47 | "info", 48 | "time", 49 | "timeEnd", 50 | "trace" 51 | ], 52 | "no-construct": true, 53 | "no-debugger": true, 54 | "no-duplicate-super": true, 55 | "no-empty": false, 56 | "no-empty-interface": true, 57 | "no-eval": true, 58 | "no-inferrable-types": [ 59 | true, 60 | "ignore-params" 61 | ], 62 | "no-misused-new": true, 63 | "no-non-null-assertion": true, 64 | "no-shadowed-variable": true, 65 | "no-string-literal": false, 66 | "no-string-throw": true, 67 | "no-switch-case-fall-through": true, 68 | "no-trailing-whitespace": true, 69 | "no-unnecessary-initializer": true, 70 | "no-unused-expression": true, 71 | "no-use-before-declare": true, 72 | "no-var-keyword": true, 73 | "object-literal-sort-keys": false, 74 | "one-line": [ 75 | true, 76 | "check-open-brace", 77 | "check-catch", 78 | "check-else", 79 | "check-whitespace" 80 | ], 81 | "prefer-const": true, 82 | "quotemark": [ 83 | true, 84 | "single" 85 | ], 86 | "radix": true, 87 | "semicolon": [ 88 | true, 89 | "always" 90 | ], 91 | "triple-equals": [ 92 | true, 93 | "allow-null-check" 94 | ], 95 | "typedef-whitespace": [ 96 | true, 97 | { 98 | "call-signature": "nospace", 99 | "index-signature": "nospace", 100 | "parameter": "nospace", 101 | "property-declaration": "nospace", 102 | "variable-declaration": "nospace" 103 | } 104 | ], 105 | "unified-signatures": true, 106 | "variable-name": false, 107 | "whitespace": [ 108 | true, 109 | "check-branch", 110 | "check-decl", 111 | "check-operator", 112 | "check-separator", 113 | "check-type" 114 | ], 115 | "directive-selector": [ 116 | true, 117 | "attribute", 118 | "app", 119 | "camelCase" 120 | ], 121 | "component-selector": [ 122 | true, 123 | "element", 124 | "app", 125 | "page", 126 | "kebab-case" 127 | ], 128 | "no-output-on-prefix": true, 129 | "use-input-property-decorator": true, 130 | "use-output-property-decorator": true, 131 | "use-host-property-decorator": true, 132 | "no-input-rename": true, 133 | "no-output-rename": true, 134 | "use-life-cycle-interface": true, 135 | "use-pipe-transform-interface": true, 136 | "directive-class-suffix": true 137 | } 138 | } 139 | --------------------------------------------------------------------------------