From 994382f39cbbfd7bc1758549acaa8d8a72c2bd68 Mon Sep 17 00:00:00 2001 From: enes Date: Wed, 20 Nov 2024 12:27:41 +0100 Subject: [PATCH] fix(wot): add exclude and fix wot dropdown --- src/components/ModsFilter.tsx | 9 +++++---- src/hooks/useFilteredMods.ts | 6 ++++++ src/types/modsFilter.ts | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/ModsFilter.tsx b/src/components/ModsFilter.tsx index 6e0342d..8d733c7 100644 --- a/src/components/ModsFilter.tsx +++ b/src/components/ModsFilter.tsx @@ -125,18 +125,19 @@ export const ModFilter = React.memo( // when logged in user not admin if ( item === WOTFilterOptions.None || - item === WOTFilterOptions.Mine_Only + item === WOTFilterOptions.Mine_Only || + item === WOTFilterOptions.Exclude ) { - const isAdmin = + const isWoTNpub = userState.user?.npub === - import.meta.env.VITE_REPORTING_NPUB + import.meta.env.VITE_SITE_WOT_NPUB const isOwnProfile = author && userState.auth && userState.user?.pubkey === author - if (!(isAdmin || isOwnProfile)) return null + if (!(isWoTNpub || isOwnProfile)) return null } return ( diff --git a/src/hooks/useFilteredMods.ts b/src/hooks/useFilteredMods.ts index 5530b0d..7c16b18 100644 --- a/src/hooks/useFilteredMods.ts +++ b/src/hooks/useFilteredMods.ts @@ -68,6 +68,12 @@ export const useFilteredMods = ( return isWoTNpub ? mods : mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author)) + case WOTFilterOptions.Exclude: + // Only admins can choose Exlude, use siteWot for others + // Exlude returns the mods not in the site's WoT + return isWoTNpub + ? mods.filter((mod) => !isInWoT(siteWot, siteWotLevel, mod.author)) + : mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author)) case WOTFilterOptions.Site_Only: return mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author) diff --git a/src/types/modsFilter.ts b/src/types/modsFilter.ts index 3752caf..b0ae63b 100644 --- a/src/types/modsFilter.ts +++ b/src/types/modsFilter.ts @@ -21,7 +21,8 @@ export enum WOTFilterOptions { Site_And_Mine = 'Site & Mine', Site_Only = 'Site Only', Mine_Only = 'Mine Only', - None = 'None' + None = 'None', + Exclude = 'Exclude' } export interface FilterOptions {