@@ -20,6 +20,8 @@ import { SystemsService } from '../core/provider/systems.service';
2020import { HttpClient } from '@angular/common/http' ;
2121import { InitModal } from '../core/modal/init/init.modal' ;
2222import { MatDialog } from '@angular/material/dialog' ;
23+ import { AuthService } from '../core/provider/auth.service' ;
24+ import { getDatabase , ref as fbref , get as fbget , child } from '@angular/fire/database'
2325
2426
2527//disables some angular checking mechanisms
@@ -70,6 +72,7 @@ export class MixerComponent implements OnInit {
7072 * dialog - Anglar Material dialog module. Used to control the popup modals.
7173 */
7274 constructor ( public dm : DesignmodesService ,
75+ private auth : AuthService ,
7376 private ms : MaterialsService ,
7477 private sys : SystemsService ,
7578 private ps : PatternService ,
@@ -158,7 +161,6 @@ export class MixerComponent implements OnInit {
158161 */
159162 importNewFile ( result : LoadResponse ) {
160163
161- console . log ( "imported new file" , result , result . data ) ;
162164 this . processFileData ( result . data ) . then (
163165 this . palette . changeDesignmode ( 'move' )
164166 ) ;
@@ -291,7 +293,6 @@ export class MixerComponent implements OnInit {
291293 }
292294 } ) ;
293295
294- console . log ( "seed nodes mapped " , seeds ) ;
295296
296297
297298
@@ -309,7 +310,7 @@ export class MixerComponent implements OnInit {
309310 return this . tree . validateNodes ( ) ;
310311 } )
311312 . then ( el => {
312- console . log ( "performing top level ops" ) ;
313+ // console.log("performing top level ops");
313314
314315 return this . tree . performTopLevelOps ( ) ;
315316 } )
@@ -321,7 +322,7 @@ export class MixerComponent implements OnInit {
321322 if ( this . tree . hasParent ( el . id ) ) {
322323 el . draft = new Draft ( { warps : 1 , wefts : 1 , pattern : [ [ new Cell ( false ) ] ] } ) ;
323324 } else {
324- console . log ( "removing node " , el . id , el . type , this . tree . hasParent ( el . id ) ) ;
325+ // console.log("removing node ", el.id, el.type, this.tree.hasParent(el.id));
325326 this . tree . removeNode ( el . id ) ;
326327 }
327328 } )
@@ -388,14 +389,72 @@ export class MixerComponent implements OnInit {
388389
389390 ngAfterViewInit ( ) {
390391
391- const dialogRef = this . dialog . open ( InitModal , {
392- data : { source : 'mixer' }
393- } ) ;
394392
395- dialogRef . afterClosed ( ) . subscribe ( loadResponse => {
396- if ( loadResponse !== undefined ) this . loadNewFile ( loadResponse ) ;
393+ this . auth . user . subscribe ( user => {
394+
395+ if ( user === null ) {
396+
397+ const dialogRef = this . dialog . open ( InitModal , {
398+ data : { source : 'mixer' }
399+ } ) ;
400+
401+
402+ dialogRef . afterClosed ( ) . subscribe ( loadResponse => {
403+ if ( loadResponse !== undefined ) this . loadNewFile ( loadResponse ) ;
404+
405+ } ) ;
406+ } else {
407+
408+ //in the case someone logs in mid way through, don't replace their work.
409+ if ( this . tree . nodes . length > 0 ) return ;
410+
411+
412+ const db = fbref ( getDatabase ( ) ) ;
413+
414+
415+ fbget ( child ( db , `users/${ this . auth . uid } /ada` ) ) . then ( ( snapshot ) => {
416+ if ( snapshot . exists ( ) ) {
417+ this . fs . loader . ada ( "recovered draft" , snapshot . val ( ) ) . then ( lr => {
418+ this . loadNewFile ( lr ) ;
419+ } ) ;
420+ }
421+ } ) . catch ( ( error ) => {
422+ console . error ( error ) ;
423+ } ) ;
424+
425+ }
426+ } ) ;
427+
428+ console . log ( this . auth , this . auth . isLoggedIn ) ;
429+
430+
431+
432+
433+
434+
435+ }
436+
437+
438+ loadSavedFile ( ) {
439+ // this.auth.user.subscribe(user => {
440+ // if(user !== null){
441+
442+ // const db = fbref(getDatabase());
397443
398- } ) ;
444+
445+ // fbget(child(db, `users/${this.auth.uid}/ada`)).then((snapshot) => {
446+ // if (snapshot.exists()) {
447+ // this.fls.loader.ada("recovered draft", snapshot.val()).then(lr => {
448+ // this.dialogRef.close(lr)
449+ // });
450+ // }
451+ // }).catch((error) => {
452+ // console.error(error);
453+ // });
454+
455+ // }
456+
457+ // });
399458
400459 }
401460
0 commit comments