From 3ff4437d4486b51c72d85a3fca36fc0066b0e8ea Mon Sep 17 00:00:00 2001 From: daniyal Date: Mon, 30 Sep 2024 15:13:57 +0500 Subject: [PATCH] fix: hide mods from latest mods section in homepage that admin/user adds to mute list --- src/pages/home.tsx | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/pages/home.tsx b/src/pages/home.tsx index f432d51..9b204dc 100644 --- a/src/pages/home.tsx +++ b/src/pages/home.tsx @@ -8,7 +8,7 @@ import { GameCard } from '../components/GameCard' import { ModCard } from '../components/ModCard' import { LANDING_PAGE_DATA } from '../constants' import { RelayController } from '../controllers' -import { useDidMount, useGames } from '../hooks' +import { useDidMount, useGames, useMuteLists } from '../hooks' import { appRoutes, getModPageRoute } from '../routes' import { ModDetails } from '../types' import { @@ -258,12 +258,12 @@ const DisplayLatestMods = () => { const [isFetchingLatestMods, setIsFetchingLatestMods] = useState(true) const [latestMods, setLatestMods] = useState([]) + const muteLists = useMuteLists() + useDidMount(() => { fetchMods({ source: window.location.host }) .then((res) => { - const mods = res - .sort((a, b) => b.published_at - a.published_at) - .slice(0, 4) + const mods = res.sort((a, b) => b.published_at - a.published_at) setLatestMods(mods) }) .finally(() => { @@ -271,6 +271,21 @@ const DisplayLatestMods = () => { }) }) + const filteredMods = useMemo(() => { + const mutedAuthors = [...muteLists.admin.authors, ...muteLists.user.authors] + const mutedEvents = [ + ...muteLists.admin.replaceableEvents, + ...muteLists.user.replaceableEvents + ] + + const filtered = latestMods.filter( + (mod) => + !mutedAuthors.includes(mod.author) && !mutedEvents.includes(mod.aTag) + ) + + return filtered.slice(0, 4) + }, [muteLists, latestMods]) + return (
@@ -280,7 +295,7 @@ const DisplayLatestMods = () => { {isFetchingLatestMods ? ( ) : ( - latestMods.map((mod) => { + filteredMods.map((mod) => { return }) )}