@@ -14,14 +14,18 @@ if (process.platform === "darwin")
1414 win . menu = mb ;
1515}
1616
17- //Parse Variables.
18- Parse . initialize ( "VvmNgHcupWn43L9ThaNDiIldMSjOXiLvd7DR7wTq" , "DTAv28KMYt5pYlY3Q1yDJ3Tvm2FOViL4io9deBBt" ) ;
19- var Parse_Notes = Parse . Object . extend ( "Notes" ) ;
20- var Private_Parse_Notes = new Parse_Notes ( ) ;
17+ // Firebase setup.
18+ var config = {
19+ apiKey : "AIzaSyDtYLpfW_yRF273-N6iwZDHDX7xG8Nt5_g" ,
20+ authDomain : "marknote-681e3.firebaseapp.com" ,
21+ databaseURL : "https://marknote-681e3.firebaseio.com" ,
22+ storageBucket : "marknote-681e3.appspot.com" ,
23+ messagingSenderId : "809473583891"
24+ } ;
25+ firebase . initializeApp ( config ) ;
26+
2127var syncing ;
2228var wrap = true ;
23- var parsenoteid ;
24-
2529var marked = require ( "marked" ) ;
2630var highlight = require ( "highlight.js" ) ;
2731var editor ;
@@ -458,113 +462,60 @@ function render(markdown)
458462}
459463
460464/**
461- * Tries to login to Parse.com
465+ * Tries to login to Firebase
462466 * @param {string } username Parse.com username.
463467 * @param {string } password Parse.com password.
464468 */
465469function login ( username , password )
466470{
467- Parse . User . logIn ( username , password ,
468- {
469- success : function ( user )
470- {
471- currentuser = Parse . User . current ( ) ;
472- if ( syncing )
473- {
474- parse_getnotes ( ) ;
475- }
476-
477- } ,
478- error : function ( user , error )
479- {
480- signup ( username , password ) ;
481- }
471+ firebase . auth ( ) . signInWithEmailAndPassword ( username , password ) . then ( function ( ) {
472+ cloud_getnotes ( ) ;
473+ } ) . catch ( function ( error ) {
474+ signup ( username , password ) ;
482475 } ) ;
483476}
484477
485478/**
486- * Parse.com signup.
479+ * Firebase signup.
487480 * @param {string } username Desired username.
488481 * @param {string } password Desired password.
489482 */
490483function signup ( username , password )
491484{
492- var user = new Parse . User ( ) ;
493- user . set ( "username" , username ) ;
494- user . set ( "password" , password ) ;
485+ firebase . auth ( ) . createUserWithEmailAndPassword ( username , password ) . catch ( function ( error ) {
486+ var errorCode = error . code ;
487+ var errorMessage = error . message ;
495488
496- user . signUp ( null ,
497- {
498- success : function ( user )
499- {
500- login ( username , password ) ;
501- } ,
502- error : function ( user , error )
503- {
504- if ( error . code === 202 )
505- {
506- $ ( "#syncing" ) . prop ( "checked" , false ) ;
507- alert ( "Username taken or password is incorrect." ) ;
508- }
509- }
489+ $ ( "#syncing" ) . prop ( "checked" , false ) ;
490+ alert ( "Username taken or password is incorrect." ) ;
510491 } ) ;
511492}
512493
513494/**
514495 * Syncs notes from Parse.com to local notes array.
515496 */
516- function parse_getnotes ( )
517- {
518- var query = new Parse . Query ( Parse_Notes ) ;
519- query . find (
520- {
521- success : function ( results )
522- {
523- if ( results . length < 1 )
524- {
525- Private_Parse_Notes . set ( "content" , notes ) ;
526- Private_Parse_Notes . setACL ( new Parse . ACL ( Parse . User . current ( ) ) ) ;
527- Private_Parse_Notes . save ( null ,
528- {
529- success : function ( parsenote )
530- {
531- parsenoteid = parsenote . id ;
532- }
533- } ) ;
534- }
535- else
536- {
537- parsenoteid = results [ 0 ] . id ;
538- if ( _ . isEqual ( notes , results [ 0 ] . get ( "content" ) ) === false ) //Cloud copy does not match local copy.
539- {
540- notes = results [ 0 ] . get ( "content" ) ; //Copy the cloud copy into memory.
541- preloadCache ( ) ; //Update the cache.
542- updateList ( ) ; //Update the list.
543- loadNote ( current ) ; //Update the note you're currently viewing.
544- }
545- }
546- } ,
547- error : function ( error )
548- {
549- alert ( "Error: " + error . code + " " + error . message ) ;
497+ function cloud_getnotes ( )
498+ {
499+ var userId = firebase . auth ( ) . currentUser . uid ;
500+ firebase . database ( ) . ref ( '/notes/' + userId ) . once ( 'value' ) . then ( function ( snapshot ) {
501+ if ( snapshot . val ( ) ) {
502+ notes = snapshot . val ( ) ;
503+ preloadCache ( ) ; //Update the cache.
504+ updateList ( ) ; //Update the list.
505+ loadNote ( current ) ; //Update the note you're currently viewing.
506+ } else {
507+ cloud_savenotes ( ) ;
550508 }
551509 } ) ;
552510}
553511
554512/**
555513 * Save local notes array to Parse.com
556514 */
557- function parse_savenotes ( )
515+ function cloud_savenotes ( )
558516{
559- var query = new Parse . Query ( Parse_Notes ) ;
560- query . get ( parsenoteid ,
561- {
562- success : function ( n )
563- {
564- n . set ( "content" , notes ) ;
565- n . save ( ) ;
566- }
567- } ) ;
517+ var userId = firebase . auth ( ) . currentUser . uid ;
518+ firebase . database ( ) . ref ( 'notes/' + userId ) . set ( notes ) ;
568519}
569520
570521/**
@@ -633,7 +584,7 @@ function saveNotes()
633584{
634585 if ( syncing )
635586 {
636- parse_savenotes ( ) ;
587+ cloud_savenotes ( ) ;
637588 }
638589 store . save (
639590 {
0 commit comments