-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71e8793
commit c17c909
Showing
78 changed files
with
6,716 additions
and
149 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 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 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Outlet } from 'react-router-dom'; | ||
|
||
import { Breadcrumbs } from './components/Breadcrumbs'; | ||
|
||
export function Layout() { | ||
return ( | ||
<> | ||
<Breadcrumbs /> | ||
<Outlet /> | ||
</> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { ProfileId, useLogin, useProfiles } from '@lens-protocol/react'; | ||
import toast from 'react-hot-toast'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useAccount, useConnect } from 'wagmi'; | ||
import { InjectedConnector } from 'wagmi/connectors/injected'; | ||
|
||
import { ErrorMessage } from './components/error/ErrorMessage'; | ||
import { Loading } from './components/loading/Loading'; | ||
import { never } from './utils'; | ||
|
||
function ProfilesList({ owner }: { owner: string }) { | ||
const navigate = useNavigate(); | ||
const { execute: login, isPending: isLoginPending } = useLogin(); | ||
const { data: profiles, error, loading } = useProfiles({ where: { ownedBy: [owner] } }); | ||
|
||
const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
|
||
const form = event.currentTarget; | ||
const formData = new FormData(form); | ||
|
||
const profileId = (formData.get('id') as string) ?? never(); | ||
|
||
const result = await login({ | ||
address: owner, | ||
profileId: profileId as ProfileId, | ||
}); | ||
|
||
if (result.isSuccess()) { | ||
toast.success(`Welcome ${String(result.value.handle)}`); | ||
return navigate('/'); | ||
} | ||
|
||
toast.error(result.error.message); | ||
}; | ||
|
||
if (loading) { | ||
return <Loading />; | ||
} | ||
|
||
if (error) { | ||
return <ErrorMessage error={error} />; | ||
} | ||
|
||
if (profiles.length === 0) { | ||
return <p>No profiles on this wallet.</p>; | ||
} | ||
|
||
return ( | ||
<form onSubmit={onSubmit}> | ||
<fieldset> | ||
<legend>Which Profile you want to log-in with?</legend> | ||
|
||
{profiles.map((profile, idx) => ( | ||
<label key={profile.id}> | ||
<input | ||
disabled={isLoginPending} | ||
type="radio" | ||
defaultChecked={idx === 0} | ||
name="id" | ||
value={profile.id} | ||
/> | ||
{profile.handle} | ||
</label> | ||
))} | ||
|
||
<div> | ||
<button disabled={isLoginPending} type="submit"> | ||
Continue | ||
</button> | ||
</div> | ||
</fieldset> | ||
</form> | ||
); | ||
} | ||
|
||
export function LogInPage() { | ||
const { address, isDisconnected } = useAccount(); | ||
|
||
const { connect } = useConnect({ | ||
connector: new InjectedConnector(), | ||
}); | ||
|
||
return ( | ||
<div> | ||
{isDisconnected && <button onClick={() => connect()}>Connect first</button>} | ||
|
||
{address && <ProfilesList owner={address} />} | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Link } from 'react-router-dom'; | ||
|
||
// TODO render log out button once useSession is implemented | ||
export function LoginButton() { | ||
return <Link to="/login">Log in</Link>; | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './LoginButton'; |
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 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
Oops, something went wrong.