mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 08:13:50 +00:00
25 lines
1.1 KiB
TypeScript
25 lines
1.1 KiB
TypeScript
import { useEmailStore } from '@/stores/email-store';
|
|
import { useSettingsStore } from '@/stores/settings-store';
|
|
import { isFilterEmpty } from '@/lib/jmap/search-utils';
|
|
import { isUnreadFirstView, type UnreadSection } from '@/lib/unread-first';
|
|
|
|
/**
|
|
* The Unread section of Mountain View's "Unread first" inbox, when the list
|
|
* on screen is that inbox and its section is loaded; null otherwise.
|
|
*/
|
|
export function useUnreadFirstSection(): UnreadSection | null {
|
|
const interfaceLayout = useSettingsStore((state) => state.interfaceLayout);
|
|
const mvInboxType = useSettingsStore((state) => state.mvInboxType);
|
|
return useEmailStore((state) => {
|
|
const section = state.unreadSection;
|
|
if (!section || section.mailboxId !== state.selectedMailbox || state.isScheduledView) return null;
|
|
const active = isUnreadFirstView({
|
|
interfaceLayout,
|
|
mvInboxType,
|
|
mailboxRole: state.mailboxes.find((mailbox) => mailbox.id === state.selectedMailbox)?.role,
|
|
otherView: !!state.selectedKeyword || !!state.searchQuery || !isFilterEmpty(state.searchFilters) || state.isUnifiedView,
|
|
});
|
|
return active ? section : null;
|
|
});
|
|
}
|