2023-05-08 17:21:06 +00:00
|
|
|
import { clsx } from 'clsx'
|
|
|
|
import styles from './Draft.module.scss'
|
|
|
|
import type { Shout } from '../../graphql/types.gen'
|
|
|
|
import { Icon } from '../_shared/Icon'
|
|
|
|
import { formatDate } from '../../utils'
|
|
|
|
import formatDateTime from '../../utils/formatDateTime'
|
|
|
|
import { useLocalize } from '../../context/localize'
|
2023-05-09 23:15:26 +00:00
|
|
|
import { getPagePath } from '@nanostores/router'
|
2023-05-08 17:21:06 +00:00
|
|
|
import { router } from '../../stores/router'
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
class?: string
|
|
|
|
shout: Shout
|
|
|
|
onPublish: (shout: Shout) => void
|
|
|
|
onDelete: (shout: Shout) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Draft = (props: Props) => {
|
|
|
|
const { t } = useLocalize()
|
|
|
|
|
2023-05-08 18:01:11 +00:00
|
|
|
const handlePublishLinkClick = (e) => {
|
|
|
|
e.preventDefault()
|
2023-05-08 17:21:06 +00:00
|
|
|
props.onPublish(props.shout)
|
|
|
|
}
|
|
|
|
|
2023-05-08 18:01:11 +00:00
|
|
|
const handleDeleteLinkClick = (e) => {
|
|
|
|
e.preventDefault()
|
2023-05-08 17:21:06 +00:00
|
|
|
props.onDelete(props.shout)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div class={clsx(props.class)}>
|
|
|
|
<div class={styles.created}>
|
2023-05-08 18:01:11 +00:00
|
|
|
<Icon name="pencil-outline" class={styles.icon} /> {formatDate(new Date(props.shout.createdAt))}
|
|
|
|
{formatDateTime(props.shout.createdAt)()}
|
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}>
|
|
|
|
<a href={getPagePath(router, 'edit', { shoutId: props.shout.id.toString() })}>{t('Edit')}</a>
|
|
|
|
<a href="#" onClick={handlePublishLinkClick} class={styles.publishLink}>
|
|
|
|
{t('Publish')}
|
|
|
|
</a>
|
|
|
|
<a href="#" onClick={handleDeleteLinkClick} class={styles.deleteLink}>
|
|
|
|
{t('Delete')}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|