aero-mail/src/renderer/src/components/sidebar/FolderTreeItem.vue
d.a.kolesov 137426ed1c
All checks were successful
Release / release (push) Successful in 3m18s
recursive mark as read
2026-11-11 13:14:58 +07:00

456 lines
14 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup lang="ts">
import { ref, computed } from 'vue'
import type { Folder } from '@shared/types/folder'
import { SpecialFolderRole } from '@shared/types/folder'
import { useFoldersStore } from '../../stores/folders.store'
import { useAccountsStore } from '../../stores/accounts.store'
import { useNotificationsStore } from '../../stores/notifications.store'
import { useMessagesStore } from '../../stores/messages.store'
import { useRetentionStore } from '../../stores/retention.store'
import AppIcon from '../AppIcon.vue'
import type { IconName } from '../AppIcon.vue'
import FolderContextMenu from './FolderContextMenu.vue'
import RetentionLimitDialog from './RetentionLimitDialog.vue'
const props = defineProps<{
folder: Folder
depth: number
}>()
const foldersStore = useFoldersStore()
const accountsStore = useAccountsStore()
const notificationsStore = useNotificationsStore()
const messagesStore = useMessagesStore()
const retentionStore = useRetentionStore()
const contextMenu = ref<{ x: number; y: number } | null>(null)
const showRetentionDialog = ref(false)
const expanded = computed(() => foldersStore.isExpanded(props.folder.id))
const isActive = computed(() => foldersStore.activeFolderId === props.folder.id)
const isSelected = computed(() => foldersStore.selectedFolderIds.has(props.folder.id))
// Мультивыбор: меню работает по всем выделенным папкам, если кликнутая среди них
const isMultiSelect = computed(() => isSelected.value && foldersStore.selectedFolderIds.size > 1)
const selectionCount = computed(() => (isMultiSelect.value ? foldersStore.selectedFolderIds.size : 1))
const menuHasChildren = computed(() => {
if (!isMultiSelect.value) return hasChildren.value
return foldersStore.collectFolderIds(foldersStore.selectedFolderIds, true).length >
foldersStore.collectFolderIds(foldersStore.selectedFolderIds, false).length
})
const hasChildren = computed(() => props.folder.children.length > 0)
const unreadCount = computed(() => {
if (!accountsStore.activeAccountId) return 0
return foldersStore.getFolderUnread(accountsStore.activeAccountId, props.folder.id)
})
const isMuted = computed(() => {
if (!accountsStore.activeAccountId) return false
return notificationsStore.isMuted(accountsStore.activeAccountId, props.folder.id)
})
const ownRetentionRule = computed(() => {
if (!accountsStore.activeAccountId) return null
return retentionStore.getOwnRule(accountsStore.activeAccountId, props.folder.id)
})
const folderIcon = computed((): IconName => {
switch (props.folder.role) {
case SpecialFolderRole.Inbox: return 'inbox'
case SpecialFolderRole.Sent: return 'sent'
case SpecialFolderRole.Drafts: return 'drafts'
case SpecialFolderRole.Trash: return 'trash'
case SpecialFolderRole.Spam: return 'spam'
case SpecialFolderRole.Archive: return 'archive'
default: return 'folder'
}
})
function handleClick(event: MouseEvent): void {
foldersStore.selectFolder(props.folder.id, {
shift: event.shiftKey,
ctrl: event.ctrlKey || event.metaKey
})
}
function toggleExpand(event: Event): void {
event.stopPropagation()
foldersStore.toggleExpanded(props.folder.id)
}
function handleContextMenu(event: MouseEvent): void {
event.preventDefault()
// ПКМ вне выделения сбрасывает его: меню относится к кликнутой папке
if (!isSelected.value) foldersStore.clearSelection()
contextMenu.value = { x: event.clientX, y: event.clientY }
}
function closeContextMenu(): void {
contextMenu.value = null
}
function handleMute(durationMs: number | null): void {
if (accountsStore.activeAccountId) {
notificationsStore.muteFolder(accountsStore.activeAccountId, props.folder.id, durationMs)
}
contextMenu.value = null
}
function handleUnmute(): void {
if (accountsStore.activeAccountId) {
notificationsStore.unmuteFolder(accountsStore.activeAccountId, props.folder.id)
}
contextMenu.value = null
}
function handleMarkAllRead(recursive: boolean): void {
if (accountsStore.activeAccountId) {
const sourceIds = isMultiSelect.value ? [...foldersStore.selectedFolderIds] : [props.folder.id]
const folderIds = foldersStore.collectFolderIds(sourceIds, recursive)
messagesStore.markAllRead(accountsStore.activeAccountId, folderIds)
}
contextMenu.value = null
}
function handleEditRetention(): void {
contextMenu.value = null
showRetentionDialog.value = true
}
function handleRemoveRetention(): void {
if (accountsStore.activeAccountId) {
retentionStore.removeRule(accountsStore.activeAccountId, props.folder.id)
}
contextMenu.value = null
}
function handleSaveRetention(maxMessages: number, recursive: boolean): void {
if (accountsStore.activeAccountId) {
retentionStore.setRule(accountsStore.activeAccountId, props.folder.id, maxMessages, recursive)
}
showRetentionDialog.value = false
}
</script>
<template>
<div class="folder-item-wrapper">
<button
class="folder-item"
:class="{ active: isActive, selected: isSelected }"
:style="{ paddingLeft: (depth * 16 + 8) + 'px' }"
@click="handleClick"
@contextmenu.prevent="handleContextMenu"
>
<button
v-if="hasChildren"
class="expand-btn"
:class="{ rotated: expanded }"
@click="toggleExpand"
>
<AppIcon name="chevron-right" :size="12" />
</button>
<span v-else class="expand-spacer" />
<AppIcon :name="folderIcon" :size="14" class="folder-icon" />
<span class="folder-name truncate">{{ folder.name }}</span>
<AppIcon v-if="isMuted" name="bell-off" :size="11" class="muted-icon" />
<span v-if="unreadCount > 0" class="unread-badge" :class="{ muted: isMuted }">
{{ unreadCount }}
</span>
</button>
<FolderContextMenu
v-if="contextMenu && accountsStore.activeAccountId"
:x="contextMenu.x"
:y="contextMenu.y"
:account-id="accountsStore.activeAccountId"
:folder-id="folder.id"
:folder-name="folder.name"
:is-muted="isMuted"
:has-retention-rule="!!ownRetentionRule"
:has-children="menuHasChildren"
:selection-count="selectionCount"
@close="closeContextMenu"
@mute="handleMute"
@unmute="handleUnmute"
@mark-all-read="handleMarkAllRead"
@edit-retention="handleEditRetention"
@remove-retention="handleRemoveRetention"
/>
<RetentionLimitDialog
v-if="showRetentionDialog"
:folder-name="folder.name"
:initial-rule="ownRetentionRule"
@close="showRetentionDialog = false"
@save="handleSaveRetention"
/>
<div v-if="hasChildren && expanded" class="folder-children">
<FolderTreeItem
v-for="child in folder.children"
:key="child.id"
:folder="child"
:depth="depth + 1"
/>
</div>
</div>
</template>
<style scoped>
.folder-item {
display: flex;
align-items: center;
width: calc(100% - 12px);
padding: 6px 8px;
gap: 6px;
border-radius: 8px;
margin: 1px 6px;
border: 1px solid transparent;
background: transparent;
position: relative;
text-align: left;
transition:
background var(--transition-fast),
border-color var(--transition-fast),
box-shadow var(--transition-fast);
}
.folder-item:hover {
background: rgba(255, 255, 255, 0.07);
border-color: rgba(255, 255, 255, 0.10);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.08),
0 2px 8px rgba(0, 0, 0, 0.20);
}
/* ── Мультивыбор (Shift/Ctrl+клик) ───────────────────────── */
.folder-item.selected {
background: rgba(255, 255, 255, 0.10);
border-color: rgba(255, 255, 255, 0.22);
user-select: none;
}
/* ── Активное состояние: liquid glass ────────────────────── */
.folder-item.active {
background: linear-gradient(
145deg,
rgba(255, 255, 255, 0.12) 0%,
rgba(255, 255, 255, 0.06) 100%
);
backdrop-filter: blur(14px) saturate(200%) brightness(1.08);
-webkit-backdrop-filter: blur(14px) saturate(200%) brightness(1.08);
border-color: rgba(255, 255, 255, 0.20);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.50),
0 4px 20px rgba(0, 0, 0, 0.30);
}
/* ── Иконка папки ────────────────────────────────────────── */
.folder-icon {
flex-shrink: 0;
color: var(--text-muted);
transition: color var(--transition-fast);
}
.folder-item:hover .folder-icon {
color: var(--text-secondary);
}
.folder-item.active .folder-icon {
color: rgba(255, 255, 255, 0.75);
}
/* ── Название папки ──────────────────────────────────────── */
.folder-name {
flex: 1;
font-size: 13px;
min-width: 0;
color: var(--text-secondary);
transition: color var(--transition-fast);
}
.folder-item:hover .folder-name {
color: var(--text-primary);
}
.folder-item.active .folder-name {
color: rgba(255, 255, 255, 0.92);
font-weight: 500;
}
/* ── Кнопка разворачивания ───────────────────────────────── */
.expand-btn {
width: 16px;
height: 16px;
display: flex;
align-items: center;
justify-content: center;
color: var(--text-muted);
flex-shrink: 0;
transition: transform var(--transition-fast);
}
.expand-btn.rotated {
transform: rotate(90deg);
}
.expand-spacer {
width: 16px;
flex-shrink: 0;
}
/* ── Бейдж непрочитанных ─────────────────────────────────── */
.unread-badge {
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 10px;
font-weight: 700;
color: rgba(255, 255, 255, 0.92);
padding: 0 6px;
min-height: 18px;
line-height: 1;
border-radius: var(--radius-full);
background: rgba(200, 40, 40, 0.55);
border: 1px solid rgba(255, 100, 100, 0.25);
box-shadow:
inset 0 1px 0 rgba(255, 160, 160, 0.2),
0 2px 6px rgba(180, 30, 30, 0.3);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
flex-shrink: 0;
min-width: 18px;
text-align: center;
transition: background var(--transition-fast);
}
.folder-item:hover .unread-badge {
background: rgba(210, 45, 45, 0.70);
}
.folder-item.active .unread-badge {
background: rgba(200, 40, 40, 0.65);
border-color: rgba(255, 100, 100, 0.35);
}
/* ── Muted badge: gray instead of red ───────────────────── */
.unread-badge.muted {
background: rgba(255, 255, 255, 0.10);
border-color: rgba(255, 255, 255, 0.08);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.06),
0 1px 4px rgba(0, 0, 0, 0.12);
color: var(--text-muted);
}
.folder-item:hover .unread-badge.muted {
background: rgba(255, 255, 255, 0.14);
}
.folder-item.active .unread-badge.muted {
background: rgba(255, 255, 255, 0.12);
border-color: rgba(255, 255, 255, 0.10);
}
/* ── Muted icon ──────────────────────────────────────────── */
.muted-icon {
flex-shrink: 0;
color: var(--text-muted);
opacity: 0.65;
}
/* ── Material 3 (Navigation Drawer list item) ── */
html[data-design='material3'] .folder-item {
border-radius: var(--md-sys-shape-corner-full);
/* Полная пилюля круче скругляется у краёв, чем прежний shape/medium —
без доп. отступа справа бейдж непрочитанных вылезает за скруглённый край */
padding-right: 12px;
}
html[data-design='material3'] .folder-item:hover {
background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
border-color: transparent;
box-shadow: none;
}
html[data-design='material3'] .folder-item.selected {
background: var(--md-sys-color-secondary-container);
border-color: transparent;
}
html[data-design='material3'] .folder-item.active {
background: var(--md-sys-color-secondary-container);
backdrop-filter: none;
border-color: transparent;
box-shadow: none;
}
html[data-design='material3'] .folder-item.active:hover {
background: color-mix(in srgb, var(--md-sys-color-on-secondary-container) 8%, var(--md-sys-color-secondary-container));
}
html[data-design='material3'] .folder-icon {
color: var(--md-sys-color-on-surface-variant);
}
html[data-design='material3'] .folder-item:hover .folder-icon {
color: var(--md-sys-color-on-surface);
}
html[data-design='material3'] .folder-item.active .folder-icon {
color: var(--md-sys-color-on-secondary-container);
}
html[data-design='material3'] .folder-name {
font-size: var(--md-sys-typescale-label-large-size);
line-height: var(--md-sys-typescale-label-large-line);
color: var(--md-sys-color-on-surface-variant);
}
html[data-design='material3'] .folder-item:hover .folder-name {
color: var(--md-sys-color-on-surface);
}
html[data-design='material3'] .folder-item.active .folder-name {
color: var(--md-sys-color-on-secondary-container);
font-weight: var(--md-sys-typescale-label-large-weight);
}
html[data-design='material3'] .unread-badge {
color: var(--md-sys-color-on-error);
background: var(--md-sys-color-error);
border: none;
box-shadow: none;
backdrop-filter: none;
font-size: var(--md-sys-typescale-label-small-size);
line-height: var(--md-sys-typescale-label-small-line);
font-weight: var(--md-sys-typescale-label-small-weight);
}
html[data-design='material3'] .folder-item:hover .unread-badge {
background: var(--md-sys-color-error);
}
html[data-design='material3'] .folder-item.active .unread-badge {
background: var(--md-sys-color-error);
border: none;
}
html[data-design='material3'] .unread-badge.muted {
background: var(--md-sys-color-surface-container-highest);
border: none;
box-shadow: none;
color: var(--md-sys-color-on-surface-variant);
}
html[data-design='material3'] .folder-item:hover .unread-badge.muted {
background: var(--md-sys-color-surface-container-highest);
}
html[data-design='material3'] .folder-item.active .unread-badge.muted {
background: var(--md-sys-color-surface-container-highest);
border: none;
}
html[data-design='material3'] .muted-icon {
color: var(--md-sys-color-on-surface-variant);
opacity: 0.8;
}
</style>