6
6
7
7
import { AuthProviderInfo } from "@gitpod/gitpod-protocol" ;
8
8
import * as GitpodCookie from "@gitpod/gitpod-protocol/lib/util/gitpod-cookie" ;
9
- import { useContext , useEffect , useState } from "react" ;
9
+ import { useContext , useEffect , useMemo , useState } from "react" ;
10
10
import { UserContext } from "./user-context" ;
11
11
import { TeamsContext } from "./teams/teams-context" ;
12
12
import { getGitpodService } from "./service/service" ;
@@ -29,7 +29,7 @@ function Item(props: { icon: string; iconSize?: string; text: string }) {
29
29
const iconSize = props . iconSize || 28 ;
30
30
return (
31
31
< div className = "flex-col items-center w-1/3 px-3" >
32
- < img src = { props . icon } className = { `w-${ iconSize } m-auto h-24` } />
32
+ < img src = { props . icon } alt = { props . text } className = { `w-${ iconSize } m-auto h-24` } />
33
33
< div className = "text-gray-400 text-sm w-36 h-20 text-center" > { props . text } </ div >
34
34
</ div >
35
35
) ;
@@ -51,26 +51,28 @@ export function Login() {
51
51
const { setUser } = useContext ( UserContext ) ;
52
52
const { setTeams } = useContext ( TeamsContext ) ;
53
53
54
- const urlHash = getURLHash ( ) ;
55
- let hostFromContext : string | undefined ;
56
- let repoPathname : string | undefined ;
57
-
58
- try {
59
- if ( urlHash . length > 0 ) {
60
- const url = new URL ( urlHash ) ;
61
- hostFromContext = url . host ;
62
- repoPathname = url . pathname ;
63
- }
64
- } catch ( error ) {
65
- // Hash is not a valid URL
66
- }
54
+ const urlHash = useMemo ( ( ) => getURLHash ( ) , [ ] ) ;
67
55
68
56
const [ authProviders , setAuthProviders ] = useState < AuthProviderInfo [ ] > ( [ ] ) ;
69
57
const [ errorMessage , setErrorMessage ] = useState < string | undefined > ( undefined ) ;
70
58
const [ providerFromContext , setProviderFromContext ] = useState < AuthProviderInfo > ( ) ;
59
+ const [ hostFromContext , setHostFromContext ] = useState < string | undefined > ( ) ;
60
+ const [ repoPathname , setRepoPathname ] = useState < string | undefined > ( ) ;
71
61
72
62
const showWelcome = ! hasLoggedInBefore ( ) && ! hasVisitedMarketingWebsiteBefore ( ) && ! urlHash . startsWith ( "https://" ) ;
73
63
64
+ useEffect ( ( ) => {
65
+ try {
66
+ if ( urlHash . length > 0 ) {
67
+ const url = new URL ( urlHash ) ;
68
+ setHostFromContext ( url . host ) ;
69
+ setRepoPathname ( url . pathname ) ;
70
+ }
71
+ } catch ( error ) {
72
+ // Hash is not a valid URL
73
+ }
74
+ } , [ urlHash ] ) ;
75
+
74
76
useEffect ( ( ) => {
75
77
( async ( ) => {
76
78
setAuthProviders ( await getGitpodService ( ) . server . getAuthProviders ( ) ) ;
@@ -82,7 +84,7 @@ export function Login() {
82
84
const providerFromContext = authProviders . find ( ( provider ) => provider . host === hostFromContext ) ;
83
85
setProviderFromContext ( providerFromContext ) ;
84
86
}
85
- } , [ authProviders ] ) ;
87
+ } , [ hostFromContext , authProviders ] ) ;
86
88
87
89
const authorizeSuccessful = async ( payload ?: string ) => {
88
90
updateUser ( ) . catch ( console . error ) ;
0 commit comments