webapp/src/components/Inbox/MessageActionsPopup.tsx

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-12-17 03:27:00 +00:00
import type { PopupProps } from '../_shared/Popup'
2024-02-04 11:25:21 +00:00
import { For, createEffect, createSignal } from 'solid-js'
import { useLocalize } from '~/context/localize'
import { Popup } from '../_shared/Popup'
2022-12-17 03:27:00 +00:00
export type MessageActionType = 'reply' | 'copy' | 'pin' | 'forward' | 'select' | 'delete'
2023-05-01 18:32:32 +00:00
type MessageActionsPopupProps = {
2024-06-24 17:50:27 +00:00
actionSelect?: (selectedAction: MessageActionType) => void
2022-12-17 03:27:00 +00:00
} & Omit<PopupProps, 'children'>
2023-05-01 18:32:32 +00:00
export const MessageActionsPopup = (props: MessageActionsPopupProps) => {
2022-12-17 03:27:00 +00:00
const [selectedAction, setSelectedAction] = createSignal<MessageActionType | null>(null)
2023-02-17 09:21:02 +00:00
const { t } = useLocalize()
const actions: { name: string; action: MessageActionType }[] = [
{ 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' },
2024-06-26 08:22:05 +00:00
{ name: t('Delete'), action: 'delete' }
2023-02-17 09:21:02 +00:00
]
2022-12-17 03:27:00 +00:00
createEffect(() => {
2024-06-24 17:50:27 +00:00
if (props.actionSelect) props.actionSelect(selectedAction() || 'select')
2022-12-17 03:27:00 +00:00
})
return (
<Popup {...props} variant="tiny">
<ul class="nodash">
<For each={actions}>
{(item) => (
<li
2024-06-24 17:50:27 +00:00
style={{ color: item.action === 'delete' ? 'red' : undefined }}
2022-12-17 03:27:00 +00:00
onClick={() => setSelectedAction(item.action)}
>
{item.name}
</li>
)}
</For>
</ul>
</Popup>
)
}