2023-09-24 12:33:12 +00:00
|
|
|
import { unixNowMs } from "@snort/shared";
|
|
|
|
import useLogin from "Hooks/useLogin";
|
2023-11-13 16:51:29 +00:00
|
|
|
import { updateAppData } from "Login";
|
2023-09-24 12:33:12 +00:00
|
|
|
import { appendDedupe } from "SnortUtils";
|
|
|
|
import { useState } from "react";
|
2023-10-17 13:02:59 +00:00
|
|
|
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("");
|
|
|
|
}
|
2023-10-17 13:02:59 +00:00
|
|
|
|
|
|
|
function removeMutedWord(word: string) {
|
2023-11-13 16:51:29 +00:00
|
|
|
updateAppData(login.id, ad => ({
|
|
|
|
item: {
|
|
|
|
...ad,
|
2023-10-17 13:02:59 +00:00
|
|
|
mutedWords: login.appData.item.mutedWords.filter(a => a !== word),
|
|
|
|
},
|
2023-11-13 16:51:29 +00:00
|
|
|
timestamp: unixNowMs(),
|
|
|
|
}));
|
2023-10-17 13:02:59 +00:00
|
|
|
setMuteWord("");
|
|
|
|
}
|
|
|
|
|
2023-09-24 12:36:51 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h2>
|
|
|
|
<FormattedMessage defaultMessage="Muted Words" />
|
|
|
|
</h2>
|
2023-10-17 13:02:59 +00:00
|
|
|
<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}
|
2023-10-17 13:02:59 +00:00
|
|
|
onChange={e => setMuteWord(e.target.value.toLowerCase())}
|
2023-09-24 12:36:51 +00:00
|
|
|
/>
|
|
|
|
<button type="button" onClick={addMutedWord}>
|
|
|
|
<FormattedMessage defaultMessage="Add" />
|
|
|
|
</button>
|
2023-09-24 12:33:12 +00:00
|
|
|
</div>
|
2023-09-24 12:36:51 +00:00
|
|
|
{login.appData.item.mutedWords.map(v => (
|
2023-10-17 13:02:59 +00:00
|
|
|
<div className="p br b flex items-center justify-between">
|
2023-09-24 12:36:51 +00:00
|
|
|
<div>{v}</div>
|
2023-10-17 13:02:59 +00:00
|
|
|
<button type="button" onClick={() => removeMutedWord(v)}>
|
2023-09-24 12:36:51 +00:00
|
|
|
<FormattedMessage defaultMessage="Delete" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-09-24 12:33:12 +00:00
|
|
|
</>
|
2023-09-24 12:36:51 +00:00
|
|
|
);
|
|
|
|
}
|