Добавить pull-to-refresh, авто-проверку и предзагрузку писем
- Pull-to-refresh: прокрутка вверх до упора запускает обновление (индикатор с прогресс-анимацией, glass-стиль) - Авто-проверка: настройка интервала (выкл/1/5/10/30 мин) в SettingsView, таймер в MessageList сбрасывается при смене настройки - Предзагрузка: после загрузки папки тела первых 10 писем кэшируются в фоне через 600 мс, без пометки прочитанными Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
44c402da70
commit
cbf80e1fc5
4 changed files with 156 additions and 14 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
||||||
import { useMessagesStore } from '../../stores/messages.store'
|
import { useMessagesStore } from '../../stores/messages.store'
|
||||||
import { useFoldersStore } from '../../stores/folders.store'
|
import { useFoldersStore } from '../../stores/folders.store'
|
||||||
import { useAccountsStore } from '../../stores/accounts.store'
|
import { useAccountsStore } from '../../stores/accounts.store'
|
||||||
|
|
@ -21,11 +21,66 @@ const allVisibleSelected = computed(() =>
|
||||||
messagesStore.filteredMessages.every((m) => messagesStore.selectedIds.has(m.id))
|
messagesStore.filteredMessages.every((m) => messagesStore.selectedIds.has(m.id))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ── Refresh ───────────────────────────────────────────────
|
||||||
async function refresh(): Promise<void> {
|
async function refresh(): Promise<void> {
|
||||||
if (!accountsStore.activeAccountId || !foldersStore.activeFolderId) return
|
if (!accountsStore.activeAccountId || !foldersStore.activeFolderId) return
|
||||||
await messagesStore.loadMessages(accountsStore.activeAccountId, foldersStore.activeFolderId, 0)
|
await messagesStore.loadMessages(accountsStore.activeAccountId, foldersStore.activeFolderId, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Auto-check timer ──────────────────────────────────────
|
||||||
|
let autoCheckTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
|
function restartAutoCheck(): void {
|
||||||
|
if (autoCheckTimer) { clearInterval(autoCheckTimer); autoCheckTimer = null }
|
||||||
|
if (settingsStore.autoCheckInterval > 0) {
|
||||||
|
autoCheckTimer = setInterval(refresh, settingsStore.autoCheckInterval * 60_000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(() => settingsStore.autoCheckInterval, restartAutoCheck)
|
||||||
|
onMounted(restartAutoCheck)
|
||||||
|
onUnmounted(() => { if (autoCheckTimer) clearInterval(autoCheckTimer) })
|
||||||
|
|
||||||
|
// ── Pull-to-refresh ───────────────────────────────────────
|
||||||
|
const PULL_THRESHOLD = 64
|
||||||
|
const pullY = ref(0)
|
||||||
|
const pullRefreshing = ref(false)
|
||||||
|
const indicatorProgress = computed(() =>
|
||||||
|
pullRefreshing.value ? 1 : Math.min(1, pullY.value / PULL_THRESHOLD)
|
||||||
|
)
|
||||||
|
|
||||||
|
let pullDecayTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
|
||||||
|
function onWheel(event: WheelEvent): void {
|
||||||
|
const el = event.currentTarget as HTMLElement
|
||||||
|
if (el.scrollTop > 2) {
|
||||||
|
if (pullY.value > 0) pullY.value = 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (event.deltaY < 0 && !pullRefreshing.value && !messagesStore.loading) {
|
||||||
|
if (pullDecayTimer) { clearTimeout(pullDecayTimer); pullDecayTimer = null }
|
||||||
|
pullY.value = Math.min(PULL_THRESHOLD, pullY.value + Math.abs(event.deltaY) * 0.45)
|
||||||
|
if (pullY.value >= PULL_THRESHOLD) triggerPullRefresh()
|
||||||
|
} else if (event.deltaY > 0 && pullY.value > 0) {
|
||||||
|
schedulePullDecay()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function schedulePullDecay(): void {
|
||||||
|
if (pullDecayTimer) clearTimeout(pullDecayTimer)
|
||||||
|
pullDecayTimer = setTimeout(() => { pullY.value = 0 }, 180)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function triggerPullRefresh(): Promise<void> {
|
||||||
|
if (pullRefreshing.value) return
|
||||||
|
pullRefreshing.value = true
|
||||||
|
pullY.value = PULL_THRESHOLD
|
||||||
|
await refresh()
|
||||||
|
pullRefreshing.value = false
|
||||||
|
pullY.value = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Scroll (infinite load) ────────────────────────────────
|
||||||
function onScroll(event: Event): void {
|
function onScroll(event: Event): void {
|
||||||
const el = event.target as HTMLElement
|
const el = event.target as HTMLElement
|
||||||
if (el.scrollHeight - el.scrollTop - el.clientHeight < 200) {
|
if (el.scrollHeight - el.scrollTop - el.clientHeight < 200) {
|
||||||
|
|
@ -120,6 +175,17 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis
|
||||||
<button class="bulk-cancel" @click="exitSelectMode">Отмена</button>
|
<button class="bulk-cancel" @click="exitSelectMode">Отмена</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Pull-to-refresh индикатор (всегда в DOM, высота = 0 в обычном состоянии) -->
|
||||||
|
<div
|
||||||
|
class="pull-indicator-wrap"
|
||||||
|
:style="{ '--progress': indicatorProgress }"
|
||||||
|
>
|
||||||
|
<div class="pull-indicator" :class="{ refreshing: pullRefreshing }">
|
||||||
|
<AppIcon name="refresh" :size="13" :class="{ spinning: pullRefreshing }" />
|
||||||
|
<span>{{ pullRefreshing ? 'Обновление...' : indicatorProgress >= 1 ? 'Отпустите для обновления' : 'Потяните для обновления' }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Загрузка -->
|
<!-- Загрузка -->
|
||||||
<div
|
<div
|
||||||
v-if="messagesStore.loading && messagesStore.messages.length === 0"
|
v-if="messagesStore.loading && messagesStore.messages.length === 0"
|
||||||
|
|
@ -140,7 +206,7 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Список писем -->
|
<!-- Список писем -->
|
||||||
<div v-else class="message-list" @scroll="onScroll">
|
<div v-else class="message-list" @scroll="onScroll" @wheel="onWheel">
|
||||||
<!-- Строка "выбрать все" — только в режиме выбора -->
|
<!-- Строка "выбрать все" — только в режиме выбора -->
|
||||||
<div v-if="selectMode" class="select-all-row" @click="toggleSelectAll">
|
<div v-if="selectMode" class="select-all-row" @click="toggleSelectAll">
|
||||||
<span
|
<span
|
||||||
|
|
@ -535,6 +601,42 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Pull-to-refresh */
|
||||||
|
.pull-indicator-wrap {
|
||||||
|
height: calc(var(--progress, 0) * 44px);
|
||||||
|
overflow: hidden;
|
||||||
|
flex-shrink: 0;
|
||||||
|
transition: height 0.12s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pull-indicator {
|
||||||
|
height: 44px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 7px;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-muted);
|
||||||
|
background:
|
||||||
|
linear-gradient(180deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.01) 100%),
|
||||||
|
rgba(12, 12, 20, 0.5);
|
||||||
|
backdrop-filter: blur(12px);
|
||||||
|
-webkit-backdrop-filter: blur(12px);
|
||||||
|
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
|
||||||
|
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
|
||||||
|
letter-spacing: 0.2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pull-indicator svg {
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pull-indicator.refreshing svg {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes spin {
|
@keyframes spin {
|
||||||
to { transform: rotate(360deg); }
|
to { transform: rotate(360deg); }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,8 @@ export const useMessagesStore = defineStore('messages', () => {
|
||||||
|
|
||||||
if (offset === 0) {
|
if (offset === 0) {
|
||||||
messages.value = result.messages
|
messages.value = result.messages
|
||||||
|
// Предзагрузка тел первых 10 писем в фоне
|
||||||
|
setTimeout(() => prefetchBodies(accountId, folderId, 10), 600)
|
||||||
} else {
|
} else {
|
||||||
messages.value.push(...result.messages)
|
messages.value.push(...result.messages)
|
||||||
}
|
}
|
||||||
|
|
@ -72,6 +74,22 @@ export const useMessagesStore = defineStore('messages', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function prefetchBodies(accountId: string, folderId: string, count: number): Promise<void> {
|
||||||
|
const toFetch = messages.value
|
||||||
|
.slice(0, count)
|
||||||
|
.filter((m) => !getCachedBody(`${accountId}:${folderId}:${m.id}`))
|
||||||
|
|
||||||
|
for (const msg of toFetch) {
|
||||||
|
const key = `${accountId}:${folderId}:${msg.id}`
|
||||||
|
try {
|
||||||
|
const body = await invoke('messages:body', { accountId, folderId, messageId: msg.id })
|
||||||
|
setCachedBody(key, body)
|
||||||
|
} catch {
|
||||||
|
// фоновая предзагрузка — ошибки не критичны
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function loadMore(): Promise<void> {
|
async function loadMore(): Promise<void> {
|
||||||
if (!accountsStore.activeAccountId || !foldersStore.activeFolderId) return
|
if (!accountsStore.activeAccountId || !foldersStore.activeFolderId) return
|
||||||
if (messages.value.length >= totalCount.value) return
|
if (messages.value.length >= totalCount.value) return
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,23 @@ function applyAccentColor(hex: string): void {
|
||||||
root.style.setProperty('--accent-swipe-bg', `rgba(${r},${g},${b},${swipeAlpha})`)
|
root.style.setProperty('--accent-swipe-bg', `rgba(${r},${g},${b},${swipeAlpha})`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── Auto-check intervals ────────────────────────────────
|
||||||
|
export const AUTO_CHECK_INTERVALS: { value: number; label: string }[] = [
|
||||||
|
{ value: 0, label: 'Выключено' },
|
||||||
|
{ value: 1, label: '1 минута' },
|
||||||
|
{ value: 5, label: '5 минут' },
|
||||||
|
{ value: 10, label: '10 минут' },
|
||||||
|
{ value: 30, label: '30 минут' },
|
||||||
|
]
|
||||||
|
|
||||||
// ─── Storage ─────────────────────────────────────────────
|
// ─── Storage ─────────────────────────────────────────────
|
||||||
const STORAGE_KEY = 'vue-mail-settings'
|
const STORAGE_KEY = 'vue-mail-settings'
|
||||||
|
|
||||||
function load(): {
|
function load(): {
|
||||||
swipeLeftAction?: SwipeAction
|
swipeLeftAction?: SwipeAction
|
||||||
swipeRightAction?: SwipeAction
|
swipeRightAction?: SwipeAction
|
||||||
accentColor?: string
|
accentColor?: string
|
||||||
|
autoCheckInterval?: number
|
||||||
} {
|
} {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '{}')
|
return JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '{}')
|
||||||
|
|
@ -80,9 +90,10 @@ function load(): {
|
||||||
export const useSettingsStore = defineStore('settings', () => {
|
export const useSettingsStore = defineStore('settings', () => {
|
||||||
const saved = load()
|
const saved = load()
|
||||||
|
|
||||||
const swipeLeftAction = ref<SwipeAction>(saved.swipeLeftAction ?? 'delete')
|
const swipeLeftAction = ref<SwipeAction>(saved.swipeLeftAction ?? 'delete')
|
||||||
const swipeRightAction = ref<SwipeAction>(saved.swipeRightAction ?? 'toggleRead')
|
const swipeRightAction = ref<SwipeAction>(saved.swipeRightAction ?? 'toggleRead')
|
||||||
const accentColor = ref<string>(saved.accentColor ?? '#a8e600')
|
const accentColor = ref<string>(saved.accentColor ?? '#a8e600')
|
||||||
|
const autoCheckInterval = ref<number>(saved.autoCheckInterval ?? 5)
|
||||||
|
|
||||||
// Apply on init
|
// Apply on init
|
||||||
applyAccentColor(accentColor.value)
|
applyAccentColor(accentColor.value)
|
||||||
|
|
@ -92,15 +103,16 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||||
persist()
|
persist()
|
||||||
})
|
})
|
||||||
|
|
||||||
watch([swipeLeftAction, swipeRightAction], persist)
|
watch([swipeLeftAction, swipeRightAction, autoCheckInterval], persist)
|
||||||
|
|
||||||
function persist(): void {
|
function persist(): void {
|
||||||
localStorage.setItem(STORAGE_KEY, JSON.stringify({
|
localStorage.setItem(STORAGE_KEY, JSON.stringify({
|
||||||
swipeLeftAction: swipeLeftAction.value,
|
swipeLeftAction: swipeLeftAction.value,
|
||||||
swipeRightAction: swipeRightAction.value,
|
swipeRightAction: swipeRightAction.value,
|
||||||
accentColor: accentColor.value,
|
accentColor: accentColor.value,
|
||||||
|
autoCheckInterval: autoCheckInterval.value,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
return { swipeLeftAction, swipeRightAction, accentColor }
|
return { swipeLeftAction, swipeRightAction, accentColor, autoCheckInterval }
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useAccountsStore } from '../stores/accounts.store'
|
import { useAccountsStore } from '../stores/accounts.store'
|
||||||
import { useSettingsStore, SWIPE_ACTION_LABELS, ACCENT_QUICK_PICKS, type SwipeAction } from '../stores/settings.store'
|
import { useSettingsStore, SWIPE_ACTION_LABELS, ACCENT_QUICK_PICKS, AUTO_CHECK_INTERVALS, type SwipeAction } from '../stores/settings.store'
|
||||||
import CustomSelect from '../components/CustomSelect.vue'
|
import CustomSelect from '../components/CustomSelect.vue'
|
||||||
import ColorPicker from '../components/ColorPicker.vue'
|
import ColorPicker from '../components/ColorPicker.vue'
|
||||||
|
|
||||||
|
|
@ -59,6 +59,16 @@ const swipeOptions: { value: SwipeAction; label: string }[] = (
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- Авто-проверка почты -->
|
||||||
|
<section>
|
||||||
|
<h2>Авто-проверка почты</h2>
|
||||||
|
<p class="section-desc">Автоматически проверять новые письма с заданным интервалом</p>
|
||||||
|
<div class="setting-row">
|
||||||
|
<label class="setting-label">Интервал проверки</label>
|
||||||
|
<CustomSelect v-model="settingsStore.autoCheckInterval" :options="AUTO_CHECK_INTERVALS" />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- Жесты -->
|
<!-- Жесты -->
|
||||||
<section>
|
<section>
|
||||||
<h2>Жесты</h2>
|
<h2>Жесты</h2>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue