-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simple lens<>xmtp web integration (#401)
- Loading branch information
Showing
50 changed files
with
1,409 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@lens-protocol/shared-kernel": minor | ||
"@lens-protocol/react-web": minor | ||
"@lens-protocol/domain": minor | ||
"@lens-protocol/react": minor | ||
--- | ||
|
||
**Added** experimental hooks that integrate with @xmtp/react-sdk |
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 |
---|---|---|
|
@@ -23,4 +23,8 @@ export const CATEGORIES = [ | |
label: 'Misc', | ||
path: '/misc', | ||
}, | ||
{ | ||
label: 'Inbox', | ||
path: '/inbox', | ||
}, | ||
]; |
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,26 @@ | ||
import { LinkCard } from '../components/LinkCard'; | ||
|
||
const inboxHooks = [ | ||
{ | ||
label: 'useConversations', | ||
description: `List all conversations. Show a conversation with messages. Send a message.`, | ||
path: '/inbox/useConversations', | ||
}, | ||
{ | ||
label: 'useCreateConversation', | ||
description: `Start a new conversation.`, | ||
path: '/inbox/useCreateConversation', | ||
}, | ||
]; | ||
|
||
export function InboxPage() { | ||
return ( | ||
<div> | ||
<h1>Inbox</h1> | ||
|
||
{inboxHooks.map((link) => ( | ||
<LinkCard key={link.path} {...link} /> | ||
))} | ||
</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,88 @@ | ||
import { ProfileOwnedByMe, useEnhanceConversation } from '@lens-protocol/react-web'; | ||
import { Conversation, useClient, useConversations } from '@xmtp/react-sdk'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import { LoginButton, WhenLoggedInWithProfile, WhenLoggedOut } from '../components/auth'; | ||
import { Loading } from '../components/loading/Loading'; | ||
import { ConversationCard } from './components/ConversationCard'; | ||
import { EnableConversationsButton } from './components/EnableConversationsButton'; | ||
import { MessageComposer } from './components/MessageComposer'; | ||
import { MessagesCard } from './components/MessagesCard'; | ||
|
||
type UseConversationsInnerProps = { | ||
conversation: Conversation; | ||
profile: ProfileOwnedByMe; | ||
}; | ||
|
||
function UseConversationInner({ conversation, profile }: UseConversationsInnerProps) { | ||
const { data: enhancedConversation, loading } = useEnhanceConversation({ conversation, profile }); | ||
|
||
if (loading) return <Loading />; | ||
|
||
if (enhancedConversation) { | ||
return ( | ||
<div> | ||
<ConversationCard conversation={enhancedConversation} /> | ||
<MessageComposer conversation={enhancedConversation} /> | ||
<MessagesCard conversation={enhancedConversation} /> | ||
</div> | ||
); | ||
} | ||
|
||
return <div>Conversation not found</div>; | ||
} | ||
|
||
type EnableConversationsProps = { | ||
profile: ProfileOwnedByMe; | ||
conversationId: string; | ||
}; | ||
|
||
function EnableConversations({ profile, conversationId }: EnableConversationsProps) { | ||
const { client } = useClient(); | ||
const { conversations, error, isLoading } = useConversations(); | ||
|
||
if (!client) { | ||
return <EnableConversationsButton />; | ||
} | ||
|
||
if (error) { | ||
return <div>An error occurred while fetching conversations</div>; | ||
} | ||
|
||
const requestedConversation = conversations?.find((c) => c.topic === conversationId); | ||
|
||
return ( | ||
<div> | ||
{isLoading && <Loading />} | ||
|
||
{requestedConversation && ( | ||
<UseConversationInner conversation={requestedConversation} profile={profile} /> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export function UseConversation() { | ||
const { conversationId } = useParams(); | ||
|
||
if (!conversationId) { | ||
return <div>ConversationId not provided</div>; | ||
} | ||
|
||
return ( | ||
<> | ||
<h1> | ||
<code>useConversation</code> | ||
</h1> | ||
<WhenLoggedInWithProfile> | ||
{({ profile }) => <EnableConversations profile={profile} conversationId={conversationId} />} | ||
</WhenLoggedInWithProfile> | ||
<WhenLoggedOut> | ||
<div> | ||
<p>You must be logged in to use this example.</p> | ||
<LoginButton /> | ||
</div> | ||
</WhenLoggedOut> | ||
</> | ||
); | ||
} |
Oops, something went wrong.