1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

fixed orbis createPost

This commit is contained in:
marcoelissa 2022-11-22 20:30:21 +07:00
parent 8285249822
commit 19c5770ac9
6 changed files with 7754 additions and 1036 deletions

8742
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,7 @@
"@oceanprotocol/lib": "^2.4.0", "@oceanprotocol/lib": "^2.4.0",
"@oceanprotocol/typographies": "^0.1.0", "@oceanprotocol/typographies": "^0.1.0",
"@oceanprotocol/use-dark-mode": "^2.4.3", "@oceanprotocol/use-dark-mode": "^2.4.3",
"@orbisclub/orbis-sdk": "^0.4.4-beta.39", "@orbisclub/orbis-sdk": "^0.4.4-beta.41",
"@tippyjs/react": "^4.2.6", "@tippyjs/react": "^4.2.6",
"@urql/exchange-refocus": "^1.0.0", "@urql/exchange-refocus": "^1.0.0",
"@walletconnect/web3-provider": "^1.8.0", "@walletconnect/web3-provider": "^1.8.0",

View File

@ -60,8 +60,8 @@ export default function Postbox({
const content = { const content = {
body, body,
context, context,
master: replyTo ? replyTo.master || replyTo.stream_id : undefined, master: replyTo ? replyTo.master || replyTo.stream_id : null,
reply_to: replyTo ? replyTo.stream_id : undefined reply_to: replyTo ? replyTo.stream_id : null
// mentions: _mentions || undefined // mentions: _mentions || undefined
} }
@ -92,7 +92,7 @@ export default function Postbox({
console.log(_callbackContent) console.log(_callbackContent)
if (callback) callback(_callbackContent) callback(_callbackContent)
postBoxArea.current.innerText = '' postBoxArea.current.innerText = ''
const res = await orbis.createPost(content) const res = await orbis.createPost(content)

View File

@ -5,13 +5,11 @@ import MasterPost from './MasterPost'
import styles from './Posts.module.css' import styles from './Posts.module.css'
export default function Posts({ export default function Posts({
context,
posts, posts,
fetchPosts, fetchPosts,
hasMore, hasMore,
loading loading
}: { }: {
context: string
posts: IOrbisPost[] posts: IOrbisPost[]
fetchPosts: () => Promise<void> fetchPosts: () => Promise<void>
hasMore: boolean hasMore: boolean
@ -20,7 +18,7 @@ export default function Posts({
return ( return (
<div className={styles.posts}> <div className={styles.posts}>
{posts.length > 0 && {posts.length > 0 &&
posts.map((post, index) => <MasterPost key={index} post={post} />)} posts.map((post) => <MasterPost key={post.stream_id} post={post} />)}
{loading ? ( {loading ? (
<div className={styles.loader}> <div className={styles.loader}>

View File

@ -20,7 +20,7 @@ export default function Comment({ context }: { context: string }) {
const fetchPosts = async () => { const fetchPosts = async () => {
setLoading(true) setLoading(true)
const { data, error } = await orbis.getPosts( const { data, error } = await orbis.getPosts(
{ context: _context, algorithm: 'all-context-master-posts' }, { context, algorithm: 'all-context-master-posts' },
page page
) )
if (error) { if (error) {
@ -45,22 +45,8 @@ export default function Comment({ context }: { context: string }) {
}, [context, posts, orbis]) }, [context, posts, orbis])
const callback = (nPost: IOrbisPost) => { const callback = (nPost: IOrbisPost) => {
// console.log(nPost) const _posts = [nPost, ...posts]
if (nPost.stream_id) { setPosts(_posts)
// Search and replace
const _nPost = posts.findIndex((o) => {
return !o.stream_id
})
console.log(_nPost)
if (_nPost > -1) {
const _posts = [...posts]
_posts[_nPost] = nPost
setPosts(_posts)
}
} else {
const _posts = [nPost, ...posts]
setPosts(_posts)
}
} }
return ( return (
@ -72,13 +58,12 @@ export default function Comment({ context }: { context: string }) {
<div className={styles.postBox}> <div className={styles.postBox}>
<Postbox <Postbox
callback={callback} callback={callback}
context={_context} context={context}
placeholder="Share your comment here..." placeholder="Share your comment here..."
/> />
</div> </div>
<div className={`${styles.content} comment-scrollable`}> <div className={`${styles.content} comment-scrollable`}>
<Posts <Posts
context={_context}
posts={posts} posts={posts}
loading={loading} loading={loading}
fetchPosts={fetchPosts} fetchPosts={fetchPosts}

View File

@ -42,7 +42,6 @@ export default function DmConversation() {
} }
if (data) { if (data) {
console.log(data.length)
data.reverse() data.reverse()
if (!polling) { if (!polling) {
setHasMore(data.length >= 50) setHasMore(data.length >= 50)
@ -69,7 +68,11 @@ export default function DmConversation() {
!isLoading ? 15000 : false !isLoading ? 15000 : false
) )
const showTime = (index: number): boolean => { const showTime = (streamId: string): boolean => {
const index = messages.findIndex((o) => o.stream_id === streamId)
if (index < -1) return true
const nextMessage = messages[index + 1] const nextMessage = messages[index + 1]
if (!nextMessage || messages[index].creator !== nextMessage.creator) if (!nextMessage || messages[index].creator !== nextMessage.creator)
return true return true
@ -146,9 +149,9 @@ export default function DmConversation() {
{isLoading && <div className={styles.loading}>Loading...</div>} {isLoading && <div className={styles.loading}>Loading...</div>}
<div className={styles.messages}> <div className={styles.messages}>
<div ref={messagesWrapper} className={styles.scrollContent}> <div ref={messagesWrapper} className={styles.scrollContent}>
{messages.map((message, index) => ( {messages.map((message) => (
<div <div
key={index} key={message.stream_id}
className={`${styles.message} ${ className={`${styles.message} ${
message.stream_id.startsWith('new_post--') message.stream_id.startsWith('new_post--')
? styles.pulse ? styles.pulse
@ -157,7 +160,7 @@ export default function DmConversation() {
account?.did === message.creator_details.did account?.did === message.creator_details.did
? styles.right ? styles.right
: styles.left : styles.left
} ${showTime(index) && styles.showTime}`} } ${showTime(message.stream_id) && styles.showTime}`}
> >
<div className={styles.chatBubble}> <div className={styles.chatBubble}>
<DecryptedMessage content={message.content} /> <DecryptedMessage content={message.content} />