fix: muted words
This commit is contained in:
parent
08d4a73ca6
commit
a17c98ad25
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,4 +12,5 @@ dist/
|
||||
*.log
|
||||
.DS_Store
|
||||
.pnp*
|
||||
docs/
|
||||
docs/
|
||||
.wranger/
|
@ -63,7 +63,8 @@
|
||||
"test:watch": "vitest watch",
|
||||
"intl-extract": "formatjs extract 'src/**/*.ts*' --ignore='**/*.d.ts' --out-file src/lang.json --flatten true",
|
||||
"intl-compile": "formatjs compile src/lang.json --out-file src/translations/en.json",
|
||||
"eslint": "eslint ."
|
||||
"eslint": "eslint .",
|
||||
"deploy:meku": "NODE_CONFIG_ENV=meku yarn workspace @snort/app build && npx wrangler pages deploy --project-name meku build/"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
|
@ -42,8 +42,12 @@ export default function useModeration() {
|
||||
return words.includes(word);
|
||||
}
|
||||
|
||||
async function addMutedWord(word: string) {
|
||||
await state.addToList(EventKind.MuteList, new MutedWordTag(word.toLowerCase()), true);
|
||||
async function addMutedWord(word: string | Array<string>) {
|
||||
const words = Array.isArray(word) ? word : [word];
|
||||
for (const w of words) {
|
||||
await state.addToList(EventKind.MuteList, new MutedWordTag(w.toLowerCase()), false);
|
||||
}
|
||||
await state.saveList(EventKind.MuteList);
|
||||
}
|
||||
|
||||
async function removeMutedWord(word: string) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { DefaultPreferences, updateAppData, UserPreferences } from "@/Utils/Login";
|
||||
|
||||
import useEventPublisher from "./useEventPublisher";
|
||||
import useLogin from "./useLogin";
|
||||
|
||||
export default function usePreferences<T = UserPreferences>(selector?: (v: UserPreferences) => T): T {
|
||||
@ -27,12 +26,10 @@ export function useAllPreferences() {
|
||||
pref: pref,
|
||||
};
|
||||
});
|
||||
const { system } = useEventPublisher();
|
||||
|
||||
return {
|
||||
preferences: pref,
|
||||
update: async (data: UserPreferences) => {
|
||||
await updateAppData(id, system, d => {
|
||||
await updateAppData(id, d => {
|
||||
return { ...d, preferences: data };
|
||||
});
|
||||
},
|
||||
|
@ -4,18 +4,15 @@ import { useNavigate } from "react-router-dom";
|
||||
|
||||
import AsyncButton from "@/Components/Button/AsyncButton";
|
||||
import { ToggleSwitch } from "@/Components/Icons/Toggle";
|
||||
import useEventPublisher from "@/Hooks/useEventPublisher";
|
||||
import useLogin from "@/Hooks/useLogin";
|
||||
import useModeration from "@/Hooks/useModeration";
|
||||
import { FixedModeration } from "@/Pages/onboarding/fixedModeration";
|
||||
import { appendDedupe } from "@/Utils";
|
||||
import { updateAppData } from "@/Utils/Login";
|
||||
|
||||
export function Moderation() {
|
||||
const id = useLogin(s => s.id);
|
||||
const [topics, setTopics] = useState<Array<string>>(Object.keys(FixedModeration));
|
||||
const [extraTerms, setExtraTerms] = useState("");
|
||||
const navigate = useNavigate();
|
||||
const { system } = useEventPublisher();
|
||||
const { addMutedWord } = useModeration();
|
||||
|
||||
return (
|
||||
<div className="flex flex-col g24">
|
||||
@ -82,10 +79,7 @@ export function Moderation() {
|
||||
.filter(a => a.length > 1),
|
||||
);
|
||||
if (words.length > 0) {
|
||||
updateAppData(id, system, ad => ({
|
||||
...ad,
|
||||
mutedWords: appendDedupe(ad.mutedWords, words),
|
||||
}));
|
||||
await addMutedWord(words);
|
||||
}
|
||||
navigate("/");
|
||||
}}>
|
||||
|
@ -336,6 +336,20 @@ export class MultiAccountStore extends ExternalStore<LoginSession> {
|
||||
delete acc["tags"];
|
||||
didMigrate = true;
|
||||
}
|
||||
if (acc.state.appdata) {
|
||||
if ("id" in acc.state.appdata) {
|
||||
delete acc.state.appdata["id"];
|
||||
didMigrate = true;
|
||||
}
|
||||
if ("mutedWords" in acc.state.appdata) {
|
||||
delete acc.state.appdata["mutedWords"];
|
||||
didMigrate = true;
|
||||
}
|
||||
if ("showContentWarningPosts" in acc.state.appdata) {
|
||||
delete acc.state.appdata["showContentWarningPosts"];
|
||||
didMigrate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (didMigrate) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user