refactor: improve logic
Signed-off-by: Sebastian <krupinski01@gmail.com>
This commit is contained in:
@@ -47,10 +47,10 @@ const selectedIdSet = computed(() => new Set(props.selectedMessageIds))
|
|||||||
const isOpened = (message: EntityInterface<MessageInterface>): boolean => {
|
const isOpened = (message: EntityInterface<MessageInterface>): boolean => {
|
||||||
if (!props.selectedMessage) return false
|
if (!props.selectedMessage) return false
|
||||||
return (
|
return (
|
||||||
message.provider === props.selectedMessage.provider &&
|
message.provider === selectedMessage.value.provider &&
|
||||||
message.service === props.selectedMessage.service &&
|
message.service === selectedMessage.value.service &&
|
||||||
message.collection === props.selectedMessage.collection &&
|
message.collection === selectedMessage.value.collection &&
|
||||||
message.identifier === props.selectedMessage.identifier
|
message.identifier === selectedMessage.value.identifier
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,12 +61,12 @@ const isSelected = (message: EntityInterface<MessageInterface>): boolean => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if message is unread
|
// Check if message is unread
|
||||||
const isUnread = (message: EntityInterface<MessageInterface>): boolean => {
|
const isUnread = (message: EntityObject): boolean => {
|
||||||
return !message.properties.flags?.read
|
return !message.properties.flags?.read
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if message is flagged
|
// Check if message is flagged
|
||||||
const isFlagged = (message: EntityInterface<MessageInterface>): boolean => {
|
const isFlagged = (message: EntityObject): boolean => {
|
||||||
return message.properties.flags?.flagged || false
|
return message.properties.flags?.flagged || false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ const handleSelectAllToggle = (value: boolean | null) => {
|
|||||||
|
|
||||||
// Sorted messages (newest first)
|
// Sorted messages (newest first)
|
||||||
const sortedMessages = computed(() => {
|
const sortedMessages = computed(() => {
|
||||||
return [...props.messages].sort((a, b) => {
|
return [...currentMessages.value].sort((a, b) => {
|
||||||
const dateA = a.properties.date ? new Date(a.properties.date).getTime() : 0
|
const dateA = a.properties.date ? new Date(a.properties.date).getTime() : 0
|
||||||
const dateB = b.properties.date ? new Date(b.properties.date).getTime() : 0
|
const dateB = b.properties.date ? new Date(b.properties.date).getTime() : 0
|
||||||
return dateB - dateA
|
return dateB - dateA
|
||||||
@@ -216,12 +216,12 @@ const unreadCount = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const totalCount = computed(() => {
|
const totalCount = computed(() => {
|
||||||
return props.selectedCollection?.properties.total ?? 0
|
return selectedFolder.value?.properties.total ?? 0
|
||||||
})
|
})
|
||||||
|
|
||||||
// True only when the collection explicitly provides total/unread counts
|
// True only when the collection explicitly provides total/unread counts
|
||||||
const hasCountData = computed(() => {
|
const hasCountData = computed(() => {
|
||||||
return props.selectedCollection?.properties.total != null
|
return selectedFolder.value?.properties.total != null
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ const hasCountData = computed(() => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Empty state -->
|
<!-- Empty state -->
|
||||||
<div v-else-if="messages.length === 0" class="pa-8 text-center">
|
<div v-else-if="currentMessages.length === 0" class="pa-8 text-center">
|
||||||
<v-icon size="64" color="grey-lighten-1">mdi-email-outline</v-icon>
|
<v-icon size="64" color="grey-lighten-1">mdi-email-outline</v-icon>
|
||||||
<div class="text-h6 mt-4 text-medium-emphasis">No messages</div>
|
<div class="text-h6 mt-4 text-medium-emphasis">No messages</div>
|
||||||
<div class="text-body-2 text-medium-emphasis">
|
<div class="text-body-2 text-medium-emphasis">
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch } from 'vue'
|
import { computed, ref, watch } from 'vue'
|
||||||
import { useUser } from '@KTXC'
|
import { useUser } from '@KTXC'
|
||||||
import type { EntityInterface } from '@MailManager/types/entity'
|
import type { EntityObject } from '@MailManager/models'
|
||||||
import type { MessageInterface } from '@MailManager/types/message'
|
|
||||||
import { MessageObject } from '@MailManager/models/message'
|
import { MessageObject } from '@MailManager/models/message'
|
||||||
import { SecurityLevel } from '@/utile/emailSanitizer'
|
import { SecurityLevel } from '@/utile/emailSanitizer'
|
||||||
import ReaderEmpty from './reader/ReaderEmpty.vue'
|
import ReaderEmpty from './reader/ReaderEmpty.vue'
|
||||||
@@ -12,7 +11,7 @@ import ReaderBody from './reader/ReaderBody.vue'
|
|||||||
|
|
||||||
// Props
|
// Props
|
||||||
interface Props {
|
interface Props {
|
||||||
message?: EntityInterface<MessageInterface> | null
|
message?: EntityObject | null
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
@@ -22,11 +21,11 @@ const { getSetting } = useUser()
|
|||||||
|
|
||||||
// Emits
|
// Emits
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
reply: [message: EntityInterface<MessageInterface>]
|
reply: [message: EntityObject]
|
||||||
forward: [message: EntityInterface<MessageInterface>]
|
forward: [message: EntityObject]
|
||||||
move: [message: EntityInterface<MessageInterface>]
|
move: [message: EntityObject]
|
||||||
delete: [message: EntityInterface<MessageInterface>]
|
delete: [message: EntityObject]
|
||||||
flag: [message: EntityInterface<MessageInterface>]
|
flag: [message: EntityObject]
|
||||||
compose: []
|
compose: []
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import type { EntityInterface } from '@MailManager/types/entity'
|
import type { EntityObject } from '@MailManager/models'
|
||||||
import type { MessageInterface } from '@MailManager/types/message'
|
|
||||||
import { SecurityLevel } from '@/utile/emailSanitizer'
|
import { SecurityLevel } from '@/utile/emailSanitizer'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
message: EntityInterface<MessageInterface>
|
message: EntityObject
|
||||||
isHtml: boolean
|
isHtml: boolean
|
||||||
allowImages: boolean
|
allowImages: boolean
|
||||||
securityLevel: SecurityLevel
|
securityLevel: SecurityLevel
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ const {
|
|||||||
selectionModeActive,
|
selectionModeActive,
|
||||||
composeMode,
|
composeMode,
|
||||||
composeReplyTo,
|
composeReplyTo,
|
||||||
currentMessages,
|
|
||||||
moveDialogVisible,
|
moveDialogVisible,
|
||||||
selectionCount,
|
selectionCount,
|
||||||
hasSelection,
|
hasSelection,
|
||||||
@@ -201,6 +200,7 @@ const handleFolderCreated = (folder: CollectionObject) => mailStore.notify(`Fold
|
|||||||
<!-- Message list panel -->
|
<!-- Message list panel -->
|
||||||
<div class="mail-list-panel">
|
<div class="mail-list-panel">
|
||||||
<MessageList
|
<MessageList
|
||||||
|
<<<<<<< HEAD
|
||||||
:messages="currentMessages"
|
:messages="currentMessages"
|
||||||
:selected-message="selectedMessage"
|
:selected-message="selectedMessage"
|
||||||
:selected-message-ids="selectedMessageIds"
|
:selected-message-ids="selectedMessageIds"
|
||||||
@@ -209,6 +209,8 @@ const handleFolderCreated = (folder: CollectionObject) => mailStore.notify(`Fold
|
|||||||
:has-selection="hasSelection"
|
:has-selection="hasSelection"
|
||||||
:all-current-messages-selected="allCurrentMessagesSelected"
|
:all-current-messages-selected="allCurrentMessagesSelected"
|
||||||
:selected-collection="selectedFolder"
|
:selected-collection="selectedFolder"
|
||||||
|
=======
|
||||||
|
>>>>>>> 749d922 (refactor: improve logic)
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
@open="handleMessageOpen"
|
@open="handleMessageOpen"
|
||||||
@toggle-selection="handleMessageSelectionToggle"
|
@toggle-selection="handleMessageSelectionToggle"
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import type { CollectionIdentifier, EntityIdentifier } from '@MailManager/types/
|
|||||||
import type { ServiceObject, CollectionObject, EntityObject } from '@MailManager/models'
|
import type { ServiceObject, CollectionObject, EntityObject } from '@MailManager/models'
|
||||||
|
|
||||||
export const useMailStore = defineStore('mailStore', () => {
|
export const useMailStore = defineStore('mailStore', () => {
|
||||||
|
const servicesStore = useServicesStore()
|
||||||
const collectionsStore = useCollectionsStore()
|
const collectionsStore = useCollectionsStore()
|
||||||
const entitiesStore = useEntitiesStore()
|
const entitiesStore = useEntitiesStore()
|
||||||
const servicesStore = useServicesStore()
|
|
||||||
const { showSnackbar } = useSnackbar()
|
const { showSnackbar } = useSnackbar()
|
||||||
|
|
||||||
// Background mail sync
|
// Background mail sync
|
||||||
@@ -160,12 +160,20 @@ export const useMailStore = defineStore('mailStore', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Sync Helpers ──────────────────────────────────────────────────────────
|
// ── Helpers ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function _serviceKey(provider: string, service: string | number) {
|
function _serviceKey(provider: string, service: string | number) {
|
||||||
return `${provider}:${String(service)}`
|
return `${provider}:${String(service)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _collectionIdentifier(collection: CollectionObject): CollectionIdentifier {
|
||||||
|
return `${collection.provider}:${String(collection.service)}:${String(collection.identifier)}` as CollectionIdentifier
|
||||||
|
}
|
||||||
|
|
||||||
|
function _entityIdentifier(entity: EntityObject): EntityIdentifier {
|
||||||
|
return `${entity.provider}:${String(entity.service)}:${String(entity.collection)}:${String(entity.identifier)}` as EntityIdentifier
|
||||||
|
}
|
||||||
|
|
||||||
function _setServiceFolderLoading(provider: string, service: string | number, loadingState: boolean) {
|
function _setServiceFolderLoading(provider: string, service: string | number, loadingState: boolean) {
|
||||||
serviceFolderLoadingState.value = {
|
serviceFolderLoadingState.value = {
|
||||||
...serviceFolderLoadingState.value,
|
...serviceFolderLoadingState.value,
|
||||||
@@ -234,14 +242,6 @@ export const useMailStore = defineStore('mailStore', () => {
|
|||||||
return serviceFolderErrorState.value[_serviceKey(provider, service)] ?? null
|
return serviceFolderErrorState.value[_serviceKey(provider, service)] ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
function _entityIdentifier(entity: EntityObject): EntityIdentifier {
|
|
||||||
return `${entity.provider}:${String(entity.service)}:${String(entity.collection)}:${String(entity.identifier)}` as EntityIdentifier
|
|
||||||
}
|
|
||||||
|
|
||||||
function _collectionIdentifier(collection: CollectionObject): CollectionIdentifier {
|
|
||||||
return `${collection.provider}:${String(collection.service)}:${String(collection.identifier)}` as CollectionIdentifier
|
|
||||||
}
|
|
||||||
|
|
||||||
function _serviceFor(provider: string, serviceIdentifier: string | number) {
|
function _serviceFor(provider: string, serviceIdentifier: string | number) {
|
||||||
return servicesStore.services.find(service =>
|
return servicesStore.services.find(service =>
|
||||||
service.provider === provider &&
|
service.provider === provider &&
|
||||||
@@ -438,11 +438,6 @@ export const useMailStore = defineStore('mailStore', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteMessage(message: EntityObject) {
|
|
||||||
// TODO: implement delete via entity / collection store
|
|
||||||
console.log('[Mail] Delete message:', message.identifier)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function moveMessages(targetFolder: CollectionObject) {
|
async function moveMessages(targetFolder: CollectionObject) {
|
||||||
const candidates = moveMessageCandidates.value
|
const candidates = moveMessageCandidates.value
|
||||||
|
|
||||||
@@ -524,6 +519,11 @@ export const useMailStore = defineStore('mailStore', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteMessage(message: EntityObject) {
|
||||||
|
// TODO: implement delete via entity / collection store
|
||||||
|
console.log('[Mail] Delete message:', message.identifier)
|
||||||
|
}
|
||||||
|
|
||||||
function toggleSidebar() {
|
function toggleSidebar() {
|
||||||
sidebarVisible.value = !sidebarVisible.value
|
sidebarVisible.value = !sidebarVisible.value
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user