snort/packages/app/src/Pages/settings/Moderation.tsx

87 lines
2.6 KiB
TypeScript
Raw Normal View History

2023-09-24 12:33:12 +00:00
import { useState } from "react";
import { FormattedMessage } from "react-intl";
2023-09-24 12:33:12 +00:00
2024-04-15 12:23:26 +00:00
import useEventPublisher from "@/Hooks/useEventPublisher";
2024-01-04 17:01:18 +00:00
import useLogin from "@/Hooks/useLogin";
import { appendDedupe } from "@/Utils";
import { SnortAppData, updateAppData } from "@/Utils/Login";
export default function ModerationSettingsPage() {
2023-09-24 12:36:51 +00:00
const login = useLogin();
const [muteWord, setMuteWord] = useState("");
2024-04-15 12:23:26 +00:00
const appData = login.appData.json;
const { system } = useEventPublisher();
2023-09-24 12:33:12 +00:00
2023-09-24 12:36:51 +00:00
function addMutedWord() {
2024-04-15 12:23:26 +00:00
updateAppData(login.id, system, ad => ({
...ad,
mutedWords: appendDedupe(appData.mutedWords, [muteWord]),
2023-11-13 16:51:29 +00:00
}));
2023-09-24 12:36:51 +00:00
setMuteWord("");
}
const handleToggle = (setting: keyof SnortAppData) => {
2024-04-15 12:23:26 +00:00
updateAppData(login.id, system, ad => ({
...ad,
[setting]: !appData[setting],
}));
};
function removeMutedWord(word: string) {
2024-04-15 12:23:26 +00:00
updateAppData(login.id, system, ad => ({
...ad,
mutedWords: appData.mutedWords.filter(a => a !== word),
2023-11-13 16:51:29 +00:00
}));
setMuteWord("");
}
2023-09-24 12:36:51 +00:00
return (
<>
<h2>
<FormattedMessage defaultMessage="Moderation" id="wofVHy" />
2023-09-24 12:36:51 +00:00
</h2>
<div className="py-4 flex flex-col gap-2">
<div className="flex items-center mb-2">
<input
type="checkbox"
checked={appData.showContentWarningPosts}
onChange={() => handleToggle("showContentWarningPosts")}
className="mr-2"
id="showContentWarningPosts"
/>
<label htmlFor="showContentWarningPosts">
<FormattedMessage defaultMessage="Show posts that have a content warning tag" id="fQN+tq" />
</label>
</div>
</div>
<h3>
<FormattedMessage defaultMessage="Muted Words" id="AN0Z7Q" />
</h3>
<div className="flex flex-col g12">
2023-09-24 12:36:51 +00:00
<div className="flex g8">
<input
type="text"
placeholder="eg. crypto"
className="w-max"
value={muteWord}
onChange={e => setMuteWord(e.target.value.toLowerCase())}
2023-09-24 12:36:51 +00:00
/>
<button type="button" onClick={addMutedWord}>
<FormattedMessage defaultMessage="Add" id="2/2yg+" />
2023-09-24 12:36:51 +00:00
</button>
2023-09-24 12:33:12 +00:00
</div>
{appData.mutedWords.map(v => (
2024-01-04 09:54:58 +00:00
<div key={v} className="p br b flex items-center justify-between">
2023-09-24 12:36:51 +00:00
<div>{v}</div>
<button type="button" onClick={() => removeMutedWord(v)}>
<FormattedMessage defaultMessage="Delete" id="K3r6DQ" />
2023-09-24 12:36:51 +00:00
</button>
</div>
))}
</div>
2023-09-24 12:33:12 +00:00
</>
2023-09-24 12:36:51 +00:00
);
}