diff --git a/front/components/GtkUI/ElementTypes.tsx b/front/components/GtkUI/ElementTypes.tsx index e1ae0ab..61fad59 100644 --- a/front/components/GtkUI/ElementTypes.tsx +++ b/front/components/GtkUI/ElementTypes.tsx @@ -62,7 +62,7 @@ export const getElementToggleNode = ( ) => { return ( onToggle()} + // the callback is called by the Pressable component wrapping the entire row isChecked={value ?? false} defaultIsChecked={defaultValue} disabled={disabled} diff --git a/front/views/settings/NotificationView.tsx b/front/views/settings/NotificationView.tsx index b0c66d9..8c6bb16 100644 --- a/front/views/settings/NotificationView.tsx +++ b/front/views/settings/NotificationView.tsx @@ -5,62 +5,101 @@ import { translate, Translate } from "../../i18n/i18n"; import { useDispatch } from "react-redux"; import { RootState, useSelector } from "../../state/Store"; import { useLanguage } from "../../state/LanguageSlice"; -import { SettingsState, updateSettings } from '../../state/SettingsSlice'; +import { SettingsState, updateSettings } from "../../state/SettingsSlice"; +import ElementList from "../../components/GtkUI/ElementList"; const NotificationsView = ({ navigation }) => { const dispatch = useDispatch(); - const settings: SettingsState = useSelector( + let settings: SettingsState = useSelector( (state: RootState) => state.settings ); + const [pushNotifications, setPushNotifications] = React.useState( + settings.enablePushNotifications + ); + const [emailNotifications, setEmailNotifications] = React.useState( + settings.enableMailNotifications + ); + const [trainingReminder, setTrainingReminder] = React.useState( + settings.enableLessongsReminders + ); + const [releaseAlert, setReleaseAlert] = React.useState( + settings.enableReleaseAlerts + ); + return (
- - Push notifications - { - dispatch(updateSettings({ enablePushNotifications: value })); - }} - /> - - - Email notifications - { - dispatch(updateSettings({ enableMailNotifications: value })); - }} - /> - - - Training reminder - { - dispatch(updateSettings({ enableLessongsReminders: value })); - }} - /> - - - New songs - { - dispatch(updateSettings({ enableReleaseAlerts: value })); - }} - /> - + { + dispatch( + updateSettings({ + enablePushNotifications: !settings.enablePushNotifications, + }) + ); + setPushNotifications(!pushNotifications); + }, + }, + }, + { + type: "toggle", + title: "Email notifications", + data: { + value: emailNotifications, + onToggle: () => { + dispatch( + updateSettings({ + enableMailNotifications: !settings.enableMailNotifications, + }) + ); + setEmailNotifications(!emailNotifications); + }, + }, + }, + { + type: "toggle", + title: "Training reminder", + data: { + value: trainingReminder, + onToggle: () => { + dispatch( + updateSettings({ + enableLessongsReminders: !settings.enableLessongsReminders, + }) + ); + setTrainingReminder(!trainingReminder); + }, + }, + }, + { + type: "toggle", + title: "New songs", + data: { + value: releaseAlert, + onToggle: () => { + dispatch( + updateSettings({ + enableReleaseAlerts: !settings.enableReleaseAlerts, + }) + ); + setReleaseAlert(!releaseAlert); + }, + }, + }, + ]} + />
); };