Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Make ts-strict happier
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Jun 19, 2023
1 parent 5f2fc11 commit 9f8a986
Showing 1 changed file with 145 additions and 113 deletions.
258 changes: 145 additions & 113 deletions src/components/views/settings/notifications/NotificationSettings2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default function NotificationSettings2(): JSX.Element {

return (
<div className="mx_NotificationSettings2">
{hasPendingChanges && (
{hasPendingChanges && model !== null && (
<SettingsBanner
icon={<img src={NewAndImprovedIcon} alt="" width={12} />}
action={_t("Switch now")}
Expand All @@ -109,12 +109,14 @@ export default function NotificationSettings2(): JSX.Element {
label={_t("Enable notifications for this account")}
value={!settings.globalMute}
disabled={disabled}
onChange={(value) =>
reconcile({
...model,
globalMute: !value,
})
}
onChange={(value) => {
if (model !== null) {
reconcile({
...model,
globalMute: !value,
});
}
}}
/>
<LabelledToggleSwitch
label={_t("Enable desktop notifications for this session")}
Expand Down Expand Up @@ -147,22 +149,24 @@ export default function NotificationSettings2(): JSX.Element {
value={toDefaultLevels(settings.defaultLevels)}
disabled={disabled}
definitions={NotificationOptions}
onChange={(value) =>
reconcile({
...model,
defaultLevels: {
...model.defaultLevels,
dm:
value !== NotificationDefaultLevels.MENTIONS_KEYWORDS
? RoomNotifState.AllMessages
: RoomNotifState.MentionsOnly,
room:
value === NotificationDefaultLevels.ALL_MESSAGES
? RoomNotifState.AllMessages
: RoomNotifState.MentionsOnly,
},
})
}
onChange={(value) => {
if (model !== null) {
reconcile({
...model,
defaultLevels: {
...model.defaultLevels,
dm:
value !== NotificationDefaultLevels.MENTIONS_KEYWORDS
? RoomNotifState.AllMessages
: RoomNotifState.MentionsOnly,
room:
value === NotificationDefaultLevels.ALL_MESSAGES
? RoomNotifState.AllMessages
: RoomNotifState.MentionsOnly,
},
});
}
}}
/>
</SettingsSubsection>
<SettingsSubsection
Expand All @@ -173,87 +177,99 @@ export default function NotificationSettings2(): JSX.Element {
label="People"
value={settings.sound.people !== undefined}
disabled={disabled}
onChange={(value) =>
reconcile({
...model,
sound: {
...model.sound,
people: value ? "default" : undefined,
},
})
}
onChange={(value) => {
if (model !== null) {
reconcile({
...model,
sound: {
...model.sound,
people: value ? "default" : undefined,
},
});
}
}}
/>
<LabelledCheckbox
label={_t("Mentions and Keywords")}
value={settings.sound.mentions !== undefined}
disabled={disabled}
onChange={(value) =>
reconcile({
...model,
sound: {
...model.sound,
mentions: value ? "default" : undefined,
},
})
}
onChange={(value) => {
if (model !== null) {
reconcile({
...model,
sound: {
...model.sound,
mentions: value ? "default" : undefined,
},
});
}
}}
/>
<LabelledCheckbox
label={_t("Audio and Video calls")}
value={settings.sound.calls !== undefined}
disabled={disabled}
onChange={(value) =>
reconcile({
...model,
sound: {
...model.sound,
calls: value ? "ring" : undefined,
},
})
}
onChange={(value) => {
if (model !== null) {
reconcile({
...model,
sound: {
...model.sound,
calls: value ? "ring" : undefined,
},
});
}
}}
/>
</SettingsSubsection>
<SettingsSubsection heading={_t("Other things we think you might be interested in:")}>
<LabelledCheckbox
label={_t("Invited to a room")}
value={settings.activity.invite}
disabled={disabled}
onChange={(value) =>
reconcile({
...model,
activity: {
...model.activity,
invite: value,
},
})
}
onChange={(value) => {
if (model !== null) {
reconcile({
...model,
activity: {
...model.activity,
invite: value,
},
});
}
}}
/>
<LabelledCheckbox
label={_t("New room activity, upgrades and status messages occur")}
value={settings.activity.status_event}
disabled={disabled}
onChange={(value) =>
reconcile({
...model,
activity: {
...model.activity,
status_event: value,
},
})
}
onChange={(value) => {
if (model !== null) {
reconcile({
...model,
activity: {
...model.activity,
status_event: value,
},
});
}
}}
/>
<LabelledCheckbox
label={_t("Messages are sent by a bot")}
value={settings.activity.bot_notices}
disabled={disabled}
onChange={(value) =>
reconcile({
...model,
activity: {
...model.activity,
bot_notices: value,
},
})
}
onChange={(value) => {
if (model !== null) {
reconcile({
...model,
activity: {
...model.activity,
bot_notices: value,
},
});
}
}}
/>
</SettingsSubsection>
<SettingsSubsection
Expand All @@ -270,59 +286,69 @@ export default function NotificationSettings2(): JSX.Element {
label={_t("Notify when someone mentions using @room")}
value={settings.mentions.room}
disabled={disabled}
onChange={(value) =>
reconcile({
...model,
mentions: {
...model.mentions,
room: value,
},
})
}
onChange={(value) => {
if (model !== null) {
reconcile({
...model,
mentions: {
...model.mentions,
room: value,
},
});
}
}}
/>
<LabelledCheckbox
label={_t("Notify when someone mentions using @displayname or @mxid")}
value={settings.mentions.user}
disabled={disabled}
onChange={(value) =>
reconcile({
...model,
mentions: {
...model.mentions,
user: value,
},
})
}
onChange={(value) => {
if (model !== null) {
reconcile({
...model,
mentions: {
...model.mentions,
user: value,
},
});
}
}}
/>
<LabelledCheckbox
label={_t("Notify when someone uses a keyword")}
byline={_t("Enter keywords here, or use for spelling variations or nicknames")}
value={settings.mentions.keywords}
disabled={disabled}
onChange={(value) =>
reconcile({
...model,
mentions: {
...model.mentions,
keywords: value,
},
})
}
onChange={(value) => {
if (model !== null) {
reconcile({
...model,
mentions: {
...model.mentions,
keywords: value,
},
});
}
}}
/>
<TagComposer
tags={model?.keywords ?? []}
disabled={disabled}
onAdd={(keyword) => {
reconcile({
...model,
keywords: [keyword, ...model.keywords],
});
if (model !== null) {
reconcile({
...model,
keywords: [keyword, ...model.keywords],
});
}
}}
onRemove={(keyword) => {
reconcile({
...model,
keywords: model.keywords.filter((it) => it !== keyword),
});
if (model !== null) {
reconcile({
...model,
keywords: model.keywords.filter((it) => it !== keyword),
});
}
}}
label={_t("Keyword")}
placeholder={_t("New keyword")}
Expand All @@ -338,7 +364,13 @@ export default function NotificationSettings2(): JSX.Element {
>
{_t("Mark all messages as read")}
</AccessibleButton>
<AccessibleButton kind="danger_outline" onClick={() => reconcile(DefaultNotificationSettings)}>
<AccessibleButton
kind="danger_outline"
onClick={() => {
if (model !== null) {
reconcile(DefaultNotificationSettings);
}
}}>
{_t("Reset to default settings")}
</AccessibleButton>
</SettingsSubsection>
Expand Down

0 comments on commit 9f8a986

Please sign in to comment.