Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added a Notification head bar to present current notifications number #1322

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const HomeFooterView: React.FC<HomeFooterViewProps> = ({ children }) => {

imageContainer: {
alignItems: 'center',
marginTop: 100,
marginTop: 60,
},
})

Expand Down
40 changes: 36 additions & 4 deletions packages/legacy/core/App/components/views/HomeHeaderView.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
import { useTheme } from '../../contexts/theme'
import { useTranslation } from 'react-i18next'
import React from 'react'
import { View } from 'react-native'
import { View, Text, StyleSheet } from 'react-native'
import { NotificationReturnType } from '../../hooks/notifications'
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'

interface HomeHeaderViewProps {
export interface HomeHeaderViewProps {
notifications: NotificationReturnType
showNotifications: boolean
children?: any
}

const HomeHeaderView: React.FC<HomeHeaderViewProps> = ({ children }) => {
return <View>{children}</View>
const HomeHeaderView: React.FC<HomeHeaderViewProps> = ({ notifications, showNotifications, children }: HomeHeaderViewProps) => {
const { t } = useTranslation()
const { ColorPallet, TextTheme } = useTheme()

const styles = StyleSheet.create({
noNotificationContainer: {
flex: 1,
flexDirection: "row",
alignContent: "space-between",
paddingHorizontal: 20,
paddingTop: 20,
paddingBottom: 0,
backgroundColor: ColorPallet.brand.secondaryBackground,
}
})
return notifications?.length > 0 ? (
<View style={styles.noNotificationContainer}>
<Text style={[TextTheme.label, { fontSize: 20, marginBottom: 6, textAlign: 'left' }]}>
{t('Home.Notifications')} ({notifications?.length})
</Text>
<Text style={{ position: 'absolute', right: 20, top: 20}}>
<Icon name={showNotifications ? 'chevron-up' : 'chevron-down'} size={30} />
</Text>
{children}
</View>
) : (
<></>
)
}

export default HomeHeaderView
3 changes: 2 additions & 1 deletion packages/legacy/core/App/container-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { PINExplainerProps } from './screens/PINExplainer'
import { CredentialListFooterProps } from './types/credential-list-footer'
import { ContactListItemProps } from './components/listItems/ContactListItem'
import { ContactCredentialListItemProps } from './components/listItems/ContactCredentialListItem'
import { HomeHeaderViewProps } from './components/views/HomeHeaderView'
import { InlineErrorConfig } from './types/error'

export type FN_ONBOARDING_DONE = (
Expand Down Expand Up @@ -181,7 +182,7 @@ export type TokenMapping = {
[TOKENS.COMPONENT_CRED_LIST_HEADER_RIGHT]: React.FC
[TOKENS.COMPONENT_CRED_LIST_OPTIONS]: React.FC
[TOKENS.COMPONENT_CRED_LIST_FOOTER]: React.FC<CredentialListFooterProps>
[TOKENS.COMPONENT_HOME_HEADER]: React.FC
[TOKENS.COMPONENT_HOME_HEADER]: React.FC<HomeHeaderViewProps>
[TOKENS.COMPONENT_HOME_NOTIFICATIONS_EMPTY_LIST]: React.FC
[TOKENS.COMPONENT_HOME_FOOTER]: React.FC
[TOKENS.COMPONENT_CRED_EMPTY_LIST]: React.FC
Expand Down
17 changes: 13 additions & 4 deletions packages/legacy/core/App/screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ const Home: React.FC<HomeProps> = () => {
const { ColorPallet } = useTheme()
const [store, dispatch] = useStore()
const { start } = useTour()
const [showNotifications] = useState(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This state variable isn't changed and is used in more than one component. Would it be better adding it as a config option? (TOKENS.CONFIG)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise I don't really see the purpose, as it's not overideable and isn't ever changed. If that's fine then maybe we can just remove it entirely?

Copy link
Contributor Author

@jian4on jian4on Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the chevron and showNotifications state, will add them back in story implements them

const [showTourPopup, setShowTourPopup] = useState(false)
const screenIsFocused = useIsFocused()

const styles = StyleSheet.create({
flatlist: {
marginBottom: 35,
marginBottom: 20,
},
})

Expand Down Expand Up @@ -130,7 +131,15 @@ const Home: React.FC<HomeProps> = () => {
scrollEnabled={notifications?.length > 0 ? true : false}
decelerationRate="fast"
ListEmptyComponent={NoNewUpdates}
ListHeaderComponent={() => <HomeHeaderView />}
ListHeaderComponent={() => {
const homeHeaderViewProps = {
notifications: notifications,
showNotifications: showNotifications,
}
return (
<HomeHeaderView {...homeHeaderViewProps} />
)
}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ListHeaderComponent={() => {
const homeHeaderViewProps = {
notifications: notifications,
showNotifications: showNotifications,
}
return (
<HomeHeaderView {...homeHeaderViewProps} />
)
}}
ListHeaderComponent={() => <HomeHeaderView notifications={notifications} /> }

If the showNotifications gets moved into config, this might be a bit cleaner

ListFooterComponent={() => <HomeFooterView />}
data={notifications}
keyExtractor={(_, i) => i.toString()}
Expand All @@ -139,11 +148,11 @@ const Home: React.FC<HomeProps> = () => {
style={{
paddingHorizontal: 20,
paddingTop: index === 0 ? 20 : 0,
paddingBottom: index === notifications.length - 1 ? 20 : 10,
paddingBottom: !showNotifications ? 0 : index === notifications.length - 1 ? 20 : 10,
backgroundColor: ColorPallet.brand.secondaryBackground,
}}
>
{DisplayListItemType(item)}
{ showNotifications && DisplayListItemType(item) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showNotifications can be removed unless it becomes changeable / configurable. If it does become configurable, then it should simply not render these list items at all. No empty Views with padding and background needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the chevron icons and the showNotification state, will add them back in next story with the implementations

</View>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import HomeHeaderView from '../../App/components/views/HomeHeaderView'

describe('HomeHeaderView Component', () => {
test('Renders correctly', async () => {
const tree = render(<HomeHeaderView />)
const tree = render(<HomeHeaderView {...{ notifications: [], showNotifications: true}} />)

expect(tree).toMatchSnapshot()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports[`HomeFooterView Component Renders correctly with no notifications 1`] =
style={
Object {
"alignItems": "center",
"marginTop": 100,
"marginTop": 60,
}
}
>
Expand Down Expand Up @@ -108,7 +108,7 @@ exports[`HomeFooterView Component Renders correctly with notifications 1`] = `
style={
Object {
"alignItems": "center",
"marginTop": 100,
"marginTop": 60,
}
}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`HomeHeaderView Component Renders correctly 1`] = `<View />`;
exports[`HomeHeaderView Component Renders correctly 1`] = `null`;
Loading