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/typographies": "^0.1.0",
"@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",
"@urql/exchange-refocus": "^1.0.0",
"@walletconnect/web3-provider": "^1.8.0",

View File

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

View File

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

View File

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

View File

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