Add optional text input for link posts (#558)

* add link comment functionality

* handle anon case

* revise info text

* simplify by using item.text

* remove hint

* cleanup

---------

Co-authored-by: rleed <rleed1@pm.me>
This commit is contained in:
rleed 2023-10-22 12:55:50 -03:00 committed by GitHub
parent d1db762ecb
commit 92c5303d81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 8 deletions

View File

@ -26,7 +26,7 @@ export default gql`
bookmarkItem(id: ID): Item
subscribeItem(id: ID): Item
deleteItem(id: ID): Item
upsertLink(id: ID, sub: String, title: String!, url: String!, boost: Int, forward: [ItemForwardInput], hash: String, hmac: String): Item!
upsertLink(id: ID, sub: String, title: String!, url: String!, text: String, boost: Int, forward: [ItemForwardInput], hash: String, hmac: String): Item!
upsertDiscussion(id: ID, sub: String, title: String!, text: String, boost: Int, forward: [ItemForwardInput], hash: String, hmac: String): Item!
upsertBounty(id: ID, sub: String, title: String!, text: String, bounty: Int, hash: String, hmac: String, boost: Int, forward: [ItemForwardInput]): Item!
upsertJob(id: ID, sub: String!, title: String!, company: String!, location: String, remote: Boolean,

View File

@ -1,5 +1,5 @@
import AccordianItem from './accordian-item'
import { Input, InputUserSuggest, VariableInput, Checkbox } from './form'
import { MarkdownInput, Input, InputUserSuggest, VariableInput, Checkbox } from './form'
import InputGroup from 'react-bootstrap/InputGroup'
import { BOOST_MIN, BOOST_MULT, MAX_FORWARDS } from '../lib/constants'
import { DEFAULT_CROSSPOSTING_RELAYS } from '../lib/nostr'
@ -11,14 +11,15 @@ import { useRouter } from 'next/router'
const EMPTY_FORWARD = { nym: '', pct: '' }
export function AdvPostInitial ({ forward, boost }) {
export function AdvPostInitial ({ text, forward, boost }) {
return {
text: text || '',
boost: boost || '',
forward: forward?.length ? forward : [EMPTY_FORWARD]
}
}
export default function AdvPostForm () {
export default function AdvPostForm ({ isLink }) {
const me = useMe()
const router = useRouter()
@ -27,6 +28,24 @@ export default function AdvPostForm () {
header={<div style={{ fontWeight: 'bold', fontSize: '92%' }}>options</div>}
body={
<>
{isLink &&
<MarkdownInput
label={
<div className='d-flex align-items-center'>text
<Info>
<span className='fw-bold'>You can use this text to ...</span>
<ul>
<li>provide context</li>
<li>summarize the link</li>
<li>spur great conversation!</li>
<li>or for anything else that comes to your mind</li>
</ul>
</Info>
</div>
}
name='text'
minRows={6}
/>}
<Input
label={
<div className='d-flex align-items-center'>boost

View File

@ -70,8 +70,8 @@ export function LinkForm ({ item, sub, editThreshold, children }) {
const [upsertLink] = useMutation(
gql`
mutation upsertLink($sub: String, $id: ID, $title: String!, $url: String!, $boost: Int, $forward: [ItemForwardInput], $hash: String, $hmac: String) {
upsertLink(sub: $sub, id: $id, title: $title, url: $url, boost: $boost, forward: $forward, hash: $hash, hmac: $hmac) {
mutation upsertLink($sub: String, $id: ID, $title: String!, $url: String!, $text: String, $boost: Int, $forward: [ItemForwardInput], $hash: String, $hmac: String) {
upsertLink(sub: $sub, id: $id, title: $title, url: $url, text: $text, boost: $boost, forward: $forward, hash: $hash, hmac: $hmac) {
id
}
}`
@ -123,7 +123,7 @@ export function LinkForm ({ item, sub, editThreshold, children }) {
initial={{
title: item?.title || shareTitle || '',
url: item?.url || shareUrl || '',
...AdvPostInitial({ forward: normalizeForwards(item?.forwards), boost: item?.boost }),
...AdvPostInitial({ text: item?.text, forward: normalizeForwards(item?.forwards), boost: item?.boost }),
...SubSelectInitial({ sub: item?.subName || sub?.name })
}}
schema={schema}
@ -185,7 +185,7 @@ export function LinkForm ({ item, sub, editThreshold, children }) {
}
}}
/>
<AdvPostForm edit={!!item} />
<AdvPostForm edit={!!item} isLink />
<div className='mt-3'>
{item
? (