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

64 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-09-24 12:33:12 +00:00
import { unixNowMs } from "@snort/shared";
2023-11-17 11:52:10 +00:00
import useLogin from "@/Hooks/useLogin";
import { updateAppData } from "@/Login";
import { appendDedupe } from "@/SnortUtils";
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
export function ModerationSettings() {
2023-09-24 12:36:51 +00:00
const login = useLogin();
const [muteWord, setMuteWord] = useState("");
2023-09-24 12:33:12 +00:00
2023-09-24 12:36:51 +00:00
function addMutedWord() {
2023-11-13 16:51:29 +00:00
updateAppData(login.id, ad => ({
2023-09-24 12:36:51 +00:00
item: {
2023-11-13 16:51:29 +00:00
...ad,
2023-09-24 12:36:51 +00:00
mutedWords: appendDedupe(login.appData.item.mutedWords, [muteWord]),
},
2023-11-13 16:51:29 +00:00
timestamp: unixNowMs(),
}));
2023-09-24 12:36:51 +00:00
setMuteWord("");
}
function removeMutedWord(word: string) {
2023-11-13 16:51:29 +00:00
updateAppData(login.id, ad => ({
item: {
...ad,
mutedWords: login.appData.item.mutedWords.filter(a => a !== word),
},
2023-11-13 16:51:29 +00:00
timestamp: unixNowMs(),
}));
setMuteWord("");
}
2023-09-24 12:36:51 +00:00
return (
<>
<h2>
<FormattedMessage defaultMessage="Muted Words" id="AN0Z7Q" />
2023-09-24 12:36:51 +00:00
</h2>
<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>
2023-09-24 12:36:51 +00:00
{login.appData.item.mutedWords.map(v => (
<div 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
);
}