stacker.news/components/comment-edit.js
SatsAllDay 852d2cf304
@remindme bot support (#1159)
* @remindme bot support

support reminders via @remindme bot, just like @delete bot

* minor cleanup

* minor query cleanup

* add db migration

* various fixes and updates:

* hasNewNotes implementation
* actually return notification component in ui
* delete reminder and job on item delete
* other goodies

* refactor to use prisma for deleting existing reminder

* * switch to deleteMany to delete existing Reminders upon edit/delete of post to satisfy prisma

* update wording in form toast for remindme bot usage

* update wording in the push notification sent

* transactional reminder inserts and expirein

* set expirein on @delete too

---------

Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2024-05-19 15:52:02 -05:00

65 lines
1.8 KiB
JavaScript

import { Form, MarkdownInput } from '@/components/form'
import { gql, useMutation } from '@apollo/client'
import styles from './reply.module.css'
import { commentSchema } from '@/lib/validate'
import { useToast } from './toast'
import { toastUpsertSuccessMessages } from '@/lib/form'
import { FeeButtonProvider } from './fee-button'
import { ItemButtonBar } from './post'
export default function CommentEdit ({ comment, editThreshold, onSuccess, onCancel }) {
const toaster = useToast()
const [upsertComment] = useMutation(
gql`
mutation upsertComment($id: ID! $text: String!) {
upsertComment(id: $id, text: $text) {
text
deleteScheduledAt
reminderScheduledAt
}
}`, {
update (cache, { data: { upsertComment } }) {
cache.modify({
id: `Item:${comment.id}`,
fields: {
text () {
return upsertComment.text
}
}
})
}
}
)
return (
<div className={`${styles.reply} mt-2`}>
<FeeButtonProvider>
<Form
initial={{
text: comment.text
}}
schema={commentSchema}
onSubmit={async (values, { resetForm }) => {
const { data, error } = await upsertComment({ variables: { ...values, id: comment.id } })
if (error) {
throw new Error({ message: error.toString() })
}
toastUpsertSuccessMessages(toaster, data, 'upsertComment', true, values.text)
if (onSuccess) {
onSuccess()
}
}}
>
<MarkdownInput
name='text'
minRows={6}
autoFocus
required
/>
<ItemButtonBar itemId={comment.id} onDelete={onSuccess} hasCancel={false} />
</Form>
</FeeButtonProvider>
</div>
)
}