66
77import { AuthProviderInfo } from "@gitpod/gitpod-protocol" ;
88import * 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" ;
1010import { UserContext } from "./user-context" ;
1111import { TeamsContext } from "./teams/teams-context" ;
1212import { getGitpodService } from "./service/service" ;
@@ -29,7 +29,7 @@ function Item(props: { icon: string; iconSize?: string; text: string }) {
2929 const iconSize = props . iconSize || 28 ;
3030 return (
3131 < 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` } />
3333 < div className = "text-gray-400 text-sm w-36 h-20 text-center" > { props . text } </ div >
3434 </ div >
3535 ) ;
@@ -51,26 +51,28 @@ export function Login() {
5151 const { setUser } = useContext ( UserContext ) ;
5252 const { setTeams } = useContext ( TeamsContext ) ;
5353
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 ( ) , [ ] ) ;
6755
6856 const [ authProviders , setAuthProviders ] = useState < AuthProviderInfo [ ] > ( [ ] ) ;
6957 const [ errorMessage , setErrorMessage ] = useState < string | undefined > ( undefined ) ;
7058 const [ providerFromContext , setProviderFromContext ] = useState < AuthProviderInfo > ( ) ;
59+ const [ hostFromContext , setHostFromContext ] = useState < string | undefined > ( ) ;
60+ const [ repoPathname , setRepoPathname ] = useState < string | undefined > ( ) ;
7161
7262 const showWelcome = ! hasLoggedInBefore ( ) && ! hasVisitedMarketingWebsiteBefore ( ) && ! urlHash . startsWith ( "https://" ) ;
7363
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+
7476 useEffect ( ( ) => {
7577 ( async ( ) => {
7678 setAuthProviders ( await getGitpodService ( ) . server . getAuthProviders ( ) ) ;
@@ -82,7 +84,7 @@ export function Login() {
8284 const providerFromContext = authProviders . find ( ( provider ) => provider . host === hostFromContext ) ;
8385 setProviderFromContext ( providerFromContext ) ;
8486 }
85- } , [ authProviders ] ) ;
87+ } , [ hostFromContext , authProviders ] ) ;
8688
8789 const authorizeSuccessful = async ( payload ?: string ) => {
8890 updateUser ( ) . catch ( console . error ) ;
0 commit comments