-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: top styling * chore: compatible section changes * chore: wip remove home * chore: refactor login flow * chore: yarn lock update
- Loading branch information
Showing
40 changed files
with
418 additions
and
1,267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,90 @@ | ||
import React from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import { useAccount } from '../src/context/AccountContext'; | ||
import { SessionLogin } from '../src/views/login/SessionLogin'; | ||
import { useRouter } from 'next/router'; | ||
import { HomePageView } from '../src/views/homepage/HomePage'; | ||
import { appendBasePath } from '../src/utils/basePath'; | ||
import { LoadingView } from '../src/components/loading/LoadingView'; | ||
import { TopSection } from '../src/views/homepage/Top'; | ||
import { LoginBox } from '../src/views/homepage/LoginBox'; | ||
import { Accounts } from '../src/views/homepage/Accounts'; | ||
import { | ||
useStatusState, | ||
useStatusDispatch, | ||
} from '../src/context/StatusContext'; | ||
import { useGetCanConnectLazyQuery } from '../src/generated/graphql'; | ||
import { LoadingCard } from '../src/components/loading/LoadingCard'; | ||
import { Section } from '../src/components/section/Section'; | ||
import { toast } from 'react-toastify'; | ||
|
||
const ContextApp: React.FC = () => { | ||
const ContextApp = () => { | ||
const { push } = useRouter(); | ||
const { loggedIn, admin, viewOnly, sessionAdmin } = useAccount(); | ||
const { | ||
name, | ||
host, | ||
cert, | ||
admin, | ||
viewOnly, | ||
sessionAdmin, | ||
accounts, | ||
} = useAccount(); | ||
const { loading: statusLoading } = useStatusState(); | ||
const dispatch = useStatusDispatch(); | ||
|
||
if (loggedIn) { | ||
if (admin === '' || viewOnly !== '' || sessionAdmin !== '') { | ||
const change = accounts.length <= 1 && admin === ''; | ||
const isSession = admin !== '' && viewOnly === ''; | ||
|
||
const [getCanConnect, { data, loading, error }] = useGetCanConnectLazyQuery({ | ||
fetchPolicy: 'network-only', | ||
onError: () => { | ||
toast.error(`Unable to connect to ${name}`); | ||
dispatch({ type: 'disconnected' }); | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
if (loading && !error) { | ||
dispatch({ type: 'loading' }); | ||
} | ||
if (!loading && data?.getNodeInfo && !error) { | ||
dispatch({ type: 'connected' }); | ||
push(appendBasePath('/home')); | ||
return <LoadingView />; | ||
} | ||
} | ||
}, [loading, data, error]); | ||
|
||
useEffect(() => { | ||
if (viewOnly !== '' || sessionAdmin !== '') { | ||
getCanConnect({ | ||
variables: { | ||
auth: { | ||
host, | ||
macaroon: viewOnly !== '' ? viewOnly : sessionAdmin, | ||
cert, | ||
}, | ||
}, | ||
}); | ||
} | ||
}, [viewOnly, sessionAdmin]); | ||
|
||
return !loggedIn && admin === '' ? <HomePageView /> : <SessionLogin />; | ||
return ( | ||
<> | ||
<TopSection /> | ||
{statusLoading && ( | ||
<Section withColor={false}> | ||
<LoadingCard | ||
inverseColor={true} | ||
loadingHeight={'160px'} | ||
title={`Connecting to ${name}`} | ||
/> | ||
</Section> | ||
)} | ||
{!statusLoading && ( | ||
<> | ||
{isSession && <SessionLogin />} | ||
<Accounts change={!isSession} /> | ||
<LoginBox change={change} /> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default ContextApp; |
Oops, something went wrong.