fixed a bug in ElementToggle and added statte for notifications and ElementList overhaul

This commit is contained in:
Clément Le Bihan
2023-04-10 23:04:44 +02:00
parent d9ede44d7d
commit 4ec8878e8a
2 changed files with 86 additions and 47 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ export const getElementToggleNode = (
) => {
return (
<Switch
onToggle={() => onToggle()}
// the callback is called by the Pressable component wrapping the entire row
isChecked={value ?? false}
defaultIsChecked={defaultValue}
disabled={disabled}
+85 -46
View File
@@ -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 (
<Center style={{ flex: 1, justifyContent: "center" }}>
<Heading style={{ textAlign: "center" }}>
<Translate translationKey="notifBtn" />
</Heading>
<View style={{ margin: 20 }}>
<Text style={{ textAlign: "center" }}>Push notifications</Text>
<Switch
value={settings.enablePushNotifications}
style={{ alignSelf: "center", margin: 10 }}
colorScheme="primary"
onValueChange={(value) => {
dispatch(updateSettings({ enablePushNotifications: value }));
}}
/>
</View>
<View style={{ margin: 20 }}>
<Text style={{ textAlign: "center" }}>Email notifications</Text>
<Switch
value={settings.enableMailNotifications}
style={{ alignSelf: "center", margin: 10 }}
colorScheme="primary"
onValueChange={(value) => {
dispatch(updateSettings({ enableMailNotifications: value }));
}}
/>
</View>
<View style={{ margin: 20 }}>
<Text style={{ textAlign: "center" }}>Training reminder</Text>
<Switch
value={settings.enableLessongsReminders}
style={{ alignSelf: "center", margin: 10 }}
colorScheme="primary"
onValueChange={(value) => {
dispatch(updateSettings({ enableLessongsReminders: value }));
}}
/>
</View>
<View style={{ margin: 20 }}>
<Text style={{ textAlign: "center" }}>New songs</Text>
<Switch
value={settings.enableReleaseAlerts}
style={{ alignSelf: "center", margin: 10 }}
colorScheme="primary"
onValueChange={(value) => {
dispatch(updateSettings({ enableReleaseAlerts: value }));
}}
/>
</View>
<ElementList
style={{
marginTop: 20,
width: "100%",
maxWidth: 850,
}}
elements={[
{
type: "toggle",
title: "Push notifications",
data: {
value: pushNotifications,
onToggle: () => {
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);
},
},
},
]}
/>
</Center>
);
};