From a655bbc590b2ac8016bc4ccb73030aa68ce1e891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20=C3=96brink?= Date: Fri, 1 Oct 2021 09:49:03 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Notifications=20use=20mo?= =?UTF-8?q?dified,=20then=20created=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/__tests__/Notification.test.js | 17 +++++++++++++++-- .../app/components/childListItem.component.tsx | 7 +++++-- .../app/components/notification.component.tsx | 7 ++----- .../components/notificationsList.component.tsx | 8 -------- packages/app/ios/Podfile.lock | 4 ++-- packages/app/package.json | 2 +- packages/app/yarn.lock | 8 ++++---- 7 files changed, 29 insertions(+), 24 deletions(-) diff --git a/packages/app/components/__tests__/Notification.test.js b/packages/app/components/__tests__/Notification.test.js index 8ec6b1a5..3a205795 100644 --- a/packages/app/components/__tests__/Notification.test.js +++ b/packages/app/components/__tests__/Notification.test.js @@ -7,6 +7,7 @@ const defaultItem = { sender: 'Planering', category: 'Bedömning', dateCreated: '2021-02-15T09:13:28.484Z', + dateModified: '2021-02-15T09:14:28.484Z', } const setup = (customProps = {}) => { @@ -22,9 +23,20 @@ beforeEach(() => { MockDate.set('2021-02-15T09:30:28.484Z') }) -test('renders subtitle with date', () => { +test('renders subtitle with modified date', () => { const screen = setup() + expect(screen.getByText('Bedömning • för 16 minuter sedan')).toBeTruthy() +}) + +test('renders subtitle with created date', () => { + const itemWithoutModifiedDate = { + ...defaultItem, + dateModified: undefined, + } + + const screen = setup({ item: itemWithoutModifiedDate }) + expect(screen.getByText('Bedömning • för 17 minuter sedan')).toBeTruthy() }) @@ -32,6 +44,7 @@ test('renders subtitle without date', () => { const itemWithoutDate = { ...defaultItem, dateCreated: undefined, + dateModified: undefined, } const screen = setup({ item: itemWithoutDate }) @@ -47,5 +60,5 @@ test('renders subtitle without category', () => { const screen = setup({ item: itemWithoutCategory }) - expect(screen.getByText('för 17 minuter sedan')).toBeTruthy() + expect(screen.getByText('för 16 minuter sedan')).toBeTruthy() }) diff --git a/packages/app/components/childListItem.component.tsx b/packages/app/components/childListItem.component.tsx index e89b8b3c..c7c8e453 100644 --- a/packages/app/components/childListItem.component.tsx +++ b/packages/app/components/childListItem.component.tsx @@ -53,8 +53,11 @@ export const ChildListItem = ({ child, color }: ChildListItemProps) => { moment().add(7, 'days').toISOString() ) - const notificationsThisWeek = notifications.filter(({ dateCreated }) => - dateCreated ? moment(dateCreated).isSame(moment(), 'week') : false + const notificationsThisWeek = notifications.filter( + ({ dateCreated, dateModified }) => { + const date = dateModified || dateCreated + return date ? moment(date).isSame(moment(), 'week') : false + } ) const newsThisWeek = news.filter(({ modified, published }) => { diff --git a/packages/app/components/notification.component.tsx b/packages/app/components/notification.component.tsx index ab7e6a0a..e0657ea6 100644 --- a/packages/app/components/notification.component.tsx +++ b/packages/app/components/notification.component.tsx @@ -16,11 +16,8 @@ export const Notification = ({ item }: NotificationProps) => { const open = () => setIsOpen(true) const close = () => setIsOpen(false) - const displayDate = item.dateModified - ? moment(item.dateModified).fromNow() - : item.dateCreated - ? moment(item.dateCreated).fromNow() - : null + const date = item.dateModified || item.dateCreated + const displayDate = date ? moment(date).fromNow() : null const sharedCookiesEnabled: boolean = Boolean( item.url && item.url.startsWith('https://start.unikum.net/') diff --git a/packages/app/components/notificationsList.component.tsx b/packages/app/components/notificationsList.component.tsx index 177b2f51..2b09051b 100644 --- a/packages/app/components/notificationsList.component.tsx +++ b/packages/app/components/notificationsList.component.tsx @@ -10,14 +10,6 @@ export const NotificationsList = () => { const child = useChild() const { data } = useNotifications(child) - data.sort((a, b) => - a.dateModified > b.dateModified - ? -1 - : b.dateModified > a.dateModified - ? 1 - : 0 - ) - return (