* remove shift from editor hotkeys * fix inline markdown not working * add block md parser - WIP * emojify and linkify text without react-parser * no need to sanitize text when emojify * parse block markdown in editor output - WIP * add inline parser option in block md parser * improve codeblock regex * ignore html tag when parsing inline md in block md * add list markdown rule in block parser * re-generate block markdown on edit * change copy from inline markdown to markdown * fix trim reply from body regex * fix jumbo emoji in reply message * fix broken list regex in block markdown * enable markdown by defualt
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
import { atom } from 'jotai';
|
|
|
|
const STORAGE_KEY = 'settings';
|
|
export type MessageSpacing = '0' | '100' | '200' | '300' | '400' | '500';
|
|
export type MessageLayout = 0 | 1 | 2;
|
|
|
|
export interface Settings {
|
|
themeIndex: number;
|
|
useSystemTheme: boolean;
|
|
isMarkdown: boolean;
|
|
editorToolbar: boolean;
|
|
twitterEmoji: boolean;
|
|
|
|
isPeopleDrawer: boolean;
|
|
memberSortFilterIndex: number;
|
|
enterForNewline: boolean;
|
|
messageLayout: MessageLayout;
|
|
messageSpacing: MessageSpacing;
|
|
hideMembershipEvents: boolean;
|
|
hideNickAvatarEvents: boolean;
|
|
mediaAutoLoad: boolean;
|
|
showHiddenEvents: boolean;
|
|
|
|
showNotifications: boolean;
|
|
isNotificationSounds: boolean;
|
|
}
|
|
|
|
const defaultSettings: Settings = {
|
|
themeIndex: 0,
|
|
useSystemTheme: true,
|
|
isMarkdown: true,
|
|
editorToolbar: false,
|
|
twitterEmoji: false,
|
|
|
|
isPeopleDrawer: true,
|
|
memberSortFilterIndex: 0,
|
|
enterForNewline: false,
|
|
messageLayout: 0,
|
|
messageSpacing: '400',
|
|
hideMembershipEvents: false,
|
|
hideNickAvatarEvents: true,
|
|
mediaAutoLoad: true,
|
|
showHiddenEvents: false,
|
|
|
|
showNotifications: true,
|
|
isNotificationSounds: true,
|
|
};
|
|
|
|
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>(
|
|
(get) => get(baseSettings),
|
|
(get, set, update) => {
|
|
set(baseSettings, update);
|
|
setSettings(update);
|
|
}
|
|
);
|