Update SW cache

This commit is contained in:
Zakary Timson 2018-08-08 14:43:43 -04:00
parent 6565178ecd
commit 538c585cc1
2 changed files with 59 additions and 53 deletions

View File

@ -1,31 +1,37 @@
import {Component, OnInit} from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {Router, NavigationEnd} from '@angular/router'; import { Router, NavigationEnd } from '@angular/router';
import {ElectronService} from 'ngx-electron'; import { ElectronService } from 'ngx-electron';
import {filter} from 'rxjs/operators'; import { filter } from 'rxjs/operators';
import {MatDialog} from '@angular/material'; import { MatDialog } from '@angular/material';
import {LoginComponent} from './login/login.component'; import { LoginComponent } from './login/login.component';
import {LocalStorage} from 'webstorage-decorators'; import { LocalStorage } from 'webstorage-decorators';
import {AppStore} from './app.store'; import { AppStore } from './app.store';
import {AngularFireAuth} from '../../node_modules/angularfire2/auth'; import { AngularFireAuth } from '../../node_modules/angularfire2/auth';
import { SwUpdate } from '../../node_modules/@angular/service-worker';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
templateUrl: 'app.component.html' templateUrl: 'app.component.html'
}) })
export class AppComponent implements OnInit { export class AppComponent implements OnInit {
@LocalStorage({defaultValue: [], encryptionKey: 'HmRoBFUEVWqW5uvy'}) @LocalStorage({ defaultValue: [], encryptionKey: 'HmRoBFUEVWqW5uvy' })
cart: {id: string; item: string; price: number; currency: 'CAD' | 'USD'; quantity: number}[]; cart: { id: string; item: string; price: number; currency: 'CAD' | 'USD'; quantity: number }[];
constructor( constructor(
private router: Router, private router: Router,
private dialog: MatDialog, private dialog: MatDialog,
private updates: SwUpdate,
public electron: ElectronService, public electron: ElectronService,
public store: AppStore, public store: AppStore,
public afAuth: AngularFireAuth public afAuth: AngularFireAuth
) {} ) {
updates.available.subscribe(event => {
if (event.current != event.available) updates.activateUpdate().then(() => document.location.reload());
});
}
cartAdd(id: string, item: string, price: number, currency: 'CAD' | 'USD', quantity: number) { cartAdd(id: string, item: string, price: number, currency: 'CAD' | 'USD', quantity: number) {
this.cart = [{id: id, item: item, price: Number(price), currency: currency, quantity: Number(quantity)}].concat( this.cart = [{ id: id, item: item, price: Number(price), currency: currency, quantity: Number(quantity) }].concat(
this.cart this.cart
); );
} }

View File

@ -1,35 +1,35 @@
import {BrowserModule} from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {RouterModule} from '@angular/router'; import { RouterModule } from '@angular/router';
import {AngularFireModule} from 'angularfire2'; import { AngularFireModule } from 'angularfire2';
import {AngularFirestoreModule, AngularFirestore} from 'angularfire2/firestore'; import { AngularFirestoreModule, AngularFirestore } from 'angularfire2/firestore';
import {NgModule} from '@angular/core'; import { NgModule } from '@angular/core';
import {FormsModule, ReactiveFormsModule} from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import {AppComponent} from './app.component'; import { AppComponent } from './app.component';
import {environment} from '../environments/environment'; import { environment } from '../environments/environment';
import {ConvertFromGPipe, ConvertToGPipe} from './formulaManager/units.pipe'; import { ConvertFromGPipe, ConvertToGPipe } from './formulaManager/units.pipe';
import {ScalePipe} from './formulaManager/scale.pipe'; import { ScalePipe } from './formulaManager/scale.pipe';
import {AngularMaterialModule} from './material.module'; import { AngularMaterialModule } from './material.module';
import {HomeComponent} from './home/home.component'; import { HomeComponent } from './home/home.component';
import {ServiceWorkerModule} from '@angular/service-worker'; import { ServiceWorkerModule } from '@angular/service-worker';
import {FormulaManagerComponent} from './formulaManager/formulaManager.component'; import { FormulaManagerComponent } from './formulaManager/formulaManager.component';
import {NgxElectronModule} from 'ngx-electron'; import { NgxElectronModule } from 'ngx-electron';
import {AboutComponent} from './about/about.component'; import { AboutComponent } from './about/about.component';
import {CategoriesComponent} from './store/categories.component'; import { CategoriesComponent } from './store/categories.component';
import {AngularFireStorageModule} from 'angularfire2/storage'; import { AngularFireStorageModule } from 'angularfire2/storage';
import {LoginComponent} from './login/login.component'; import { LoginComponent } from './login/login.component';
import {AngularFireAuthModule} from 'angularfire2/auth'; import { AngularFireAuthModule } from 'angularfire2/auth';
import {NewCategoryComponent} from './store/newCategory/newCategory.component'; import { NewCategoryComponent } from './store/newCategory/newCategory.component';
import {NewProductComponent} from './store/newProduct/newProduct.component'; import { NewProductComponent } from './store/newProduct/newProduct.component';
import {DeleteComponent} from './delete/delete.component'; import { DeleteComponent } from './delete/delete.component';
import {ProductsComponent} from './store/products/products.component'; import { ProductsComponent } from './store/products/products.component';
import {CartComponent} from './store/cart/cart.component'; import { CartComponent } from './store/cart/cart.component';
import {ViewComponents} from './formulaManager/viewComponents/viewComponents.component'; import { ViewComponents } from './formulaManager/viewComponents/viewComponents.component';
import {NewComponentComponent} from './formulaManager/newComponent/newComponent.component'; import { NewComponentComponent } from './formulaManager/newComponent/newComponent.component';
import {HttpModule} from '@angular/http'; import { HttpModule } from '@angular/http';
import {NewFormulaComponent} from './formulaManager/newFormula/newFormula.component'; import { NewFormulaComponent } from './formulaManager/newFormula/newFormula.component';
import {AppStore} from './app.store'; import { AppStore } from './app.store';
import {SlideshowModule} from 'ng-simple-slideshow'; import { SlideshowModule } from 'ng-simple-slideshow';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -64,15 +64,15 @@ import {SlideshowModule} from 'ng-simple-slideshow';
NgxElectronModule, NgxElectronModule,
ReactiveFormsModule, ReactiveFormsModule,
RouterModule.forRoot([ RouterModule.forRoot([
{path: 'about', component: AboutComponent}, { path: 'about', component: AboutComponent },
{path: 'cart', component: CartComponent}, { path: 'cart', component: CartComponent },
{path: 'formulaManager', component: FormulaManagerComponent}, { path: 'formulaManager', component: FormulaManagerComponent },
{path: 'products/:product', component: ProductsComponent}, { path: 'products/:product', component: ProductsComponent },
{path: 'store/:category', component: CategoriesComponent}, { path: 'store/:category', component: CategoriesComponent },
{path: 'store', component: CategoriesComponent}, { path: 'store', component: CategoriesComponent },
{path: '**', component: HomeComponent} { path: '**', component: HomeComponent }
]), ]),
ServiceWorkerModule.register('/ngsw-worker.js', {enabled: false}), ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }),
SlideshowModule SlideshowModule
], ],
providers: [AppStore], providers: [AppStore],