Skip to content

Commit

Permalink
fix: merge to a single group of inbox items in for the viewtypes draf…
Browse files Browse the repository at this point in the history
…t and sent
  • Loading branch information
seanes committed Sep 26, 2024
1 parent 0fc465a commit f4587b8
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/frontend/src/pages/Inbox/Inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ export const Inbox = ({ viewType }: InboxProps) => {
(d) => new Date(d.createdAt).getFullYear() === new Date().getFullYear(),
);

const allAreDraftOrSent = itemsToDisplay.every((d) => ['drafts', 'sent'].includes(getViewType(d)));
if (!shouldShowSearchResults && allAreDraftOrSent) {
return [
{
label: t(`inbox.heading.title.${viewType}`, { count: itemsToDisplay.length }),
id: viewType,
items: itemsToDisplay,
},
];
}

return itemsToDisplay.reduce((acc, item, _, list) => {
const createdAt = new Date(item.createdAt);
const viewType = getViewType(item);
Expand All @@ -146,13 +157,9 @@ export const Inbox = ({ viewType }: InboxProps) => {
? format(createdAt, 'LLLL')
: format(createdAt, 'yyyy');

let label = key;

if (shouldShowSearchResults) {
label = t(`inbox.heading.search_results.${key}`, { count: list.filter((i) => getViewType(i) === key).length });
} else if (['drafts', 'sent'].includes(viewType)) {
label = t(`inbox.heading.title.${viewType}`, { count: list.length });
}
const label = shouldShowSearchResults
? t(`inbox.heading.search_results.${key}`, { count: list.filter((i) => getViewType(i) === key).length })
: key;

const existingCategory = acc.find((c) => c.id === key);

Expand Down

0 comments on commit f4587b8

Please sign in to comment.