From 02a81213a21a1d7ee378458f5f3ff13eb6fb627c Mon Sep 17 00:00:00 2001 From: enes Date: Tue, 19 Nov 2024 16:23:42 +0100 Subject: [PATCH] refactor(wot): update redux wot level if admin wot npub changes level --- src/hooks/useFilteredMods.ts | 1 + src/pages/settings/preference.tsx | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/hooks/useFilteredMods.ts b/src/hooks/useFilteredMods.ts index fd64adb..5530b0d 100644 --- a/src/hooks/useFilteredMods.ts +++ b/src/hooks/useFilteredMods.ts @@ -123,6 +123,7 @@ export const useFilteredMods = ( return filtered }, [ + userState.auth, userState.user?.npub, filterOptions.sort, filterOptions.moderated, diff --git a/src/pages/settings/preference.tsx b/src/pages/settings/preference.tsx index cb41186..69e3d12 100644 --- a/src/pages/settings/preference.tsx +++ b/src/pages/settings/preference.tsx @@ -4,9 +4,9 @@ import { useAppDispatch, useAppSelector, useNDKContext } from 'hooks' import { kinds, UnsignedEvent, Event } from 'nostr-tools' import { useEffect, useState } from 'react' import { toast } from 'react-toastify' -import { setUserWotLevel } from 'store/reducers/wot' +import { setSiteWotLevel, setUserWotLevel } from 'store/reducers/wot' import { UserRelaysType } from 'types' -import { log, LogType, now } from 'utils' +import { log, LogType, now, npubToHex } from 'utils' // todo: use components from Input.tsx export const PreferencesSetting = () => { @@ -92,6 +92,13 @@ export const PreferencesSetting = () => { ) dispatch(setUserWotLevel(wotLevel)) + + // If wot admin, update site wot level too + const SITE_WOT_NPUB = import.meta.env.VITE_SITE_WOT_NPUB + const siteWotPubkey = npubToHex(SITE_WOT_NPUB) + if (siteWotPubkey === hexPubkey) { + dispatch(setSiteWotLevel(wotLevel)) + } }) .catch((err) => { console.error(err)