diff --git a/src/hooks/index.ts b/src/hooks/index.ts index e0f6038..7746976 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -4,6 +4,7 @@ export * from './useFilteredMods' export * from './useGames' export * from './useMuteLists' export * from './useNSFWList' +export * from './useRepostList' export * from './useReactions' export * from './useNDKContext' export * from './useScrollDisable' diff --git a/src/hooks/useRepostList.tsx b/src/hooks/useRepostList.tsx new file mode 100644 index 0000000..605bc8d --- /dev/null +++ b/src/hooks/useRepostList.tsx @@ -0,0 +1,19 @@ +import { useState } from 'react' +import { useDidMount } from './useDidMount' +import { useNDKContext } from './useNDKContext' +import { CurationSetIdentifiers, getReportingSet } from 'utils' + +export const useRepostList = () => { + const ndkContext = useNDKContext() + const [repostList, setRepostList] = useState([]) + + useDidMount(async () => { + const list = await getReportingSet( + CurationSetIdentifiers.Repost, + ndkContext + ) + setRepostList(list) + }) + + return repostList +} diff --git a/src/pages/home.tsx b/src/pages/home.tsx index ef3d845..1879f28 100644 --- a/src/pages/home.tsx +++ b/src/pages/home.tsx @@ -14,7 +14,8 @@ import { useLocalStorage, useMuteLists, useNDKContext, - useNSFWList + useNSFWList, + useRepostList } from '../hooks' import { appRoutes, getModPageRoute } from '../routes' import { BlogCardDetails, ModDetails, NSFWFilter, SortBy } from '../types' @@ -257,18 +258,14 @@ const DisplayLatestMods = () => { const muteLists = useMuteLists() const nsfwList = useNSFWList() + const repostList = useRepostList() useDidMount(() => { fetchMods({ source: window.location.host }) .then((mods) => { // Sort by the latest (published_at descending) mods.sort((a, b) => b.published_at - a.published_at) - const wotFilteredMods = mods.filter( - (mod) => - isInWoT(siteWot, siteWotLevel, mod.author) || - isInWoT(userWot, userWotLevel, mod.author) - ) - setLatestMods(wotFilteredMods) + setLatestMods(mods) }) .finally(() => { setIsFetchingLatestMods(false) @@ -287,11 +284,36 @@ const DisplayLatestMods = () => { !mutedAuthors.includes(mod.author) && !mutedEvents.includes(mod.aTag) && !nsfwList.includes(mod.aTag) && - !mod.nsfw + !mod.nsfw && + (isInWoT(siteWot, siteWotLevel, mod.author) || + isInWoT(userWot, userWotLevel, mod.author)) ) + // Add repost tag if missing + for (let i = 0; i < filtered.length; i++) { + const mod = filtered[i] + const isMissingRepostTag = + !mod.repost && mod.aTag && repostList.includes(mod.aTag) + + if (isMissingRepostTag) { + mod.repost = true + } + } + return filtered.slice(0, 4) - }, [muteLists, nsfwList, latestMods]) + }, [ + latestMods, + muteLists.admin.authors, + muteLists.admin.replaceableEvents, + muteLists.user.authors, + muteLists.user.replaceableEvents, + nsfwList, + repostList, + siteWot, + siteWotLevel, + userWot, + userWotLevel + ]) return (