mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-27 20:36:27 -08:00
146 lines
3.5 KiB
TypeScript
146 lines
3.5 KiB
TypeScript
import { atom } from 'jotai';
|
|
|
|
const STORAGE_KEY = 'settings';
|
|
export type DateFormat = 'D MMM YYYY' | 'DD/MM/YYYY' | 'MM/DD/YYYY' | 'YYYY/MM/DD' | '';
|
|
export type MessageSpacing = '0' | '100' | '200' | '300' | '400' | '500';
|
|
export enum MessageLayout {
|
|
Modern = 0,
|
|
Compact = 1,
|
|
Bubble = 2,
|
|
}
|
|
|
|
export enum RightSwipeAction {
|
|
Members = 'members',
|
|
Reply = 'reply',
|
|
}
|
|
|
|
export type JumboEmojiSize = 'none' | 'extraSmall' | 'small' | 'normal' | 'large' | 'extraLarge';
|
|
|
|
export interface Settings {
|
|
themeId?: string;
|
|
useSystemTheme: boolean;
|
|
lightThemeId?: string;
|
|
darkThemeId?: string;
|
|
monochromeMode?: boolean;
|
|
uniformIcons: boolean;
|
|
isMarkdown: boolean;
|
|
editorToolbar: boolean;
|
|
twitterEmoji: boolean;
|
|
pageZoom: number;
|
|
hideActivity: boolean;
|
|
|
|
isPeopleDrawer: boolean;
|
|
isWidgetDrawer: boolean;
|
|
memberSortFilterIndex: number;
|
|
enterForNewline: boolean;
|
|
messageLayout: MessageLayout;
|
|
messageSpacing: MessageSpacing;
|
|
hideMembershipEvents: boolean;
|
|
hideNickAvatarEvents: boolean;
|
|
mediaAutoLoad: boolean;
|
|
urlPreview: boolean;
|
|
encUrlPreview: boolean;
|
|
showHiddenEvents: boolean;
|
|
legacyUsernameColor: boolean;
|
|
|
|
usePushNotifications: boolean;
|
|
useInAppNotifications: boolean;
|
|
isNotificationSounds: boolean;
|
|
showMessageContentInNotifications: boolean;
|
|
showMessageContentInEncryptedNotifications: boolean;
|
|
|
|
hour24Clock: boolean;
|
|
dateFormatString: string;
|
|
|
|
developerTools: boolean;
|
|
|
|
// Cosmetics!
|
|
jumboEmojiSize: JumboEmojiSize;
|
|
privacyBlur: boolean;
|
|
privacyBlurAvatars: boolean;
|
|
privacyBlurEmotes: boolean;
|
|
showPronouns: boolean;
|
|
renderGlobalNameColors: boolean;
|
|
|
|
// Sable features!
|
|
mobileGestures: boolean;
|
|
rightSwipeAction: RightSwipeAction;
|
|
hideMembershipInReadOnly: boolean;
|
|
useRightBubbles: boolean;
|
|
}
|
|
|
|
const defaultSettings: Settings = {
|
|
themeId: undefined,
|
|
useSystemTheme: true,
|
|
lightThemeId: undefined,
|
|
darkThemeId: undefined,
|
|
monochromeMode: false,
|
|
uniformIcons: false,
|
|
isMarkdown: true,
|
|
editorToolbar: false,
|
|
twitterEmoji: true,
|
|
pageZoom: 100,
|
|
hideActivity: false,
|
|
|
|
isPeopleDrawer: true,
|
|
isWidgetDrawer: false,
|
|
memberSortFilterIndex: 0,
|
|
enterForNewline: false,
|
|
messageLayout: 0,
|
|
messageSpacing: '400',
|
|
hideMembershipEvents: false,
|
|
hideNickAvatarEvents: true,
|
|
mediaAutoLoad: true,
|
|
urlPreview: true,
|
|
encUrlPreview: false,
|
|
showHiddenEvents: false,
|
|
legacyUsernameColor: false,
|
|
|
|
usePushNotifications: false,
|
|
useInAppNotifications: true,
|
|
isNotificationSounds: true,
|
|
showMessageContentInNotifications: false,
|
|
showMessageContentInEncryptedNotifications: false,
|
|
|
|
hour24Clock: false,
|
|
dateFormatString: 'D MMM YYYY',
|
|
|
|
developerTools: false,
|
|
|
|
// Cosmetics!
|
|
jumboEmojiSize: 'normal',
|
|
privacyBlur: false,
|
|
privacyBlurAvatars: false,
|
|
privacyBlurEmotes: false,
|
|
showPronouns: true,
|
|
renderGlobalNameColors: true,
|
|
|
|
// Sable features!
|
|
mobileGestures: true,
|
|
rightSwipeAction: RightSwipeAction.Reply,
|
|
hideMembershipInReadOnly: true,
|
|
useRightBubbles: false,
|
|
};
|
|
|
|
export const getSettings = () => {
|
|
const settings = localStorage.getItem(STORAGE_KEY);
|
|
if (settings === null) return defaultSettings;
|
|
return {
|
|
...defaultSettings,
|
|
...(JSON.parse(settings) as Settings),
|
|
};
|
|
};
|
|
|
|
export const setSettings = (settings: Settings) => {
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
|
|
};
|
|
|
|
const baseSettings = atom<Settings>(getSettings());
|
|
export const settingsAtom = atom<Settings, [Settings], undefined>(
|
|
(get) => get(baseSettings),
|
|
(get, set, update) => {
|
|
set(baseSettings, update);
|
|
setSettings(update);
|
|
}
|
|
);
|