fix: hide mods from latest mods section in homepage that admin/user adds to mute list
All checks were successful
Release to Staging / build_and_release (push) Successful in 47s

This commit is contained in:
daniyal 2024-09-30 15:13:57 +05:00
parent 3b2e899c14
commit 3ff4437d44

View File

@ -8,7 +8,7 @@ import { GameCard } from '../components/GameCard'
import { ModCard } from '../components/ModCard' import { ModCard } from '../components/ModCard'
import { LANDING_PAGE_DATA } from '../constants' import { LANDING_PAGE_DATA } from '../constants'
import { RelayController } from '../controllers' import { RelayController } from '../controllers'
import { useDidMount, useGames } from '../hooks' import { useDidMount, useGames, useMuteLists } from '../hooks'
import { appRoutes, getModPageRoute } from '../routes' import { appRoutes, getModPageRoute } from '../routes'
import { ModDetails } from '../types' import { ModDetails } from '../types'
import { import {
@ -258,12 +258,12 @@ const DisplayLatestMods = () => {
const [isFetchingLatestMods, setIsFetchingLatestMods] = useState(true) const [isFetchingLatestMods, setIsFetchingLatestMods] = useState(true)
const [latestMods, setLatestMods] = useState<ModDetails[]>([]) const [latestMods, setLatestMods] = useState<ModDetails[]>([])
const muteLists = useMuteLists()
useDidMount(() => { useDidMount(() => {
fetchMods({ source: window.location.host }) fetchMods({ source: window.location.host })
.then((res) => { .then((res) => {
const mods = res const mods = res.sort((a, b) => b.published_at - a.published_at)
.sort((a, b) => b.published_at - a.published_at)
.slice(0, 4)
setLatestMods(mods) setLatestMods(mods)
}) })
.finally(() => { .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 ( return (
<div className='IBMSecMain IBMSMListWrapper'> <div className='IBMSecMain IBMSMListWrapper'>
<div className='IBMSMTitleMain'> <div className='IBMSMTitleMain'>
@ -280,7 +295,7 @@ const DisplayLatestMods = () => {
{isFetchingLatestMods ? ( {isFetchingLatestMods ? (
<Spinner /> <Spinner />
) : ( ) : (
latestMods.map((mod) => { filteredMods.map((mod) => {
return <ModCard key={mod.id} {...mod} /> return <ModCard key={mod.id} {...mod} />
}) })
)} )}