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 => {
|
||||
if (!props.selectedMessage) return false
|
||||
return (
|
||||
message.provider === props.selectedMessage.provider &&
|
||||
message.service === props.selectedMessage.service &&
|
||||
message.collection === props.selectedMessage.collection &&
|
||||
message.identifier === props.selectedMessage.identifier
|
||||
message.provider === selectedMessage.value.provider &&
|
||||
message.service === selectedMessage.value.service &&
|
||||
message.collection === selectedMessage.value.collection &&
|
||||
message.identifier === selectedMessage.value.identifier
|
||||
)
|
||||
}
|
||||
|
||||
@@ -61,12 +61,12 @@ const isSelected = (message: EntityInterface<MessageInterface>): boolean => {
|
||||
}
|
||||
|
||||
// Check if message is unread
|
||||
const isUnread = (message: EntityInterface<MessageInterface>): boolean => {
|
||||
const isUnread = (message: EntityObject): boolean => {
|
||||
return !message.properties.flags?.read
|
||||
}
|
||||
|
||||
// Check if message is flagged
|
||||
const isFlagged = (message: EntityInterface<MessageInterface>): boolean => {
|
||||
const isFlagged = (message: EntityObject): boolean => {
|
||||
return message.properties.flags?.flagged || false
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ const handleSelectAllToggle = (value: boolean | null) => {
|
||||
|
||||
// Sorted messages (newest first)
|
||||
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 dateB = b.properties.date ? new Date(b.properties.date).getTime() : 0
|
||||
return dateB - dateA
|
||||
@@ -216,12 +216,12 @@ const unreadCount = 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
|
||||
const hasCountData = computed(() => {
|
||||
return props.selectedCollection?.properties.total != null
|
||||
return selectedFolder.value?.properties.total != null
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -290,7 +290,7 @@ const hasCountData = computed(() => {
|
||||
</div>
|
||||
|
||||
<!-- 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>
|
||||
<div class="text-h6 mt-4 text-medium-emphasis">No messages</div>
|
||||
<div class="text-body-2 text-medium-emphasis">
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useUser } from '@KTXC'
|
||||
import type { EntityInterface } from '@MailManager/types/entity'
|
||||
import type { MessageInterface } from '@MailManager/types/message'
|
||||
import type { EntityObject } from '@MailManager/models'
|
||||
import { MessageObject } from '@MailManager/models/message'
|
||||
import { SecurityLevel } from '@/utile/emailSanitizer'
|
||||
import ReaderEmpty from './reader/ReaderEmpty.vue'
|
||||
@@ -12,7 +11,7 @@ import ReaderBody from './reader/ReaderBody.vue'
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
message?: EntityInterface<MessageInterface> | null
|
||||
message?: EntityObject | null
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
@@ -22,11 +21,11 @@ const { getSetting } = useUser()
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits<{
|
||||
reply: [message: EntityInterface<MessageInterface>]
|
||||
forward: [message: EntityInterface<MessageInterface>]
|
||||
move: [message: EntityInterface<MessageInterface>]
|
||||
delete: [message: EntityInterface<MessageInterface>]
|
||||
flag: [message: EntityInterface<MessageInterface>]
|
||||
reply: [message: EntityObject]
|
||||
forward: [message: EntityObject]
|
||||
move: [message: EntityObject]
|
||||
delete: [message: EntityObject]
|
||||
flag: [message: EntityObject]
|
||||
compose: []
|
||||
}>()
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type { EntityInterface } from '@MailManager/types/entity'
|
||||
import type { MessageInterface } from '@MailManager/types/message'
|
||||
import type { EntityObject } from '@MailManager/models'
|
||||
import { SecurityLevel } from '@/utile/emailSanitizer'
|
||||
|
||||
interface Props {
|
||||
message: EntityInterface<MessageInterface>
|
||||
message: EntityObject
|
||||
isHtml: boolean
|
||||
allowImages: boolean
|
||||
securityLevel: SecurityLevel
|
||||
|
||||
@@ -36,7 +36,6 @@ const {
|
||||
selectionModeActive,
|
||||
composeMode,
|
||||
composeReplyTo,
|
||||
currentMessages,
|
||||
moveDialogVisible,
|
||||
selectionCount,
|
||||
hasSelection,
|
||||
@@ -201,6 +200,7 @@ const handleFolderCreated = (folder: CollectionObject) => mailStore.notify(`Fold
|
||||
<!-- Message list panel -->
|
||||
<div class="mail-list-panel">
|
||||
<MessageList
|
||||
<<<<<<< HEAD
|
||||
:messages="currentMessages"
|
||||
:selected-message="selectedMessage"
|
||||
:selected-message-ids="selectedMessageIds"
|
||||
@@ -209,6 +209,8 @@ const handleFolderCreated = (folder: CollectionObject) => mailStore.notify(`Fold
|
||||
:has-selection="hasSelection"
|
||||
:all-current-messages-selected="allCurrentMessagesSelected"
|
||||
:selected-collection="selectedFolder"
|
||||
=======
|
||||
>>>>>>> 749d922 (refactor: improve logic)
|
||||
:loading="loading"
|
||||
@open="handleMessageOpen"
|
||||
@toggle-selection="handleMessageSelectionToggle"
|
||||
|
||||
@@ -9,9 +9,9 @@ import type { CollectionIdentifier, EntityIdentifier } from '@MailManager/types/
|
||||
import type { ServiceObject, CollectionObject, EntityObject } from '@MailManager/models'
|
||||
|
||||
export const useMailStore = defineStore('mailStore', () => {
|
||||
const servicesStore = useServicesStore()
|
||||
const collectionsStore = useCollectionsStore()
|
||||
const entitiesStore = useEntitiesStore()
|
||||
const servicesStore = useServicesStore()
|
||||
const { showSnackbar } = useSnackbar()
|
||||
|
||||
// Background mail sync
|
||||
@@ -160,12 +160,20 @@ export const useMailStore = defineStore('mailStore', () => {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Sync Helpers ──────────────────────────────────────────────────────────
|
||||
// ── Helpers ──────────────────────────────────────────────────────────
|
||||
|
||||
function _serviceKey(provider: string, service: string | number) {
|
||||
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) {
|
||||
serviceFolderLoadingState.value = {
|
||||
...serviceFolderLoadingState.value,
|
||||
@@ -234,14 +242,6 @@ export const useMailStore = defineStore('mailStore', () => {
|
||||
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) {
|
||||
return servicesStore.services.find(service =>
|
||||
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) {
|
||||
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() {
|
||||
sidebarVisible.value = !sidebarVisible.value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user