Добавить фильтрацию внутри раскрытого треда

- Кнопка сортировки (↑/↓) — переключает порядок писем в треде (по умолчанию новые сверху)
- Кнопка фильтра непрочитанных — показывает только непрочитанные письма в треде
- Кнопки появляются в строке рядом со счётчиком только при раскрытом треде
- При пустом результате фильтрации показывается подсказка

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
d.a.kolesov 2026-04-02 07:07:07 +07:00
parent 91b36b9dde
commit e17a0f71b7
2 changed files with 124 additions and 8 deletions

View file

@ -31,10 +31,11 @@ const allVisibleSelected = computed(() =>
const threads = computed<Thread[]>(() => buildThreads(messagesStore.filteredMessages))
const expandedThreadIds = ref(new Set<string>())
const threadSortDesc = ref(new Map<string, boolean>()) // true = новые сверху
const threadUnreadOnly = ref(new Set<string>())
function toggleThread(thread: Thread): void {
if (thread.messages.length === 1) {
// Один элемент — открываем напрямую
messagesStore.selectMessage(thread.messages[0].id)
return
}
@ -42,13 +43,33 @@ function toggleThread(thread: Thread): void {
expandedThreadIds.value.delete(thread.id)
} else {
expandedThreadIds.value.add(thread.id)
// Открываем последнее письмо треда
messagesStore.selectMessage(thread.latest.id)
}
// trigger reactivity
expandedThreadIds.value = new Set(expandedThreadIds.value)
}
function toggleThreadSort(threadId: string): void {
const cur = threadSortDesc.value.get(threadId) ?? true
threadSortDesc.value = new Map(threadSortDesc.value.set(threadId, !cur))
}
function toggleThreadUnread(threadId: string): void {
const next = new Set(threadUnreadOnly.value)
if (next.has(threadId)) next.delete(threadId)
else next.add(threadId)
threadUnreadOnly.value = next
}
function getThreadMessages(thread: Thread): import('@shared/types/message').MessageEnvelope[] {
// thread.messages отсортированы buildThreads от старых к новым
let msgs = thread.messages
if (threadUnreadOnly.value.has(thread.id)) {
msgs = msgs.filter(m => !m.flags.seen)
}
const desc = threadSortDesc.value.get(thread.id) ?? true
return desc ? [...msgs].reverse() : [...msgs]
}
// ── Refresh ───────────────────────────────────────────────
async function refresh(): Promise<void> {
if (!accountsStore.activeAccountId || !foldersStore.activeFolderId) return
@ -304,12 +325,22 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis
:thread="thread"
:expanded="expandedThreadIds.has(thread.id)"
:selected="thread.messages.some(m => messagesStore.selectedMessageId === m.id)"
:sort-desc="threadSortDesc.get(thread.id) ?? true"
:unread-only="threadUnreadOnly.has(thread.id)"
@click="toggleThread(thread)"
@toggle-sort="toggleThreadSort(thread.id)"
@toggle-unread="toggleThreadUnread(thread.id)"
/>
<Transition name="thread-expand">
<div v-if="expandedThreadIds.has(thread.id)" class="thread-children">
<div
v-if="threadUnreadOnly.has(thread.id) && getThreadMessages(thread).length === 0"
class="thread-empty-filter"
>
Нет непрочитанных писем
</div>
<MessageListItem
v-for="(msg, i) in thread.messages"
v-for="(msg, i) in getThreadMessages(thread)"
:key="msg.id"
:message="msg"
:selected="messagesStore.selectedMessageId === msg.id"
@ -317,7 +348,7 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis
:select-mode="selectMode"
:swipe-left-action="settingsStore.swipeLeftAction"
:swipe-right-action="settingsStore.swipeRightAction"
:class="['thread-child-item', { 'thread-child-last': i === thread.messages.length - 1 }]"
:class="['thread-child-item', { 'thread-child-last': i === getThreadMessages(thread).length - 1 }]"
@click="messagesStore.selectMessage(msg.id)"
@toggle-select="messagesStore.toggleSelect(msg.id)"
@swipe-action="(action) => handleSwipeAction(action, msg.id)"
@ -827,6 +858,15 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis
box-shadow: none !important;
}
/* Пустое состояние при фильтрации */
.thread-empty-filter {
padding: 10px 14px;
font-size: 11.5px;
color: var(--text-muted);
text-align: center;
border-top: 1px solid rgba(255, 255, 255, 0.04);
}
/* Разделитель между соседними дочерними письмами */
.thread-children :deep(.thread-child-item:not(:first-child) .message-item) {
border-top: 1px solid rgba(255, 255, 255, 0.04);

View file

@ -8,9 +8,15 @@ const props = defineProps<{
thread: Thread
selected: boolean
expanded?: boolean
sortDesc?: boolean // true = новые сверху (default)
unreadOnly?: boolean
}>()
defineEmits<{ click: [] }>()
defineEmits<{
click: []
toggleSort: []
toggleUnread: []
}>()
const isUnread = computed(() => props.thread.unreadCount > 0)
const dateDisplay = computed(() => formatMessageDate(props.thread.latest.date))
@ -57,7 +63,7 @@ const snippet = computed(() => props.thread.latest.snippet || '')
</div>
</div>
<!-- Строка 2: тема + счётчик + шеврон раскрытия -->
<!-- Строка 2: тема + счётчик + фильтры + шеврон -->
<div class="thread-row2">
<span class="thread-subject truncate" :class="{ bold: isUnread }">
{{ normalizedSubject }}
@ -65,6 +71,46 @@ const snippet = computed(() => props.thread.latest.snippet || '')
<span v-if="thread.messages.length > 1" class="thread-count">
{{ thread.messages.length }}
</span>
<!-- Кнопки фильтрации — только когда тред раскрыт -->
<template v-if="expanded">
<!-- Сортировка по дате -->
<button
class="thread-filter-btn"
:title="sortDesc ? 'Новые сверху' : 'Старые сверху'"
@click.stop="$emit('toggleSort')"
>
<svg width="10" height="10" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2.5"
stroke-linecap="round" stroke-linejoin="round">
<template v-if="sortDesc">
<!-- Стрелка вниз (новые сверху) -->
<line x1="12" y1="5" x2="12" y2="19"/>
<polyline points="19 12 12 19 5 12"/>
</template>
<template v-else>
<!-- Стрелка вверх (старые сверху) -->
<line x1="12" y1="19" x2="12" y2="5"/>
<polyline points="5 12 12 5 19 12"/>
</template>
</svg>
</button>
<!-- Только непрочитанные -->
<button
class="thread-filter-btn"
:class="{ active: unreadOnly }"
title="Только непрочитанные"
@click.stop="$emit('toggleUnread')"
>
<svg width="10" height="10" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="4"/>
</svg>
</button>
</template>
<svg
class="thread-chevron"
:class="{ open: expanded }"
@ -265,6 +311,36 @@ const snippet = computed(() => props.thread.latest.snippet || '')
line-height: 1.4;
}
/* Кнопки фильтрации треда */
.thread-filter-btn {
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
border-radius: 4px;
color: var(--text-muted);
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.08);
transition:
background var(--transition-fast),
color var(--transition-fast),
border-color var(--transition-fast);
}
.thread-filter-btn:hover {
background: rgba(255, 255, 255, 0.10);
border-color: rgba(255, 255, 255, 0.16);
color: var(--text-secondary);
}
.thread-filter-btn.active {
color: var(--accent);
background: color-mix(in srgb, var(--accent) 14%, transparent);
border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
.thread-chevron {
flex-shrink: 0;
color: var(--text-muted);