diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 9049b273..ff117436 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -1,5 +1,11 @@ # @baseapp-frontend/components +## 1.0.30 + +### Patch Changes + +- Native: Dividing notifications into unread/read + ## 1.0.29 ### Patch Changes diff --git a/packages/components/modules/notifications/native/NotificationsList/Divider/index.tsx b/packages/components/modules/notifications/native/NotificationsList/Divider/index.tsx new file mode 100644 index 00000000..28eeca70 --- /dev/null +++ b/packages/components/modules/notifications/native/NotificationsList/Divider/index.tsx @@ -0,0 +1,24 @@ +import { FC } from 'react' + +import { Text } from '@baseapp-frontend/design-system/components/native/typographies' +import { View } from '@baseapp-frontend/design-system/components/native/views' +import { useTheme } from '@baseapp-frontend/design-system/providers/native' + +import { createStyles } from './styles' + +const Divider: FC = () => { + const theme = useTheme() + const styles = createStyles(theme) + + return ( + + + + Read + + + + ) +} + +export default Divider diff --git a/packages/components/modules/notifications/native/NotificationsList/Divider/styles.ts b/packages/components/modules/notifications/native/NotificationsList/Divider/styles.ts new file mode 100644 index 00000000..ba7dc328 --- /dev/null +++ b/packages/components/modules/notifications/native/NotificationsList/Divider/styles.ts @@ -0,0 +1,25 @@ +import { Theme } from '@baseapp-frontend/design-system/styles/native' + +import { StyleSheet } from 'react-native' + +export const createStyles = (theme: Theme) => + StyleSheet.create({ + container: { + height: 30, + width: '100%', + display: 'flex', + flexDirection: 'row', + justifyContent: 'center', + alignItems: 'center', + gap: 16, + }, + line: { + height: 1, + width: 10, + backgroundColor: theme.colors.surface.disabled, + flexGrow: 1, + }, + text: { + alignItems: 'center', + }, + }) diff --git a/packages/components/modules/notifications/native/NotificationsList/NotificationItem/index.tsx b/packages/components/modules/notifications/native/NotificationsList/NotificationItem/index.tsx index 834448a1..89b12557 100644 --- a/packages/components/modules/notifications/native/NotificationsList/NotificationItem/index.tsx +++ b/packages/components/modules/notifications/native/NotificationsList/NotificationItem/index.tsx @@ -10,6 +10,7 @@ import { NotificationItemProps } from './types' const NotificationItem: FC = ({ notification: notificationRef, NotificationItemRenderer = DefaultNotificationItemRenderer, + refetch, }) => { const notification = useFragment(NotificationItemFragment, notificationRef) @@ -18,6 +19,9 @@ const NotificationItem: FC = ({ const markAsRead = () => { if (notification.unread) { commitMutation({ + // TODO: check whether this is needed (clicking on a notification should navigate to the underlying comment, + // so the screen will not remain visible). If needed, check whether we can use optimistic updates + onCompleted: refetch, variables: { input: { read: true, diff --git a/packages/components/modules/notifications/native/NotificationsList/NotificationItem/types.ts b/packages/components/modules/notifications/native/NotificationsList/NotificationItem/types.ts index b3195c47..bb8472a5 100644 --- a/packages/components/modules/notifications/native/NotificationsList/NotificationItem/types.ts +++ b/packages/components/modules/notifications/native/NotificationsList/NotificationItem/types.ts @@ -9,6 +9,7 @@ import { NotificationItemRendererProps } from './NotificationItemRenderer/types' export interface NotificationItemProps { notification: NotificationItemFragment$key NotificationItemRenderer?: FC + refetch: VoidFunction } export interface GenericItemProps { diff --git a/packages/components/modules/notifications/native/NotificationsList/index.tsx b/packages/components/modules/notifications/native/NotificationsList/index.tsx index 8a5d90fa..50a8dd71 100644 --- a/packages/components/modules/notifications/native/NotificationsList/index.tsx +++ b/packages/components/modules/notifications/native/NotificationsList/index.tsx @@ -16,6 +16,7 @@ import { useNotificationsSubscription, } from '../../common' import { NotificationsNode } from '../../common/types' +import Divider from './Divider' import DefaultEmptyState from './EmptyState' import MarkAllAsReadButton from './MarkAllAsReadButton' import DefaultNotificationItem from './NotificationItem' @@ -48,19 +49,24 @@ const NotificationsList: FC = ({ ) const refetchNotifications = () => { - refetch(options, { fetchPolicy: 'network-only' }) + refetch(options, { fetchPolicy: 'store-and-network' }) } - const renderNotificationItem = (notification: NotificationsNode) => { + const renderNotificationItem = (notification: NotificationsNode, index: number) => { if (!notification) return null - - // TODO add notifications divider and unread/Read notifications as per design + let divider = null + if (!notification.unread && index > 0 && notifications[index - 1]?.unread) { + divider = + } return ( - + <> + {divider} + + ) } @@ -71,7 +77,7 @@ const NotificationsList: FC = ({ renderNotificationItem(item)} + renderItem={({ item, index }: { item: NotificationsNode, index: number }) => renderNotificationItem(item, index)} estimatedItemSize={134} onEndReached={() => { if (hasNext) { diff --git a/packages/components/package.json b/packages/components/package.json index a28e2c6e..3b802292 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -1,7 +1,7 @@ { "name": "@baseapp-frontend/components", "description": "BaseApp components modules such as comments, notifications, messages, and more.", - "version": "1.0.29", + "version": "1.0.30", "sideEffects": false, "scripts": { "babel:transpile": "babel modules -d tmp-babel --extensions .ts,.tsx --ignore '**/__tests__/**','**/__storybook__/**'",