Skip to content

Commit

Permalink
Merge branch 'lens-v2' into v2/bookmark-toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
reecejohnson committed Oct 18, 2023
2 parents 9fac313 + fca2473 commit 27c89e7
Show file tree
Hide file tree
Showing 87 changed files with 1,681 additions and 579 deletions.
7 changes: 7 additions & 0 deletions .changeset/honest-drinks-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lens-protocol/api-bindings": minor
"@lens-protocol/react": minor
"@lens-protocol/react-web": minor
---

adds publication bookmarks
6 changes: 6 additions & 0 deletions .changeset/loud-pets-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@lens-protocol/react": minor
"@lens-protocol/react-web": minor
---

**feat:** implements `useLogout` hook
9 changes: 9 additions & 0 deletions .changeset/olive-beans-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@lens-protocol/api-bindings": patch
"@lens-protocol/domain": patch
"@lens-protocol/react": patch
---

Rename useFollowProfile to useFollow
Rename useUnfollowProfile to useUnfollow
Add support for LensProfileManager to useFollow, useUnfollow and useUpdateFollowPolicy hooks
4 changes: 4 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"grumpy-coats-scream",
"happy-pumpkins-clean",
"heavy-dodos-raise",
"honest-drinks-try",
"hot-hornets-drum",
"large-cars-know",
"late-clocks-rhyme",
Expand All @@ -51,11 +52,14 @@
"long-carpets-marry",
"nervous-papayas-design",
"new-doors-sip",
"odd-cougars-poke",
"old-carrots-breathe",
"olive-beans-double",
"popular-pants-look",
"shaggy-carrots-cry",
"shy-pugs-taste",
"six-feet-sparkle",
"six-tigers-serve",
"slow-cats-dance",
"slow-melons-fail",
"tasty-houses-admire",
Expand Down
8 changes: 8 additions & 0 deletions .changeset/six-tigers-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@lens-protocol/gated-content": patch
"@lens-protocol/api-bindings": patch
"@lens-protocol/client": patch
"@lens-protocol/react": patch
---

Updated to support the latest API schema
2 changes: 1 addition & 1 deletion examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@bundlr-network/client": "^0.11.9",
"@lens-protocol/client": "workspace:*",
"@lens-protocol/metadata": "0.1.0-alpha.29",
"@lens-protocol/metadata": "0.1.0-alpha.30",
"dotenv": "^16.0.3",
"ethers": "^5.7.2",
"uuid": "^9.0.0",
Expand Down
10 changes: 6 additions & 4 deletions examples/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { MiscPage, UseCurrencies } from './misc';
import {
ProfilesPage,
UseFollowAndUnfollowProfile,
UseFollowAndUnfollow,
UseLazyProfile,
UseMutualFollowers,
UseProfile,
Expand All @@ -40,7 +40,7 @@ import {
UseUpdateProfileManagers,
UseWhoActedOnPublication,
} from './profiles';
import { UseUpdateProfileDetails } from './profiles/UseUpdateProfileDetails';
import { UseSetProfileMetadata } from './profiles/UseSetProfileMetadata';
import {
PublicationsPage,
UsePublication,
Expand All @@ -53,6 +53,7 @@ import { UseBookmarkToggle } from './publications/UseBookmarkToggle';
import { UseCreateComment } from './publications/UseCreateComment';
import { UseCreatePost } from './publications/UseCreatePost';
import { UseHidePublication } from './publications/UseHidePublication';
import { UseMyBookmarks } from './publications/UseMyBookmarks';

const { publicClient, webSocketPublicClient } = configureChains(
[polygonMumbai],
Expand Down Expand Up @@ -105,6 +106,7 @@ export function App() {
<Route path="useReportPublication" element={<UseReportPublication />} />
<Route path="useReactionToggle" element={<UseReactionToggle />} />
<Route path="useBookmarkToggle" element={<UseBookmarkToggle />} />
<Route path="useMyBookmarks" element={<UseMyBookmarks />} />
</Route>

<Route path="/profiles">
Expand All @@ -115,7 +117,7 @@ export function App() {
<Route path="useProfileFollowers" element={<UseProfileFollowers />} />
<Route path="useProfileFollowing" element={<UseProfileFollowing />} />
<Route path="useMutualFollowers" element={<UseMutualFollowers />} />
<Route path="useFollowProfile" element={<UseFollowAndUnfollowProfile />} />
<Route path="useFollow" element={<UseFollowAndUnfollow />} />
<Route path="useRecommendedProfiles" element={<UseRecommendedProfiles />} />
<Route path="useProfileManagers" element={<UseProfileManagers />} />
<Route
Expand All @@ -127,7 +129,7 @@ export function App() {
element={<UseWhoActedOnPublication />}
/>
<Route path="useProfileActionHistory" element={<UseProfileActionHistory />} />
<Route path="useSetProfileMetadata" element={<UseUpdateProfileDetails />} />
<Route path="useSetProfileMetadata" element={<UseSetProfileMetadata />} />
<Route path="useUpdateFollowPolicy" element={<UseUpdateFollowPolicy />} />
</Route>

Expand Down
1 change: 0 additions & 1 deletion examples/web/src/components/auth/LoginButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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>;
}
10 changes: 10 additions & 0 deletions examples/web/src/components/auth/LogoutButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useLogout } from '@lens-protocol/react-web';

export function LogoutButton() {
const { execute: logout } = useLogout();
return (
<a href="javascript:false" onClick={() => logout()}>
Log out
</a>
);
}
1 change: 1 addition & 0 deletions examples/web/src/components/auth/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './LoginButton';
export * from './LogoutButton';
export * from './WhenLoggedIn';
export * from './WhenLoggedOut';
export * from './UnauthenticatedFallback';
4 changes: 2 additions & 2 deletions examples/web/src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SessionType, useSession } from '@lens-protocol/react-web';
import { NavLink } from 'react-router-dom';

import { CATEGORIES } from '../../config';
import { LoginButton } from '../auth';
import { LoginButton, LogoutButton } from '../auth';

export function Header() {
const { data: session } = useSession();
Expand Down Expand Up @@ -37,7 +37,7 @@ export function Header() {
</strong>
)}

<LoginButton />
{session?.authenticated ? <LogoutButton /> : <LoginButton />}
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions examples/web/src/profiles/ProfilesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const profileHooks = [
path: '/profiles/useMutualFollowers',
},
{
label: 'useFollowProfile & useUnfollowProfile',
label: 'useFollow & useUnfollow',
description: `Follow and unfollow a profile.`,
path: '/profiles/useFollowProfile',
path: '/profiles/useFollow',
},
{
label: 'useRecommendedProfiles',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
Profile,
useExploreProfiles,
useFollowProfile,
useUnfollowProfile,
} from '@lens-protocol/react-web';
import { Profile, useExploreProfiles, useFollow, useUnfollow } from '@lens-protocol/react-web';

import { UnauthenticatedFallback, WhenLoggedIn, WhenLoggedOut } from '../components/auth';
import { ErrorMessage } from '../components/error/ErrorMessage';
Expand All @@ -15,13 +10,9 @@ type FollowButtonProps = {
};

function FollowButton({ followee }: FollowButtonProps) {
const { execute: follow, error: followError, loading: isFollowLoading } = useFollowProfile();
const { execute: follow, error: followError, loading: isFollowLoading } = useFollow();

const {
execute: unfollow,
error: unfollowError,
loading: isUnfollowLoading,
} = useUnfollowProfile();
const { execute: unfollow, error: unfollowError, loading: isUnfollowLoading } = useUnfollow();

if (followee.operations.isFollowedByMe.value) {
// or followee.operations.canFollow === TriStateValue.Yes
Expand Down Expand Up @@ -65,11 +56,11 @@ function UseFollowInner() {
);
}

export function UseFollowAndUnfollowProfile() {
export function UseFollowAndUnfollow() {
return (
<>
<h1>
<code>useFollowProfile / useUnfollowProfile</code>
<code>useFollow / useUnfollow</code>
</h1>
<WhenLoggedIn>
<UseFollowInner />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MetadataAttributeType, profile } from '@lens-protocol/metadata';
import { Profile, useSetProfileMetadata } from '@lens-protocol/react-web';
import { toast } from 'react-hot-toast';

import { WhenLoggedIn, WhenLoggedOut } from '../components/auth';
import { Loading } from '../components/loading/Loading';
Expand All @@ -18,35 +19,45 @@ function UpdateProfileForm({ activeProfile }: UpdateProfileFormProps) {

const formData = new FormData(event.currentTarget);

const name = formData.get('name') as string;
const name = formData.get('name') as string | undefined;
const bio = formData.get('bio') as string | undefined;
const location = formData.get('location') as string | undefined;
const website = formData.get('website') as string | undefined;

if (!location || !website) {
throw new Error('Location and website are required');
}

const metadata = profile({
name,
bio,
attributes: [
{
key: 'location',
value: location,
value: location ?? '',
type: MetadataAttributeType.STRING,
},
{
key: 'website',
value: website,
value: website ?? '',
type: MetadataAttributeType.STRING,
},
],
});

const metadataURI = await uploadJson(metadata);

await update({ metadataURI });
const result = await update({ metadataURI });

if (result.isFailure()) {
toast.error(result.error.message);
return;
}

const completion = await result.value.waitForCompletion();

if (completion.isFailure()) {
toast.error(completion.error.message);
return;
}

toast.success('Profile updated');
}

const location = activeProfile.metadata?.attributes?.find((a) => a.key === 'location');
Expand All @@ -60,7 +71,6 @@ function UpdateProfileForm({ activeProfile }: UpdateProfileFormProps) {
Name:
<br />
<input
required
type="text"
placeholder="Your name"
disabled={loading}
Expand All @@ -74,7 +84,6 @@ function UpdateProfileForm({ activeProfile }: UpdateProfileFormProps) {
<br />
<textarea
rows={3}
required
placeholder="Write a line about you"
style={{ resize: 'none' }}
disabled={loading}
Expand All @@ -88,11 +97,10 @@ function UpdateProfileForm({ activeProfile }: UpdateProfileFormProps) {
<br />
<input
type="text"
required
placeholder="Where are you?"
disabled={loading}
name="location"
defaultValue={location?.value ?? ''}
defaultValue={location?.value ?? undefined}
/>
</label>

Expand All @@ -101,7 +109,6 @@ function UpdateProfileForm({ activeProfile }: UpdateProfileFormProps) {
<br />
<input
type="text"
required
placeholder="https://example.com"
disabled={loading}
name="website"
Expand All @@ -118,11 +125,11 @@ function UpdateProfileForm({ activeProfile }: UpdateProfileFormProps) {
);
}

export function UseUpdateProfileDetails() {
export function UseSetProfileMetadata() {
return (
<div>
<h1>
<code>useUpdateProfileDetails</code>
<code>useSetProfileMetadata</code>
</h1>

<WhenLoggedIn loadingElement={<Loading />}>
Expand Down
2 changes: 1 addition & 1 deletion examples/web/src/profiles/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './ProfilesPage';
export * from './UseFollowAndUnfollowProfile';
export * from './UseFollowAndUnfollow';
export * from './UseLazyProfile';
export * from './UseMutualFollowers';
export * from './UseProfile';
Expand Down
5 changes: 5 additions & 0 deletions examples/web/src/publications/PublicationsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const publicationHooks = [
description: `Add or remove a bookmark to a publication.`,
path: '/publications/useBookmarkToggle',
},
{
label: 'useMyBookmarks',
description: `Fetch a list of publications that the current user has bookmarked.`,
path: '/publications/useMyBookmarks',
},
];

export function PublicationsPage() {
Expand Down
2 changes: 1 addition & 1 deletion examples/web/src/publications/UseHidePublication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function HidePublicationButton({ publication }: HidePublicationButtonProps) {
if (publication.isHidden) return <p>Publication is hidden</p>;

return (
<button onClick={hide} disabled={loading}>
<button onClick={() => hide()} disabled={loading}>
Hide
</button>
);
Expand Down
45 changes: 45 additions & 0 deletions examples/web/src/publications/UseMyBookmarks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useMyBookmarks } from '@lens-protocol/react-web';

import { UnauthenticatedFallback, WhenLoggedIn } from '../components/auth';
import { ErrorMessage } from '../components/error/ErrorMessage';
import { Loading } from '../components/loading/Loading';
import { useInfiniteScroll } from '../hooks/useInfiniteScroll';
import { PublicationCard } from './components/PublicationCard';

export function MyBookmarks() {
const {
data: publications,
error,
loading,
hasMore,
observeRef,
} = useInfiniteScroll(useMyBookmarks());

if (loading) return <Loading />;

if (error) return <ErrorMessage error={error} />;

if (publications.length === 0) return <p>No bookmarks yet.</p>;

return (
<div>
{publications.map((publication) => (
<PublicationCard key={publication.id} publication={publication} />
))}
{hasMore && <p ref={observeRef}>Loading more...</p>}
</div>
);
}

export function UseMyBookmarks() {
return (
<div>
<h1>
<code>useMyBookmarks</code>
</h1>

<WhenLoggedIn>{() => <MyBookmarks />}</WhenLoggedIn>
<UnauthenticatedFallback message="Log in to run this demo." />
</div>
);
}
Loading

0 comments on commit 27c89e7

Please sign in to comment.