Add missing repost tag to latest mods on home page #195
@ -4,6 +4,7 @@ export * from './useFilteredMods'
|
|||||||
export * from './useGames'
|
export * from './useGames'
|
||||||
export * from './useMuteLists'
|
export * from './useMuteLists'
|
||||||
export * from './useNSFWList'
|
export * from './useNSFWList'
|
||||||
|
export * from './useRepostList'
|
||||||
export * from './useReactions'
|
export * from './useReactions'
|
||||||
export * from './useNDKContext'
|
export * from './useNDKContext'
|
||||||
export * from './useScrollDisable'
|
export * from './useScrollDisable'
|
||||||
|
19
src/hooks/useRepostList.tsx
Normal file
19
src/hooks/useRepostList.tsx
Normal file
@ -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<string[]>([])
|
||||||
|
|
||||||
|
useDidMount(async () => {
|
||||||
|
const list = await getReportingSet(
|
||||||
|
CurationSetIdentifiers.Repost,
|
||||||
|
ndkContext
|
||||||
|
)
|
||||||
|
setRepostList(list)
|
||||||
|
})
|
||||||
|
|
||||||
|
return repostList
|
||||||
|
}
|
@ -14,7 +14,8 @@ import {
|
|||||||
useLocalStorage,
|
useLocalStorage,
|
||||||
useMuteLists,
|
useMuteLists,
|
||||||
useNDKContext,
|
useNDKContext,
|
||||||
useNSFWList
|
useNSFWList,
|
||||||
|
useRepostList
|
||||||
} from '../hooks'
|
} from '../hooks'
|
||||||
import { appRoutes, getModPageRoute } from '../routes'
|
import { appRoutes, getModPageRoute } from '../routes'
|
||||||
import { BlogCardDetails, ModDetails, NSFWFilter, SortBy } from '../types'
|
import { BlogCardDetails, ModDetails, NSFWFilter, SortBy } from '../types'
|
||||||
@ -257,18 +258,14 @@ const DisplayLatestMods = () => {
|
|||||||
|
|
||||||
const muteLists = useMuteLists()
|
const muteLists = useMuteLists()
|
||||||
const nsfwList = useNSFWList()
|
const nsfwList = useNSFWList()
|
||||||
|
const repostList = useRepostList()
|
||||||
|
|
||||||
useDidMount(() => {
|
useDidMount(() => {
|
||||||
fetchMods({ source: window.location.host })
|
fetchMods({ source: window.location.host })
|
||||||
.then((mods) => {
|
.then((mods) => {
|
||||||
// Sort by the latest (published_at descending)
|
// Sort by the latest (published_at descending)
|
||||||
mods.sort((a, b) => b.published_at - a.published_at)
|
mods.sort((a, b) => b.published_at - a.published_at)
|
||||||
const wotFilteredMods = mods.filter(
|
setLatestMods(mods)
|
||||||
(mod) =>
|
|
||||||
isInWoT(siteWot, siteWotLevel, mod.author) ||
|
|
||||||
isInWoT(userWot, userWotLevel, mod.author)
|
|
||||||
)
|
|
||||||
setLatestMods(wotFilteredMods)
|
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setIsFetchingLatestMods(false)
|
setIsFetchingLatestMods(false)
|
||||||
@ -287,11 +284,36 @@ const DisplayLatestMods = () => {
|
|||||||
!mutedAuthors.includes(mod.author) &&
|
!mutedAuthors.includes(mod.author) &&
|
||||||
!mutedEvents.includes(mod.aTag) &&
|
!mutedEvents.includes(mod.aTag) &&
|
||||||
!nsfwList.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)
|
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 (
|
return (
|
||||||
<div className='IBMSecMain IBMSMListWrapper'>
|
<div className='IBMSecMain IBMSMListWrapper'>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user