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

updating post comment function

This commit is contained in:
Dollar Bull 2022-10-04 17:01:42 +07:00
parent d363513c69
commit 52b9a006d8
4 changed files with 46 additions and 15 deletions

View File

@ -17,7 +17,7 @@ export default function Posts({ id }: { id: string }) {
const context = process.env.NODE_ENV const context = process.env.NODE_ENV
? 'kjzl6cwe1jw149vvm1f8p9qlohhtkjuc302f22mipq95q7mevdljgx3tv9swujy' ? 'kjzl6cwe1jw149vvm1f8p9qlohhtkjuc302f22mipq95q7mevdljgx3tv9swujy'
: id : id
const { data, error } = await orbis.getPosts({ context }, page) const { data, error } = await orbis.getPosts({ context: id }, page)
if (error) { if (error) {
console.log(error) console.log(error)
} }

View File

@ -12,7 +12,7 @@ export default function Comment({ asset }: { asset: AssetExtended }) {
<span>Public Comment</span> <span>Public Comment</span>
</div> </div>
<div className={styles.postBox}> <div className={styles.postBox}>
<Postbox placeholder="Share your comment here..." /> <Postbox id={asset?.id} placeholder="Share your comment here..." />
</div> </div>
<div className={styles.content}> <div className={styles.content}>
<Posts id={asset?.id} /> <Posts id={asset?.id} />

View File

@ -1,18 +1,41 @@
import React, { useRef } from 'react' import React, { useRef, useState } from 'react'
import Button from '@shared/atoms/Button' import Button from '@shared/atoms/Button'
import styles from './Postbox.module.css' import styles from './Postbox.module.css'
import { useOrbis } from '@context/Orbis'
export default function Postbox({ export default function Postbox({
id,
placeholder = 'Share your post here...' placeholder = 'Share your post here...'
}: { }: {
placeholder: string placeholder: string
id: string
}) { }) {
const postBoxArea = useRef(null) const [post, setPost] = useState()
const postBoxArea = useRef(null)
const { orbis } = useOrbis()
function handleInput(e) {
setPost(e.currentTarget.innerText)
const _keyCode = e.nativeEvent.data
/** Manage custom actions for some keycodes */
}
const createPost = async () => {
console.log('clicked')
const res = await orbis.createPost({ body: post, context: id })
if (res.status === 200) {
console.log('success with,', res)
setPost(null)
if (postBoxArea.current) {
postBoxArea.current.textContent = ''
postBoxArea.current.focus()
}
}
}
// const handleInput = (e: Event): FormEvent<HTMLDivElement> => {
// e.preventDefault()
// console.log(e)
// }
return ( return (
<> <>
<div className={styles.postbox}> <div className={styles.postbox}>
@ -22,9 +45,16 @@ export default function Postbox({
className={styles.editable} className={styles.editable}
contentEditable={true} contentEditable={true}
data-placeholder={placeholder} data-placeholder={placeholder}
onInput={(e) => handleInput(e)}
></div> ></div>
<div className={styles.sendButtonWrap}> <div className={styles.sendButtonWrap}>
<Button style="primary" type="submit" size="small" disabled={false}> <Button
style="primary"
type="submit"
size="small"
disabled={false}
onClick={createPost}
>
Send Send
</Button> </Button>
</div> </div>

View File

@ -50,12 +50,13 @@ export default function AccountHeader({
} }
const createConversation = async () => { const createConversation = async () => {
const res = await orbis.createConversation({ // const res = await orbis.createConversation({
recipients: [userDid] // recipients: [userDid]
}) // })
if (res.status === 200) { // if (res.status === 200) {
console.log(res) // console.log(res)
} // }
console.log('clicked')
} }
useEffect(() => { useEffect(() => {