mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-04 22:40:29 +03:00
* Add setting to enable 24-hour time format * added hour24Clock to TimeProps * Add incomplete dateFormatString setting * Move 24-hour toggle to Appearance * Add "Date & Time" subheading, cleanup after merge * Add setting for date formatting * Fix minor formatting and naming issues * Document functions * adress most comments * add hint for date formatting * add support for 24hr time to TimePicker * prevent overflow on small displays
98 lines
2.3 KiB
TypeScript
98 lines
2.3 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 interface Settings {
|
|
themeId?: string;
|
|
useSystemTheme: boolean;
|
|
lightThemeId?: string;
|
|
darkThemeId?: string;
|
|
isMarkdown: boolean;
|
|
editorToolbar: boolean;
|
|
twitterEmoji: boolean;
|
|
pageZoom: number;
|
|
hideActivity: boolean;
|
|
|
|
isPeopleDrawer: boolean;
|
|
memberSortFilterIndex: number;
|
|
enterForNewline: boolean;
|
|
messageLayout: MessageLayout;
|
|
messageSpacing: MessageSpacing;
|
|
hideMembershipEvents: boolean;
|
|
hideNickAvatarEvents: boolean;
|
|
mediaAutoLoad: boolean;
|
|
urlPreview: boolean;
|
|
encUrlPreview: boolean;
|
|
showHiddenEvents: boolean;
|
|
legacyUsernameColor: boolean;
|
|
|
|
showNotifications: boolean;
|
|
isNotificationSounds: boolean;
|
|
|
|
hour24Clock: boolean;
|
|
dateFormatString: string;
|
|
|
|
developerTools: boolean;
|
|
}
|
|
|
|
const defaultSettings: Settings = {
|
|
themeId: undefined,
|
|
useSystemTheme: true,
|
|
lightThemeId: undefined,
|
|
darkThemeId: undefined,
|
|
isMarkdown: true,
|
|
editorToolbar: false,
|
|
twitterEmoji: false,
|
|
pageZoom: 100,
|
|
hideActivity: false,
|
|
|
|
isPeopleDrawer: true,
|
|
memberSortFilterIndex: 0,
|
|
enterForNewline: false,
|
|
messageLayout: 0,
|
|
messageSpacing: '400',
|
|
hideMembershipEvents: false,
|
|
hideNickAvatarEvents: true,
|
|
mediaAutoLoad: true,
|
|
urlPreview: true,
|
|
encUrlPreview: false,
|
|
showHiddenEvents: false,
|
|
legacyUsernameColor: false,
|
|
|
|
showNotifications: true,
|
|
isNotificationSounds: true,
|
|
|
|
hour24Clock: false,
|
|
dateFormatString: 'D MMM YYYY',
|
|
|
|
developerTools: 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);
|
|
}
|
|
);
|