2023-04-26 02:37:29 +00:00
|
|
|
import { clsx } from 'clsx'
|
|
|
|
import { Button } from '../../_shared/Button'
|
|
|
|
import { Icon } from '../../_shared/Icon'
|
|
|
|
import { useLocalize } from '../../../context/localize'
|
|
|
|
import styles from './Panel.module.scss'
|
|
|
|
import { useEditorContext } from '../../../context/editor'
|
2023-05-03 16:13:48 +00:00
|
|
|
import { useOutsideClickHandler } from '../../../utils/useOutsideClickHandler'
|
|
|
|
import { useEscKeyDownHandler } from '../../../utils/useEscKeyDownHandler'
|
|
|
|
import { getPagePath } from '@nanostores/router'
|
|
|
|
import { router } from '../../../stores/router'
|
2023-04-26 02:37:29 +00:00
|
|
|
|
2023-05-04 04:43:52 +00:00
|
|
|
type Props = {
|
2023-05-08 17:21:06 +00:00
|
|
|
shoutId: number
|
2023-05-03 16:13:48 +00:00
|
|
|
}
|
2023-04-26 02:37:29 +00:00
|
|
|
|
2023-05-04 04:43:52 +00:00
|
|
|
export const Panel = (props: Props) => {
|
2023-04-26 02:37:29 +00:00
|
|
|
const { t } = useLocalize()
|
|
|
|
const {
|
|
|
|
isEditorPanelVisible,
|
|
|
|
wordCounter,
|
2023-05-08 17:21:06 +00:00
|
|
|
actions: { toggleEditorPanel, saveShout, publishShout }
|
2023-04-26 02:37:29 +00:00
|
|
|
} = useEditorContext()
|
|
|
|
|
2023-05-03 16:13:48 +00:00
|
|
|
const containerRef: { current: HTMLElement } = {
|
|
|
|
current: null
|
|
|
|
}
|
|
|
|
|
|
|
|
useOutsideClickHandler({
|
|
|
|
containerRef,
|
|
|
|
predicate: () => isEditorPanelVisible(),
|
|
|
|
handler: () => toggleEditorPanel()
|
|
|
|
})
|
|
|
|
|
|
|
|
useEscKeyDownHandler(() => {
|
|
|
|
if (isEditorPanelVisible()) {
|
|
|
|
toggleEditorPanel()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-05-08 17:21:06 +00:00
|
|
|
const handleSaveLinkClick = () => {
|
|
|
|
saveShout()
|
|
|
|
}
|
|
|
|
|
|
|
|
const handlePublishLinkClick = () => {
|
|
|
|
publishShout()
|
|
|
|
}
|
|
|
|
|
2023-04-26 02:37:29 +00:00
|
|
|
return (
|
2023-05-03 16:13:48 +00:00
|
|
|
<aside
|
|
|
|
ref={(el) => (containerRef.current = el)}
|
|
|
|
class={clsx('col-md-6', styles.Panel, { [styles.hidden]: !isEditorPanelVisible() })}
|
|
|
|
>
|
2023-04-26 02:37:29 +00:00
|
|
|
<div class={styles.actionsHolder}>
|
|
|
|
<Button
|
|
|
|
value={<Icon name="close" />}
|
|
|
|
variant={'inline'}
|
|
|
|
class={styles.close}
|
|
|
|
onClick={() => toggleEditorPanel()}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class={clsx(styles.actionsHolder, styles.scrolled)}>
|
|
|
|
<section>
|
2023-05-03 16:13:48 +00:00
|
|
|
<p>
|
2023-05-08 17:21:06 +00:00
|
|
|
<a href="#" onClick={handlePublishLinkClick}>
|
|
|
|
{t('Publish')}
|
|
|
|
</a>
|
2023-05-03 16:13:48 +00:00
|
|
|
</p>
|
|
|
|
<p>
|
2023-05-08 17:21:06 +00:00
|
|
|
<a href="#" onClick={handleSaveLinkClick}>
|
|
|
|
{t('Save draft')}
|
|
|
|
</a>
|
2023-05-03 16:13:48 +00:00
|
|
|
</p>
|
2023-04-26 02:37:29 +00:00
|
|
|
</section>
|
|
|
|
|
|
|
|
<section>
|
2023-05-03 16:13:48 +00:00
|
|
|
<p>
|
|
|
|
<a class={styles.linkWithIcon}>
|
|
|
|
<Icon name="eye" class={styles.icon} />
|
|
|
|
{t('Preview')}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<a
|
|
|
|
class={styles.linkWithIcon}
|
2023-05-08 17:21:06 +00:00
|
|
|
href={getPagePath(router, 'edit', { shoutId: props.shoutId.toString() })}
|
2023-05-03 16:13:48 +00:00
|
|
|
>
|
|
|
|
<Icon name="pencil-outline" class={styles.icon} />
|
|
|
|
{t('Editing')}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<a class={styles.linkWithIcon}>
|
|
|
|
<Icon name="feed-discussion" class={styles.icon} />
|
|
|
|
{t('FAQ')}
|
|
|
|
</a>
|
|
|
|
</p>
|
2023-04-26 02:37:29 +00:00
|
|
|
</section>
|
|
|
|
|
|
|
|
<section>
|
2023-05-03 16:13:48 +00:00
|
|
|
<p>
|
|
|
|
<a>{t('Invite co-authors')}</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
2023-05-08 17:21:06 +00:00
|
|
|
<a href={getPagePath(router, 'editSettings', { shoutId: props.shoutId.toString() })}>
|
2023-05-03 16:13:48 +00:00
|
|
|
{t('Publication settings')}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<a>{t('Corrections history')}</a>
|
|
|
|
</p>
|
2023-04-26 02:37:29 +00:00
|
|
|
</section>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<p>
|
|
|
|
<a href="/how-to-write-a-good-article">{t('How to write a good article')}</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<a href="#">{t('Hotkeys')}</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<a href="#">{t('Help')}</a>
|
|
|
|
</p>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<div class={styles.stats}>
|
|
|
|
<div>
|
|
|
|
{t('Characters')}: <em>{wordCounter().characters}</em>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{t('Words')}: <em>{wordCounter().words}</em>
|
|
|
|
</div>
|
2023-05-03 16:13:48 +00:00
|
|
|
{/*<div>*/}
|
|
|
|
{/* {t('Last rev.')}: <em>22.03.22 в 18:20</em>*/}
|
|
|
|
{/*</div>*/}
|
2023-04-26 02:37:29 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</aside>
|
|
|
|
)
|
|
|
|
}
|