added firebase
This commit is contained in:
		@@ -13,6 +13,8 @@ import {MaterialModule} from "./material.module";
 | 
			
		||||
import {CalibrateComponent} from "./map/calibrate/calibrate.component";
 | 
			
		||||
import {MatInputModule} from "@angular/material";
 | 
			
		||||
import {PermissionsComponent} from "./permissions/permissions.component";
 | 
			
		||||
import {AngularFireModule} from "@angular/fire";
 | 
			
		||||
import {AngularFirestoreModule} from "@angular/fire/firestore";
 | 
			
		||||
 | 
			
		||||
@NgModule({
 | 
			
		||||
    declarations: [
 | 
			
		||||
@@ -24,6 +26,8 @@ import {PermissionsComponent} from "./permissions/permissions.component";
 | 
			
		||||
    ],
 | 
			
		||||
    imports: [
 | 
			
		||||
        AgmCoreModule.forRoot({apiKey: 'AIzaSyDFtvCY6nH_HUoTBNf_5b-E8nRweSLYtxE'}),
 | 
			
		||||
        AngularFireModule.initializeApp(environment.firebaseConfig),
 | 
			
		||||
        AngularFirestoreModule.enablePersistence(),
 | 
			
		||||
        AppRouting,
 | 
			
		||||
        BrowserAnimationsModule,
 | 
			
		||||
        BrowserModule,
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ import {Component} from "@angular/core";
 | 
			
		||||
import {Observable, timer} from "rxjs";
 | 
			
		||||
import {map, take} from "rxjs/operators";
 | 
			
		||||
import {Router} from "@angular/router";
 | 
			
		||||
import {SyncService} from "../map/sync.service";
 | 
			
		||||
 | 
			
		||||
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
 | 
			
		||||
 | 
			
		||||
@@ -13,7 +14,7 @@ export class HomeComponent {
 | 
			
		||||
    phrase = 'If you\'re into that';
 | 
			
		||||
    typedText: Observable<string>;
 | 
			
		||||
 | 
			
		||||
    constructor(private router: Router) {
 | 
			
		||||
    constructor(private syncService: SyncService, private router: Router) {
 | 
			
		||||
        this.typedText = timer(750, 50).pipe(take(this.phrase.length), map((i: number) => this.phrase.substring(0, i + 1)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -21,7 +22,7 @@ export class HomeComponent {
 | 
			
		||||
        let mapCode: string;
 | 
			
		||||
        do {
 | 
			
		||||
            mapCode = Array(16).fill(0).map(() => chars[Math.round(Math.random() * chars.length)]).join('');
 | 
			
		||||
        } while (false);
 | 
			
		||||
        this.router.navigate(['/', mapCode]);
 | 
			
		||||
        } while (await this.syncService.exists(mapCode));
 | 
			
		||||
        return this.router.navigate(['/', mapCode]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										24
									
								
								src/app/map/sync.service.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/app/map/sync.service.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
import {Injectable} from "@angular/core";
 | 
			
		||||
import {AngularFirestore, AngularFirestoreCollection, DocumentSnapshot} from "@angular/fire/firestore";
 | 
			
		||||
import {map} from "rxjs/operators";
 | 
			
		||||
 | 
			
		||||
@Injectable({
 | 
			
		||||
    providedIn: 'root'
 | 
			
		||||
})
 | 
			
		||||
export class SyncService {
 | 
			
		||||
    private collection: AngularFirestoreCollection;
 | 
			
		||||
 | 
			
		||||
    constructor(private db: AngularFirestore) {
 | 
			
		||||
        this.collection = this.db.collection('Maps');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async exists(mapCode: string) {
 | 
			
		||||
        return (await this.collection.doc(mapCode).ref.get()).exists;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    load(mapCode: string) {
 | 
			
		||||
        return this.collection.doc(mapCode).snapshotChanges().pipe(map((snap: any) => {
 | 
			
		||||
            return Object.assign({}, snap.data, {delete: snap.ref.delete, set: snap.ref.set, update: snap.ref.update});
 | 
			
		||||
        }))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user