1- import Grid from ' @material-ui/core/Grid' ;
2- import fetch from ' isomorphic-unfetch' ;
3- import { NextRouter , withRouter } from ' next/router' ;
4- import { Component } from ' react' ;
5- import { docData } from ' rxfire/firestore' ;
6- import { Subject } from ' rxjs' ;
7- import { takeUntil } from ' rxjs/operators' ;
1+ import Grid from " @material-ui/core/Grid" ;
2+ import fetch from " isomorphic-unfetch" ;
3+ import { NextRouter , withRouter } from " next/router" ;
4+ import { Component } from " react" ;
5+ import { docData } from " rxfire/firestore" ;
6+ import { Subject } from " rxjs" ;
7+ import { takeUntil } from " rxjs/operators" ;
88
9- import BookDetail from ' ../components/BookDetail' ;
10- import BookPage from ' ../components/BookPage' ;
11- import ChapterDetail from ' ../components/ChapterDetail' ;
12- import loadFirebase from ' ../lib/firebase' ;
13- import BookModel from ' ../models/BookModel' ;
14- import ChapterModel from ' ../models/ChapterModel' ;
15- import PageModel from ' ../models/PageModel' ;
9+ import BookDetail from " ../components/BookDetail" ;
10+ import BookPage from " ../components/BookPage" ;
11+ import ChapterDetail from " ../components/ChapterDetail" ;
12+ import loadFirebase from " ../lib/firebase" ;
13+ import BookModel from " ../models/BookModel" ;
14+ import ChapterModel from " ../models/ChapterModel" ;
15+ import PageModel from " ../models/PageModel" ;
1616
1717class book extends Component <
1818 {
@@ -33,7 +33,7 @@ class book extends Component<
3333 book : { } ,
3434 chapter : { } ,
3535 page : { } ,
36- stopSubs : new Subject < boolean > ( )
36+ stopSubs : new Subject < boolean > ( ) ,
3737 } ;
3838
3939 static async getInitialProps ( { req, query } : any ) {
@@ -43,19 +43,19 @@ class book extends Component<
4343
4444 const retObj = {
4545 book : {
46- id : id
46+ id : id ,
4747 } ,
4848 chapter : {
49- id : chapterId
49+ id : chapterId ,
5050 } ,
5151 page : {
52- id : pageId
53- }
52+ id : pageId ,
53+ } ,
5454 } ;
5555 if ( req ) {
5656 /* Just a note using Promise.all() would probably be faster */
5757 if ( id ) {
58- console . log ( ' Server Fetching Book' , id ) ;
58+ console . log ( " Server Fetching Book" , id ) ;
5959 const res = await fetch (
6060 /*
6161 API can be found in next.config.js
@@ -68,19 +68,17 @@ class book extends Component<
6868 retObj . book = json ;
6969 }
7070 if ( chapterId ) {
71- console . log ( ' Server Fetching Chapter' , chapterId ) ;
71+ console . log ( " Server Fetching Chapter" , chapterId ) ;
7272 const res = await fetch (
7373 `${ process . env . API_ENDPOINT } chapter?id=${ id } &chapterId=${ chapterId } `
7474 ) ;
7575 const json = await res . json ( ) ;
7676 retObj . chapter = json ;
7777 }
7878 if ( pageId ) {
79- console . log ( ' Server Fetching Page' , pageId ) ;
79+ console . log ( " Server Fetching Page" , pageId ) ;
8080 const res = await fetch (
81- `${
82- process . env . API_ENDPOINT
83- } page?id=${ id } &chapterId=${ chapterId } &pageId=${ pageId } `
81+ `${ process . env . API_ENDPOINT } page?id=${ id } &chapterId=${ chapterId } &pageId=${ pageId } `
8482 ) ;
8583 const json = await res . json ( ) ;
8684 retObj . page = json ;
@@ -94,7 +92,7 @@ class book extends Component<
9492 book : this . props . book ,
9593 chapter : this . props . chapter ,
9694 page : this . props . page ,
97- firebase : await loadFirebase ( )
95+ firebase : await loadFirebase ( ) ,
9896 } ) ;
9997
10098 /* After client loads */
@@ -129,37 +127,37 @@ class book extends Component<
129127 pageId : string | undefined
130128 ) {
131129 if ( bookId ) {
132- const booksRef = this . state . firebase
130+ const booksRef = this . state . firebase . default
133131 . firestore ( )
134- . collection ( ' books' )
132+ . collection ( " books" )
135133 . doc ( bookId ) ;
136134 // Book Detail
137- docData ( booksRef , 'id' )
135+ docData ( booksRef , "id" )
138136 . pipe ( takeUntil ( this . state . stopSubs ) )
139- . subscribe ( book => {
137+ . subscribe ( ( book ) => {
140138 this . setState ( { book } ) ;
141139 } ) ;
142140 }
143141 // Chapter Detail
144142 if ( chapterId ) {
145- const chapterRef = this . state . firebase
143+ const chapterRef = this . state . firebase . default
146144 . firestore ( )
147145 . collection ( `books/${ bookId } /chapters` )
148146 . doc ( chapterId ) ;
149- docData ( chapterRef , 'id' )
147+ docData ( chapterRef , "id" )
150148 . pipe ( takeUntil ( this . state . stopSubs ) )
151- . subscribe ( chapter => {
149+ . subscribe ( ( chapter ) => {
152150 this . setState ( { chapter } ) ;
153151 } ) ;
154152
155153 if ( pageId ) {
156- const pageRef = this . state . firebase
154+ const pageRef = this . state . firebase . default
157155 . firestore ( )
158156 . collection ( `books/${ bookId } /chapters/${ chapterId } /pages` )
159157 . doc ( pageId ) ;
160- docData ( pageRef , 'id' )
158+ docData ( pageRef , "id" )
161159 . pipe ( takeUntil ( this . state . stopSubs ) )
162- . subscribe ( page => {
160+ . subscribe ( ( page ) => {
163161 this . setState ( { page } ) ;
164162 } ) ;
165163 } else {
0 commit comments