-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notifs): centre de notifs pour les articles (#1418)
* feat(notifs): création de la page * feat(notifs): activer/désactiver notif articles * feat(notifs): accessibilité * feat(notif): retours PR * feat(notifs): retours PR * feat(notifs): retours PR
- Loading branch information
Showing
11 changed files
with
386 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
front/src/components/notification/notificationToggle.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import type { FC } from "react"; | ||
import * as React from "react"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { StyleSheet, Text, View } from "react-native"; | ||
|
||
import { Toggle } from "../../components/baseComponents"; | ||
import { Labels, StorageKeysConstants } from "../../constants"; | ||
import { Colors, FontStyle, FontWeight, Margins } from "../../styles"; | ||
import { StorageUtils } from "../../utils"; | ||
import * as NotificationUtils from "../../utils/notification.util"; | ||
import { NotificationType } from "../../utils/notification.util"; | ||
|
||
interface Props { | ||
title: string; | ||
description: string; | ||
type: NotificationType; | ||
} | ||
|
||
const NotificationToggle: FC<Props> = ({ title, description, type }) => { | ||
const [isToggleOn, setToggleOn] = useState(false); | ||
|
||
useEffect(() => { | ||
void initToggle(); | ||
}, []); | ||
|
||
const initToggle = async () => { | ||
// Value in storage | ||
const storageValue = (await StorageUtils.getObjectValue( | ||
StorageKeysConstants.notifToggleArticles | ||
)) as boolean; | ||
setToggleOn(storageValue); | ||
}; | ||
|
||
const onTouchToggle = useCallback(async () => { | ||
const newValue = !isToggleOn; | ||
setToggleOn(newValue); | ||
await StorageUtils.storeObjectValue( | ||
StorageKeysConstants.notifToggleArticles, | ||
newValue | ||
); | ||
|
||
if (newValue) { | ||
if (type === NotificationType.articles) | ||
void NotificationUtils.updateArticlesNotification(); | ||
} else await NotificationUtils.cancelAllNotificationsByType(type); | ||
}, [isToggleOn, type]); | ||
|
||
return ( | ||
<View style={styles.mainContent}> | ||
<View style={styles.itemTextBloc}> | ||
<Text style={styles.itemTextTitle} accessibilityRole="header"> | ||
{title} | ||
</Text> | ||
<Text style={styles.itemTextDescr}>{description}</Text> | ||
</View> | ||
<View style={styles.itemToggleBloc}> | ||
<Text | ||
style={[ | ||
styles.itemToggleText, | ||
isToggleOn ? null : { fontWeight: FontWeight.bold }, | ||
]} | ||
importantForAccessibility="no" | ||
accessibilityElementsHidden | ||
accessible={false} | ||
> | ||
{Labels.buttons.no} | ||
</Text> | ||
<View style={styles.itemToggle}> | ||
<Toggle isToggleOn={isToggleOn} toggleSwitch={onTouchToggle} /> | ||
</View> | ||
<Text | ||
style={[ | ||
styles.itemToggleText, | ||
isToggleOn ? { fontWeight: FontWeight.bold } : null, | ||
]} | ||
importantForAccessibility="no" | ||
accessibilityElementsHidden | ||
accessible={false} | ||
> | ||
{Labels.buttons.yes} | ||
</Text> | ||
</View> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
itemTextBloc: { | ||
flex: 2, | ||
}, | ||
itemTextDescr: { | ||
color: Colors.grey, | ||
fontStyle: FontStyle.italic, | ||
marginTop: Margins.smaller, | ||
}, | ||
itemTextTitle: { | ||
fontWeight: FontWeight.bold, | ||
}, | ||
itemToggle: { | ||
marginHorizontal: Margins.smaller, | ||
}, | ||
itemToggleBloc: { | ||
flex: 1, | ||
flexDirection: "row", | ||
justifyContent: "center", | ||
}, | ||
itemToggleText: { | ||
color: Colors.secondaryGreenDark, | ||
}, | ||
mainContent: { | ||
flexDirection: "row", | ||
marginVertical: Margins.larger, | ||
}, | ||
}); | ||
|
||
export default NotificationToggle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
front/src/screens/notificationsCenter/notificationsCenter.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import type { StackNavigationProp } from "@react-navigation/stack"; | ||
import type { FC } from "react"; | ||
import * as React from "react"; | ||
import { useCallback, useState } from "react"; | ||
import { ScrollView, StyleSheet, View } from "react-native"; | ||
|
||
import { BackButton, TitleH1 } from "../../components/baseComponents"; | ||
import NotificationToggle from "../../components/notification/notificationToggle.component"; | ||
import TrackerHandler from "../../components/tracker/trackerHandler.component"; | ||
import { Labels } from "../../constants"; | ||
import { Colors, Paddings } from "../../styles"; | ||
import type { RootStackParamList } from "../../types"; | ||
import { TrackerUtils } from "../../utils"; | ||
import { NotificationType } from "../../utils/notification.util"; | ||
|
||
interface Props { | ||
navigation: StackNavigationProp<RootStackParamList>; | ||
} | ||
|
||
const NotificationsCenter: FC<Props> = ({ navigation }) => { | ||
const [trackerAction, setTrackerAction] = useState<string>(""); | ||
|
||
const goBack = useCallback(() => { | ||
setTrackerAction(Labels.buttons.cancel); | ||
navigation.goBack(); | ||
}, [navigation]); | ||
|
||
return ( | ||
<ScrollView style={styles.mainContainer}> | ||
<TrackerHandler | ||
screenName={TrackerUtils.TrackingEvent.NOTIFICATIONS_CENTER} | ||
actionName={trackerAction} | ||
/> | ||
<View style={styles.header}> | ||
<View style={styles.flexStart}> | ||
<BackButton action={goBack} /> | ||
</View> | ||
<TitleH1 | ||
animated={false} | ||
title={Labels.notificationsCenter.title} | ||
description={Labels.notificationsCenter.description} | ||
/> | ||
<NotificationToggle | ||
title={Labels.notificationsCenter.article.title} | ||
description={Labels.notificationsCenter.article.decription} | ||
type={NotificationType.articles} | ||
/> | ||
</View> | ||
</ScrollView> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
flexStart: { | ||
alignItems: "flex-start", | ||
}, | ||
header: { | ||
padding: Paddings.default, | ||
paddingTop: Paddings.default, | ||
}, | ||
mainContainer: { | ||
backgroundColor: Colors.white, | ||
}, | ||
}); | ||
|
||
export default NotificationsCenter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.