-
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.
Merge pull request #933 from lens-protocol/release-react-2.2.0
chore: prepare release react 2.2.0
- Loading branch information
Showing
81 changed files
with
11,032 additions
and
1,207 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { LensClient, ManagedProfileVisibility, development } from '@lens-protocol/client'; | ||
|
||
import { setupWallet } from '../shared/setupWallet'; | ||
|
||
/** | ||
* Notice! | ||
* Hide managed profile feature works only for managed profiles that are not owned by the wallet. | ||
*/ | ||
|
||
async function fetchManagedNotOwnedProfiles(client: LensClient, address: string) { | ||
const result = await client.wallet.profilesManaged({ | ||
for: address, | ||
includeOwned: false, // important! | ||
hiddenFilter: ManagedProfileVisibility.NoneHidden, | ||
}); | ||
|
||
console.log( | ||
`Profiles managed by ${address}: `, | ||
result.items.map((item) => ({ | ||
id: item.id, | ||
handle: item.handle, | ||
})), | ||
); | ||
|
||
return result.items; | ||
} | ||
|
||
async function main() { | ||
const client = new LensClient({ | ||
environment: development, | ||
}); | ||
|
||
const wallet = setupWallet(); | ||
const address = await wallet.getAddress(); | ||
|
||
const profiles = await fetchManagedNotOwnedProfiles(client, address); | ||
|
||
if (profiles.length === 0) { | ||
console.log('No managed profiles found'); | ||
process.exit(0); | ||
} | ||
|
||
const profileIdToHide = profiles[0].id; | ||
|
||
// Hide the first managed profile | ||
console.log(`Hiding profile ${profileIdToHide} from managed profiles list`); | ||
|
||
await client.wallet.hideManagedProfile({ | ||
profileId: profileIdToHide, | ||
}); | ||
|
||
// Fetch managed profiles again | ||
await fetchManagedNotOwnedProfiles(client, address); | ||
|
||
// Unhide the profile | ||
console.log(`Unhiding profile ${profileIdToHide}`); | ||
|
||
await client.wallet.unhideManagedProfile({ | ||
profileId: profileIdToHide, | ||
}); | ||
|
||
// Fetch managed profiles again | ||
await fetchManagedNotOwnedProfiles(client, address); | ||
} | ||
|
||
main(); |
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 |
---|---|---|
@@ -1,15 +1,43 @@ | ||
import { profileId, useProfile } from '@lens-protocol/react-web'; | ||
import { useProfile } from '@lens-protocol/react-web'; | ||
import { Suspense, startTransition, useState } from 'react'; | ||
|
||
import { ErrorMessage } from '../components/error/ErrorMessage'; | ||
import { Loading } from '../components/loading/Loading'; | ||
import { ProfileCard } from './components/ProfileCard'; | ||
|
||
export function UseProfileInner({ localName }: { localName: string }) { | ||
const { data, error } = useProfile({ forHandle: `lens/${localName}`, suspense: true }); | ||
|
||
if (error) { | ||
return <p>Profile not found.</p>; | ||
} | ||
|
||
return <ProfileCard profile={data} />; | ||
} | ||
|
||
export function UseProfile() { | ||
const { data: profile, error, loading } = useProfile({ forProfileId: profileId('0x01') }); | ||
const [localName, setLocalName] = useState('brainjammer'); | ||
|
||
const update = (event: React.ChangeEvent<HTMLInputElement>) => | ||
startTransition(() => { | ||
if (event.target.value.length > 0) { | ||
setLocalName(event.target.value); | ||
} | ||
}); | ||
|
||
if (loading) return <Loading />; | ||
return ( | ||
<div> | ||
<h1> | ||
<code>useProfile</code> | ||
</h1> | ||
|
||
if (error) return <ErrorMessage error={error} />; | ||
<label> | ||
lens/ | ||
<input type="text" name="localName" defaultValue={localName} onChange={update} /> | ||
</label> | ||
|
||
return <ProfileCard profile={profile} />; | ||
<Suspense fallback={<Loading />}> | ||
<UseProfileInner localName={localName} /> | ||
</Suspense> | ||
</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,122 @@ | ||
import { | ||
useAddProfileInterests, | ||
useRemoveProfileInterests, | ||
ProfileInterestTypes, | ||
Profile, | ||
} from '@lens-protocol/react-web'; | ||
import { Fragment, useMemo } from 'react'; | ||
|
||
import { RequireProfileSession } from '../components/auth'; | ||
|
||
// Capitalizes each word in a string | ||
function capitalize(label: string): string { | ||
return label.toLowerCase().replace(/\b\w/g, (char) => char.toUpperCase()); | ||
} | ||
|
||
type Interest = { | ||
parent: string; | ||
value: ProfileInterestTypes; | ||
label: string; | ||
}; | ||
|
||
// Processes raw interest types into structured interests array | ||
function createInterests(categories: ProfileInterestTypes[]): Interest[] { | ||
return categories.map((item) => { | ||
const [parent, subcategory] = item.split('__'); | ||
const label = capitalize( | ||
subcategory ? subcategory.replace(/_/g, ' ') : parent.replace(/_/g, ' '), | ||
); | ||
return { parent, value: item, label }; | ||
}); | ||
} | ||
|
||
type ButtonProps = { | ||
isActive: boolean; | ||
onClick: () => void; | ||
children: React.ReactNode; | ||
}; | ||
|
||
function ToggleButton({ isActive, onClick, children }: ButtonProps) { | ||
const normalStyle = { | ||
backgroundColor: 'transparent', | ||
border: '1px solid grey', | ||
color: '#111', | ||
outline: 'none', | ||
}; | ||
|
||
const activeStyle = { | ||
...normalStyle, | ||
backgroundColor: '#333', | ||
color: '#eee', | ||
}; | ||
|
||
return ( | ||
<button style={isActive ? activeStyle : normalStyle} onClick={onClick}> | ||
{children} | ||
</button> | ||
); | ||
} | ||
|
||
function UseProfileInterestsInner({ profile }: { profile: Profile }) { | ||
const { execute: addInterests } = useAddProfileInterests(); | ||
const { execute: removeInterests } = useRemoveProfileInterests(); | ||
|
||
const groupedInterests = useMemo(() => { | ||
const interests = createInterests(Object.values(ProfileInterestTypes)); | ||
|
||
// Group interests by category | ||
return interests.reduce((acc, interest) => { | ||
acc[interest.parent] = acc[interest.parent] || []; | ||
acc[interest.parent].push(interest); | ||
return acc; | ||
}, {} as Record<string, Interest[]>); | ||
}, []); | ||
|
||
const handleClick = async (interest: ProfileInterestTypes) => { | ||
const request = { | ||
interests: [interest], | ||
}; | ||
|
||
if (profile.interests.includes(interest)) { | ||
await removeInterests(request); | ||
} else { | ||
await addInterests(request); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
{Object.entries(groupedInterests).map(([category, items]) => ( | ||
<div key={category}> | ||
<h4>{capitalize(category.replace(/_/g, ' '))}</h4> | ||
<div> | ||
{items.map((item) => ( | ||
<Fragment key={item.value}> | ||
<ToggleButton | ||
onClick={() => handleClick(item.value)} | ||
isActive={profile.interests.includes(item.value)} | ||
> | ||
{item.label} | ||
</ToggleButton>{' '} | ||
</Fragment> | ||
))} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export function UseProfileInterests() { | ||
return ( | ||
<div> | ||
<h2> | ||
<code>useAddProfileInterests & useRemoveProfileInterests</code> | ||
</h2> | ||
|
||
<RequireProfileSession message="Log in to view this example."> | ||
{({ profile }) => <UseProfileInterestsInner profile={profile} />} | ||
</RequireProfileSession> | ||
</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
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.