Remove setting, add persistence

This commit is contained in:
binwiederhier 2023-07-08 15:14:35 -04:00
parent ce01a66ff3
commit b7679c7826
6 changed files with 60 additions and 67 deletions

View file

@ -359,9 +359,6 @@
"prefs_appearance_theme_system": "System (default)",
"prefs_appearance_theme_dark": "Dark mode",
"prefs_appearance_theme_light": "Light mode",
"prefs_appearance_markdown_always_enabled_title": "Format all messages as Markdown",
"prefs_appearance_markdown_always_enabled_on": "Enabled",
"prefs_appearance_markdown_always_enabled_off": "Disabled",
"prefs_reservations_title": "Reserved topics",
"prefs_reservations_description": "You can reserve topic names for personal use here. Reserving a topic gives you ownership over the topic, and allows you to define access permissions for other users over the topic.",
"prefs_reservations_limit_reached": "You reached your reserved topics limit.",

View file

@ -55,15 +55,6 @@ class Prefs {
async setTheme(mode) {
await this.db.prefs.put({ key: "theme", value: mode });
}
async markdownAlwaysEnabled() {
const record = await this.db.prefs.get("markdownAlwaysEnabled");
return record?.value ?? false;
}
async setMarkdownAlwaysEnabled(enabled) {
await this.db.prefs.put({ key: "markdownAlwaysEnabled", value: enabled });
}
}
const prefs = new Prefs(db());

View file

@ -192,6 +192,10 @@ const MarkdownContainer = styled("div")`
ol {
padding-inline: 1rem;
}
img {
max-width: 100%;
}
`;
const MarkdownContent = ({ content }) => {
@ -205,17 +209,11 @@ const MarkdownContent = ({ content }) => {
};
const NotificationBody = ({ notification }) => {
const markdownAlwaysEnabled = useLiveQuery(async () => prefs.markdownAlwaysEnabled());
// TODO: check notification content-type when implemented on the server
const displayAsMarkdown = markdownAlwaysEnabled;
const displayAsMarkdown = notification.content_type === "text/markdown";
const formatted = formatMessage(notification);
if (displayAsMarkdown) {
return <MarkdownContent content={formatted} />;
}
return autolink(formatted);
};

View file

@ -259,26 +259,6 @@ const Theme = () => {
);
};
const MarkdownAlwaysEnabled = () => {
const { t } = useTranslation();
const labelId = "prefMarkdown";
const enabled = useLiveQuery(async () => prefs.markdownAlwaysEnabled());
const handleChange = async (ev) => {
await prefs.setMarkdownAlwaysEnabled(ev.target.value);
};
return (
<Pref labelId={labelId} title={t("prefs_appearance_markdown_always_enabled_title")}>
<FormControl fullWidth variant="standard" sx={{ m: 1 }}>
<Select value={enabled ?? false} onChange={handleChange} aria-labelledby={labelId}>
<MenuItem value>{t("prefs_appearance_markdown_always_enabled_on")}</MenuItem>
<MenuItem value={false}>{t("prefs_appearance_markdown_always_enabled_off")}</MenuItem>
</Select>
</FormControl>
</Pref>
);
};
const WebPushEnabled = () => {
const { t } = useTranslation();
const labelId = "prefWebPushEnabled";
@ -533,7 +513,6 @@ const Appearance = () => {
<PrefGroup>
<Theme />
<Language />
<MarkdownAlwaysEnabled />
</PrefGroup>
</Card>
);