2024-10-02 18:29:32 +00:00
|
|
|
import { A } from '@solidjs/router'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { clsx } from 'clsx'
|
2024-07-04 07:51:15 +00:00
|
|
|
import { useLocalize } from '~/context/localize'
|
2024-06-24 17:50:27 +00:00
|
|
|
import { useSnackbar, useUI } from '~/context/ui'
|
2024-07-04 07:51:15 +00:00
|
|
|
import type { Shout } from '~/graphql/schema/core.gen'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { Icon } from '../_shared/Icon'
|
|
|
|
|
|
|
|
import styles from './Draft.module.scss'
|
2023-05-08 17:21:06 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
shout: Shout
|
|
|
|
onPublish: (shout: Shout) => void
|
|
|
|
onDelete: (shout: Shout) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Draft = (props: Props) => {
|
2023-10-18 10:56:41 +00:00
|
|
|
const { t, formatDate } = useLocalize()
|
2024-06-24 17:50:27 +00:00
|
|
|
const { showConfirm } = useUI()
|
2024-02-04 17:40:15 +00:00
|
|
|
const { showSnackbar } = useSnackbar()
|
2023-05-08 17:21:06 +00:00
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
const handlePublishLinkClick = (e: MouseEvent) => {
|
2023-05-08 18:01:11 +00:00
|
|
|
e.preventDefault()
|
2024-02-05 19:05:49 +00:00
|
|
|
if (props.shout.main_topic) {
|
|
|
|
props.onPublish(props.shout)
|
|
|
|
} else {
|
|
|
|
showSnackbar({ body: t('Please, set the main topic first') })
|
|
|
|
}
|
2023-05-08 17:21:06 +00:00
|
|
|
}
|
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
const handleDeleteLinkClick = async (e: MouseEvent) => {
|
2023-05-08 18:01:11 +00:00
|
|
|
e.preventDefault()
|
2023-07-31 21:24:41 +00:00
|
|
|
|
2023-10-16 15:57:29 +00:00
|
|
|
const isConfirmed = await showConfirm({
|
|
|
|
confirmBody: t('Are you sure you want to delete this draft?'),
|
|
|
|
confirmButtonLabel: t('Delete'),
|
|
|
|
confirmButtonVariant: 'danger',
|
2024-06-26 08:22:05 +00:00
|
|
|
declineButtonVariant: 'primary'
|
2023-10-16 15:57:29 +00:00
|
|
|
})
|
2023-07-31 21:24:41 +00:00
|
|
|
if (isConfirmed) {
|
|
|
|
props.onDelete(props.shout)
|
|
|
|
|
2023-10-16 15:57:29 +00:00
|
|
|
await showSnackbar({ body: t('Draft successfully deleted') })
|
2023-07-31 21:24:41 +00:00
|
|
|
}
|
2023-05-08 17:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2024-10-02 18:29:32 +00:00
|
|
|
<div class={styles.draft}>
|
2023-05-08 17:21:06 +00:00
|
|
|
<div class={styles.created}>
|
2023-10-18 10:56:41 +00:00
|
|
|
<Icon name="pencil-outline" class={styles.icon} />{' '}
|
2023-11-28 13:18:25 +00:00
|
|
|
{formatDate(new Date(props.shout.created_at * 1000), { hour: '2-digit', minute: '2-digit' })}
|
2023-05-08 17:21:06 +00:00
|
|
|
</div>
|
|
|
|
<div class={styles.titleContainer}>
|
|
|
|
<span class={styles.title}>{props.shout.title || t('Unnamed draft')}</span> {props.shout.subtitle}
|
|
|
|
</div>
|
|
|
|
<div class={styles.actions}>
|
2024-06-24 17:50:27 +00:00
|
|
|
<A class={styles.actionItem} href={`edit/${props.shout?.id.toString()}`}>
|
2023-08-04 15:59:36 +00:00
|
|
|
{t('Edit')}
|
2024-06-24 17:50:27 +00:00
|
|
|
</A>
|
2023-08-04 15:59:36 +00:00
|
|
|
<span onClick={handlePublishLinkClick} class={clsx(styles.actionItem, styles.publish)}>
|
|
|
|
{t('Publish')}
|
|
|
|
</span>
|
|
|
|
<span onClick={handleDeleteLinkClick} class={clsx(styles.actionItem, styles.delete)}>
|
2023-05-08 17:21:06 +00:00
|
|
|
{t('Delete')}
|
2023-08-04 15:59:36 +00:00
|
|
|
</span>
|
2023-05-08 17:21:06 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|