@@ -31,7 +31,7 @@ import {
3131} from "@mdi/js" ;
3232import moment from "moment" ;
3333
34- import { AuthenticationType , OAuth2 } from "@/types/general" ;
34+ import { Status , OAuth2 } from "@/types/general" ;
3535import { GitHub } from "@/lib/github" ;
3636import {
3737 IssueElement ,
@@ -57,11 +57,11 @@ interface HomeProps {
5757const github = new GitHub ( ) ;
5858
5959export default function Home ( { clientId } : HomeProps ) : ReactElement {
60- const [ auth , setAuth ] = useAuth ( ) ;
6160 const [ alert , setAlert ] = useState < string > ( ) ;
62- const [ authenticated , setAuthenticated ] = useState < AuthenticationType > ( 0 ) ;
61+ const [ auth , setAuth ] = useAuth ( ) ;
6362 const [ authorizeUrl , setAuthorizeUrl ] = useState < string > ( ) ;
6463 const [ repositoryData , setRepositoryData ] = useRepository ( ) ;
64+ const [ status , setStatus ] = useState < Status > ( Status . NotAuthorized ) ;
6565 const [ , setUserData ] = useUser ( ) ;
6666 const [ , setViewerData ] = useViewer ( ) ;
6767
@@ -72,7 +72,7 @@ export default function Home({ clientId }: HomeProps): ReactElement {
7272 setAlert ( undefined ) ;
7373 setAuthorizeUrl ( undefined ) ;
7474
75- if ( authenticated > AuthenticationType . NotAuthorized ) return ;
75+ if ( status > Status . NotAuthorized ) return ;
7676 console . log ( "Authenticating..." ) ;
7777
7878 let oAuthData : OAuth2 | null = null ;
@@ -96,12 +96,12 @@ export default function Home({ clientId }: HomeProps): ReactElement {
9696 ) ;
9797 } ) ( ) ;
9898 }
99- setAuthenticated ( AuthenticationType . Authenticated ) ;
99+ setStatus ( Status . Authenticated ) ;
100100 return ;
101101 }
102102
103103 if ( code && code . length > 0 && state && state . length > 0 ) {
104- setAuthenticated ( AuthenticationType . Authenticating ) ;
104+ setStatus ( Status . Authenticating ) ;
105105 console . log ( "Using code and state:" , code , state ) ;
106106 ( async ( ) => {
107107 oAuthData = await github . authenticate (
@@ -133,19 +133,19 @@ export default function Home({ clientId }: HomeProps): ReactElement {
133133
134134 setAuth ( oAuthData ) ;
135135 github . setAuth ( oAuthData ) ;
136- setAuthenticated ( AuthenticationType . Authenticated ) ;
136+ setStatus ( Status . Authenticated ) ;
137137 } ) ( ) ;
138138 return ;
139139 } else {
140140 const url = github . getAuthorizeUrl ( clientId , window . location . origin ) ;
141141 console . log ( "Generating authorize URL:" , url ) ;
142142 setAuthorizeUrl ( url ) ;
143143 }
144- } , [ authenticated , clientId , code , router , setAuth , state ] ) ;
144+ } , [ status , clientId , code , router , setAuth , state ] ) ;
145145
146146 useEffect ( ( ) => {
147- console . log ( "Authenticated :" , authenticated ) ;
148- if ( authenticated !== AuthenticationType . Authenticated ) return ;
147+ console . log ( "Status :" , status ) ;
148+ if ( status !== Status . Authenticated ) return ;
149149 ( async ( ) => {
150150 if ( ! github . auth )
151151 if ( ! auth ) return ;
@@ -159,16 +159,19 @@ export default function Home({ clientId }: HomeProps): ReactElement {
159159 }
160160 setViewerData ( data . viewer ) ;
161161 } ) ( ) ;
162- } , [ auth , authenticated , setViewerData ] ) ;
162+ } , [ auth , status , setViewerData ] ) ;
163163
164164 useEffect ( ( ) => {
165- if ( authenticated !== AuthenticationType . Authenticated ) return ;
165+ if ( status !== Status . Authenticated ) return ;
166166 let type : string | null = null ,
167167 owner : string | null = null ,
168168 repository : string | null = null ;
169169 const currentRepositoryStr =
170170 window . localStorage . getItem ( "currentRepository" ) ;
171- if ( ! currentRepositoryStr ) return ;
171+ if ( ! currentRepositoryStr ) {
172+ setStatus ( Status . NoRepository ) ;
173+ return ;
174+ }
172175 try {
173176 const currentRepository = JSON . parse ( currentRepositoryStr ) ;
174177 type = currentRepository . type ;
@@ -205,7 +208,7 @@ export default function Home({ clientId }: HomeProps): ReactElement {
205208 }
206209 setUserData ( data . user ) ;
207210 } ) ;
208- } , [ authenticated , setRepositoryData , setUserData ] ) ;
211+ } , [ status , setRepositoryData , setUserData ] ) ;
209212
210213 const daysSince = useMemo < number > ( ( ) => {
211214 const firstDate = moment ( ) . subtract ( 1 , "month" ) . startOf ( "month" ) . toDate ( ) ;
@@ -441,7 +444,13 @@ export default function Home({ clientId }: HomeProps): ReactElement {
441444 container
442445 alignContent = "space-around"
443446 justifyContent = "space-around" >
444- < CircularProgress color = "primary" />
447+ { status === Status . NoRepository ? (
448+ < Typography variant = "h4" noWrap >
449+ Please select a repository
450+ </ Typography >
451+ ) : (
452+ < CircularProgress color = "primary" />
453+ ) }
445454 </ Grid >
446455 ) }
447456 </ Grid >
0 commit comments