-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d93817
commit 9d5a9f8
Showing
6 changed files
with
109 additions
and
15 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { deepFreeze } from '../../utils/deepFreeze'; | ||
|
||
export const SettingsSchemaVersion = 1; | ||
|
||
export enum PushNotificationSound { | ||
default = 'Default', | ||
chime = 'Chime', | ||
special_chime_f1 = 'Chime (1)', // The f1 radio chime | ||
special_chime_otv = 'Chime (2)', // OfflineTV's chime | ||
none = 'None', | ||
} | ||
|
||
export type UserSettingsSchema = { | ||
pushNotificationsGlobal: boolean; | ||
pushNotificationsSound: PushNotificationSound; | ||
pushNotifications: { | ||
upcomingMatches: boolean; | ||
allianceSelection: boolean; | ||
matchScorePublish: boolean; | ||
upcomingScouting: boolean; | ||
pageNotifications: boolean; | ||
accountNotifications: boolean; | ||
}; | ||
darkMode: boolean; | ||
_meta: { | ||
version: number; // Schema version. Increment when changing schema. | ||
}; | ||
}; | ||
|
||
export const DefaultUserSettings: Readonly<UserSettingsSchema> = { | ||
pushNotificationsGlobal: true, | ||
pushNotificationsSound: PushNotificationSound.default, | ||
pushNotifications: { | ||
upcomingMatches: true, | ||
allianceSelection: true, | ||
matchScorePublish: true, | ||
upcomingScouting: true, | ||
pageNotifications: true, | ||
accountNotifications: true, | ||
}, | ||
darkMode: false, | ||
_meta: { | ||
version: SettingsSchemaVersion, | ||
}, | ||
}; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
deepFreeze(DefaultUserSettings); | ||
|
||
// Check that DefaultUserSettings is actually immutable | ||
DefaultUserSettings.pushNotifications.upcomingMatches = false; | ||
if (!DefaultUserSettings.pushNotifications.upcomingMatches) { | ||
throw new Error('DefaultUserSettings is not immutable!'); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function deepFreeze<T>(object: T): Readonly<T> { | ||
// Retrieve the property names defined on object | ||
const propNames = Object.getOwnPropertyNames(object); | ||
|
||
// Freeze properties before freezing self | ||
for (const name of propNames) { | ||
// @ts-expect-error | ||
const value = object[name]; | ||
|
||
if ((value && typeof value === 'object') || typeof value === 'function') { | ||
deepFreeze(value); | ||
} | ||
} | ||
|
||
return Object.freeze(object); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.