Pass selected action to message component

This commit is contained in:
ilya-bkv 2022-12-14 10:07:01 +03:00
parent fe91ec7b00
commit 1badb74f6f
5 changed files with 32 additions and 10 deletions

View File

@ -52,7 +52,7 @@ $actionsWidth: 32px * 2;
&:hover {
.actions {
z-index: 1;
z-index: 100;
opacity: 1;
right: -$actionsWidth;
}

View File

@ -27,6 +27,7 @@ const Message = (props: Props) => {
const isOwn = props.ownId === Number(props.content.author)
const user = props.members?.find((m) => m.id === Number(props.content.author))
const [isPopupVisible, setIsPopupVisible] = createSignal<boolean>(false)
const [selectedAction, setSelectedAction] = createSignal<string>()
const handleMouseLeave = () => {
if (isPopupVisible()) setIsPopupVisible(false)
@ -48,6 +49,7 @@ const Message = (props: Props) => {
</div>
<MessageActionsPopup
forceHide={!isPopupVisible()}
actionSelect={(selectedAction) => setSelectedAction(selectedAction)}
onVisibilityChange={(isVisible) => setIsPopupVisible(isVisible)}
trigger={<Icon name="menu" />}
/>

View File

@ -1,18 +1,32 @@
import { createEffect, createSignal, For } from 'solid-js'
import type { PopupProps } from '../_shared/Popup'
import { Popup } from '../_shared/Popup'
import { t } from '../../utils/intl'
type MessageActionsPopup = Omit<PopupProps, 'children'>
type MessageActionsPopup = {
actionSelect?: (selectedAction) => void
} & Omit<PopupProps, 'children'>
const actions = [
{ name: t('Reply'), action: 'reply' },
{ name: t('Copy'), action: 'copy' },
{ name: t('Pin'), action: 'pin' },
{ name: t('Forward'), action: 'forward' },
{ name: t('Select'), action: 'select' },
{ name: t('Delete'), action: 'delete' }
]
export const MessageActionsPopup = (props: MessageActionsPopup) => {
const [selectedAction, setSelectedAction] = createSignal<string>()
createEffect(() => {
if (props.actionSelect) props.actionSelect(selectedAction())
})
return (
<Popup {...props} variant="tiny">
<ul class="nodash">
<li>Ответить</li>
<li>Скопировать</li>
<li>Закрепить</li>
<li>Переслать</li>
<li>Выбрать</li>
<li style={{ color: 'red' }}>Удалить</li>
<For each={actions}>
{(item) => <li onClick={() => setSelectedAction(item.action)}>{item.name}</li>}
</For>
</ul>
</Popup>
)

View File

@ -8,7 +8,7 @@
opacity: 1;
color: #000;
position: absolute;
z-index: 10;
z-index: 100;
min-width: 144px;
ul {

View File

@ -205,5 +205,11 @@
"Date of Birth": "Дата рождения",
"Social networks": "Социальные сети",
"Save settings": "Сохранить настройки",
"Write message": "Написать сообщение"
"Write message": "Написать сообщение",
"Reply": "Ответить",
"Copy": "Скопировать",
"Pin": "Закрепить",
"Forward": "Переслать",
"Select": "Выбрать",
"Delete": "Удалить"
}