-
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.
feat: implements useLazyProfile hook
- Loading branch information
1 parent
63af2f6
commit 7149811
Showing
12 changed files
with
374 additions
and
48 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
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,47 @@ | ||
import { profileId, useLazyProfile } from '@lens-protocol/react'; | ||
import toast from 'react-hot-toast'; | ||
|
||
import { ErrorMessage } from '../components/error/ErrorMessage'; | ||
import { never } from '../utils'; | ||
import { ProfileCard } from './components/ProfileCard'; | ||
|
||
export function UseLazyProfile() { | ||
const { data: profile, error, loading, execute } = useLazyProfile(); | ||
|
||
const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
|
||
const form = event.currentTarget; | ||
const formData = new FormData(form); | ||
|
||
const id = profileId(formData.get('id') as string) ?? never(); | ||
|
||
const result = await execute({ forProfileId: id }); | ||
|
||
if (result.isFailure()) { | ||
toast.error(result.error.message); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<form onSubmit={onSubmit}> | ||
<fieldset> | ||
<legend>Which Profile you want to log-in with?</legend> | ||
|
||
<input name="id" defaultValue="0x01" /> | ||
|
||
<div> | ||
<button disabled={loading} type="submit"> | ||
{loading ? 'Loading...' : 'Load'} | ||
</button> | ||
</div> | ||
</fieldset> | ||
</form> | ||
|
||
{profile && <ProfileCard profile={profile} />} | ||
|
||
{error && <ErrorMessage error={error} />} | ||
</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
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,7 +1,10 @@ | ||
import { useAsyncTask } from '../helpers/tasks'; | ||
import { Profile } from '@lens-protocol/api-bindings'; | ||
import { LoginError, LoginRequest } from '@lens-protocol/domain/use-cases/authentication'; | ||
|
||
import { UseDeferredTask, useDeferredTask } from '../helpers/tasks'; | ||
import { useLoginController } from './adapters/useLoginController'; | ||
|
||
export function useLogin() { | ||
export function useLogin(): UseDeferredTask<Profile, LoginError, LoginRequest> { | ||
const login = useLoginController(); | ||
return useAsyncTask(login); | ||
return useDeferredTask(login); | ||
} |
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.