2024-09-18 16:40:34 +00:00
|
|
|
import { Pagination } from 'components/Pagination'
|
2024-08-06 10:46:38 +00:00
|
|
|
import { kinds, nip19 } from 'nostr-tools'
|
|
|
|
import React, {
|
|
|
|
Dispatch,
|
|
|
|
SetStateAction,
|
|
|
|
useCallback,
|
|
|
|
useEffect,
|
|
|
|
useMemo,
|
|
|
|
useState
|
|
|
|
} from 'react'
|
|
|
|
import { LoadingSpinner } from '../components/LoadingSpinner'
|
|
|
|
import { ModCard } from '../components/ModCard'
|
2024-09-18 16:40:34 +00:00
|
|
|
import { MOD_FILTER_LIMIT } from '../constants'
|
2024-08-06 10:46:38 +00:00
|
|
|
import { MetadataController } from '../controllers'
|
2024-09-18 16:40:34 +00:00
|
|
|
import { useAppSelector, useDidMount, useMuteLists } from '../hooks'
|
2024-09-03 10:13:51 +00:00
|
|
|
import { getModPageRoute } from '../routes'
|
2024-07-11 12:52:48 +00:00
|
|
|
import '../styles/filters.css'
|
|
|
|
import '../styles/pagination.css'
|
|
|
|
import '../styles/search.css'
|
2024-08-06 10:46:38 +00:00
|
|
|
import '../styles/styles.css'
|
2024-09-18 16:40:34 +00:00
|
|
|
import { ModDetails } from '../types'
|
2024-08-06 10:46:38 +00:00
|
|
|
import { fetchMods } from '../utils'
|
2024-07-29 06:26:26 +00:00
|
|
|
|
2024-08-06 10:46:38 +00:00
|
|
|
enum SortBy {
|
2024-07-29 06:26:26 +00:00
|
|
|
Latest = 'Latest',
|
|
|
|
Oldest = 'Oldest',
|
|
|
|
Best_Rated = 'Best Rated',
|
|
|
|
Worst_Rated = 'Worst Rated'
|
|
|
|
}
|
|
|
|
|
|
|
|
enum NSFWFilter {
|
|
|
|
Hide_NSFW = 'Hide NSFW',
|
|
|
|
Show_NSFW = 'Show NSFW',
|
|
|
|
Only_NSFW = 'Only NSFW'
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ModeratedFilter {
|
|
|
|
Moderated = 'Moderated',
|
2024-08-29 17:13:36 +00:00
|
|
|
Unmoderated = 'Unmoderated',
|
|
|
|
Unmoderated_Fully = 'Unmoderated Fully'
|
2024-07-29 06:26:26 +00:00
|
|
|
}
|
2024-07-11 12:52:48 +00:00
|
|
|
|
2024-08-06 10:46:38 +00:00
|
|
|
interface FilterOptions {
|
|
|
|
sort: SortBy
|
|
|
|
nsfw: NSFWFilter
|
|
|
|
source: string
|
|
|
|
moderated: ModeratedFilter
|
|
|
|
}
|
|
|
|
|
2024-07-11 12:52:48 +00:00
|
|
|
export const ModsPage = () => {
|
2024-08-06 10:46:38 +00:00
|
|
|
const [isFetching, setIsFetching] = useState(false)
|
2024-07-29 06:26:26 +00:00
|
|
|
const [mods, setMods] = useState<ModDetails[]>([])
|
2024-08-06 10:46:38 +00:00
|
|
|
const [filterOptions, setFilterOptions] = useState<FilterOptions>({
|
|
|
|
sort: SortBy.Latest,
|
|
|
|
nsfw: NSFWFilter.Hide_NSFW,
|
|
|
|
source: window.location.host,
|
|
|
|
moderated: ModeratedFilter.Moderated
|
|
|
|
})
|
2024-09-18 16:40:34 +00:00
|
|
|
const muteLists = useMuteLists()
|
|
|
|
|
2024-08-28 17:03:43 +00:00
|
|
|
const [nsfwList, setNSFWList] = useState<string[]>([])
|
2024-08-06 10:46:38 +00:00
|
|
|
|
|
|
|
const [page, setPage] = useState(1)
|
2024-07-29 06:26:26 +00:00
|
|
|
|
2024-08-28 17:03:43 +00:00
|
|
|
const userState = useAppSelector((state) => state.user)
|
|
|
|
|
2024-07-29 06:26:26 +00:00
|
|
|
useDidMount(async () => {
|
2024-08-06 10:46:38 +00:00
|
|
|
const metadataController = await MetadataController.getInstance()
|
2024-08-28 17:03:43 +00:00
|
|
|
|
|
|
|
metadataController.getNSFWList().then((list) => {
|
|
|
|
setNSFWList(list)
|
|
|
|
})
|
2024-08-06 10:46:38 +00:00
|
|
|
})
|
2024-07-29 06:26:26 +00:00
|
|
|
|
2024-08-06 10:46:38 +00:00
|
|
|
useEffect(() => {
|
|
|
|
setIsFetching(true)
|
2024-09-02 08:47:16 +00:00
|
|
|
fetchMods({ source: filterOptions.source })
|
2024-08-06 10:46:38 +00:00
|
|
|
.then((res) => {
|
|
|
|
setMods(res)
|
2024-07-29 06:26:26 +00:00
|
|
|
})
|
2024-08-06 10:46:38 +00:00
|
|
|
.finally(() => {
|
|
|
|
setIsFetching(false)
|
|
|
|
})
|
|
|
|
}, [filterOptions.source])
|
|
|
|
|
|
|
|
const handleNext = useCallback(() => {
|
|
|
|
setIsFetching(true)
|
|
|
|
|
|
|
|
const until =
|
2024-08-27 15:46:42 +00:00
|
|
|
mods.length > 0 ? mods[mods.length - 1].published_at - 1 : undefined
|
2024-08-06 10:46:38 +00:00
|
|
|
|
2024-09-02 08:47:16 +00:00
|
|
|
fetchMods({
|
|
|
|
source: filterOptions.source,
|
|
|
|
until
|
|
|
|
})
|
2024-08-06 10:46:38 +00:00
|
|
|
.then((res) => {
|
|
|
|
setMods(res)
|
|
|
|
setPage((prev) => prev + 1)
|
2024-07-29 06:26:26 +00:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
setIsFetching(false)
|
|
|
|
})
|
2024-08-06 10:46:38 +00:00
|
|
|
}, [filterOptions.source, mods])
|
|
|
|
|
|
|
|
const handlePrev = useCallback(() => {
|
|
|
|
setIsFetching(true)
|
2024-07-29 06:26:26 +00:00
|
|
|
|
2024-08-27 15:46:42 +00:00
|
|
|
const since = mods.length > 0 ? mods[0].published_at + 1 : undefined
|
2024-08-06 10:46:38 +00:00
|
|
|
|
2024-09-02 08:47:16 +00:00
|
|
|
fetchMods({
|
|
|
|
source: filterOptions.source,
|
|
|
|
since
|
|
|
|
})
|
2024-08-06 10:46:38 +00:00
|
|
|
.then((res) => {
|
|
|
|
setMods(res)
|
|
|
|
setPage((prev) => prev - 1)
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
setIsFetching(false)
|
|
|
|
})
|
|
|
|
}, [filterOptions.source, mods])
|
|
|
|
|
|
|
|
const filteredModList = useMemo(() => {
|
|
|
|
const nsfwFilter = (mods: ModDetails[]) => {
|
|
|
|
// Determine the filtering logic based on the NSFW filter option
|
|
|
|
switch (filterOptions.nsfw) {
|
|
|
|
case NSFWFilter.Hide_NSFW:
|
|
|
|
// If 'Hide_NSFW' is selected, filter out NSFW mods
|
2024-08-28 17:03:43 +00:00
|
|
|
return mods.filter((mod) => !mod.nsfw && !nsfwList.includes(mod.aTag))
|
2024-08-06 10:46:38 +00:00
|
|
|
case NSFWFilter.Show_NSFW:
|
|
|
|
// If 'Show_NSFW' is selected, return all mods (no filtering)
|
|
|
|
return mods
|
|
|
|
case NSFWFilter.Only_NSFW:
|
|
|
|
// If 'Only_NSFW' is selected, filter to show only NSFW mods
|
2024-08-28 17:03:43 +00:00
|
|
|
return mods.filter((mod) => mod.nsfw || nsfwList.includes(mod.aTag))
|
2024-08-06 10:46:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let filtered = nsfwFilter(mods)
|
|
|
|
|
2024-08-29 17:13:36 +00:00
|
|
|
const isAdmin = userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB
|
|
|
|
const isUnmoderatedFully =
|
|
|
|
filterOptions.moderated === ModeratedFilter.Unmoderated_Fully
|
|
|
|
|
|
|
|
// Only apply filtering if the user is not an admin or the admin has not selected "Unmoderated Fully"
|
|
|
|
if (!(isAdmin && isUnmoderatedFully)) {
|
|
|
|
filtered = filtered.filter(
|
|
|
|
(mod) =>
|
|
|
|
!muteLists.admin.authors.includes(mod.author) &&
|
|
|
|
!muteLists.admin.replaceableEvents.includes(mod.aTag)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-08-06 10:46:38 +00:00
|
|
|
if (filterOptions.moderated === ModeratedFilter.Moderated) {
|
|
|
|
filtered = filtered.filter(
|
|
|
|
(mod) =>
|
2024-08-29 17:13:36 +00:00
|
|
|
!muteLists.user.authors.includes(mod.author) &&
|
|
|
|
!muteLists.user.replaceableEvents.includes(mod.aTag)
|
2024-08-06 10:46:38 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filterOptions.sort === SortBy.Latest) {
|
2024-08-27 15:46:42 +00:00
|
|
|
filtered.sort((a, b) => b.published_at - a.published_at)
|
2024-08-06 10:46:38 +00:00
|
|
|
} else if (filterOptions.sort === SortBy.Oldest) {
|
2024-08-27 15:46:42 +00:00
|
|
|
filtered.sort((a, b) => a.published_at - b.published_at)
|
2024-08-06 10:46:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return filtered
|
|
|
|
}, [
|
2024-08-29 17:13:36 +00:00
|
|
|
userState.user?.npub,
|
2024-08-06 10:46:38 +00:00
|
|
|
filterOptions.sort,
|
|
|
|
filterOptions.moderated,
|
|
|
|
filterOptions.nsfw,
|
|
|
|
mods,
|
2024-08-28 17:03:43 +00:00
|
|
|
muteLists,
|
|
|
|
nsfwList
|
2024-08-06 10:46:38 +00:00
|
|
|
])
|
2024-07-29 06:26:26 +00:00
|
|
|
|
2024-07-11 12:52:48 +00:00
|
|
|
return (
|
2024-08-06 10:46:38 +00:00
|
|
|
<>
|
|
|
|
{isFetching && <LoadingSpinner desc='Fetching mod details from relays' />}
|
|
|
|
<div className='InnerBodyMain'>
|
|
|
|
<div className='ContainerMain'>
|
|
|
|
<div className='IBMSecMainGroup IBMSecMainGroupAlt'>
|
|
|
|
<PageTitleRow />
|
|
|
|
<Filters
|
|
|
|
filterOptions={filterOptions}
|
|
|
|
setFilterOptions={setFilterOptions}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div className='IBMSecMain IBMSMListWrapper'>
|
|
|
|
<div className='IBMSMList'>
|
2024-08-29 08:24:15 +00:00
|
|
|
{filteredModList.map((mod) => {
|
2024-09-03 10:13:51 +00:00
|
|
|
const route = getModPageRoute(
|
2024-08-29 08:24:15 +00:00
|
|
|
nip19.naddrEncode({
|
|
|
|
identifier: mod.aTag,
|
|
|
|
pubkey: mod.author,
|
|
|
|
kind: kinds.ClassifiedListing
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ModCard
|
|
|
|
key={mod.id}
|
|
|
|
title={mod.title}
|
2024-09-05 07:46:14 +00:00
|
|
|
gameName={mod.game}
|
2024-08-29 08:24:15 +00:00
|
|
|
summary={mod.summary}
|
2024-09-02 08:47:16 +00:00
|
|
|
imageUrl={mod.featuredImageUrl}
|
2024-09-16 07:35:42 +00:00
|
|
|
route={route}
|
2024-08-29 08:24:15 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
})}
|
2024-08-06 10:46:38 +00:00
|
|
|
</div>
|
2024-07-11 12:52:48 +00:00
|
|
|
</div>
|
|
|
|
|
2024-08-06 10:46:38 +00:00
|
|
|
<Pagination
|
|
|
|
page={page}
|
2024-08-08 16:56:30 +00:00
|
|
|
disabledNext={mods.length < MOD_FILTER_LIMIT}
|
2024-08-06 10:46:38 +00:00
|
|
|
handlePrev={handlePrev}
|
|
|
|
handleNext={handleNext}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-07-29 06:26:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-08-06 10:46:38 +00:00
|
|
|
</>
|
2024-07-29 06:26:26 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-08-06 10:46:38 +00:00
|
|
|
const PageTitleRow = React.memo(() => {
|
2024-07-29 06:26:26 +00:00
|
|
|
return (
|
|
|
|
<div className='IBMSecMain'>
|
|
|
|
<div className='SearchMainWrapper'>
|
|
|
|
<div className='IBMSMTitleMain'>
|
|
|
|
<h2 className='IBMSMTitleMainHeading'>Mods</h2>
|
|
|
|
</div>
|
|
|
|
<div className='SearchMain'>
|
|
|
|
<div className='SearchMainInside'>
|
|
|
|
<div className='SearchMainInsideWrapper'>
|
|
|
|
<input type='text' className='SMIWInput' />
|
|
|
|
<button className='btn btnMain SMIWButton' type='button'>
|
|
|
|
<svg
|
|
|
|
xmlns='http://www.w3.org/2000/svg'
|
|
|
|
viewBox='0 0 512 512'
|
|
|
|
width='1em'
|
|
|
|
height='1em'
|
|
|
|
fill='currentColor'
|
|
|
|
>
|
|
|
|
<path d='M500.3 443.7l-119.7-119.7c27.22-40.41 40.65-90.9 33.46-144.7C401.8 87.79 326.8 13.32 235.2 1.723C99.01-15.51-15.51 99.01 1.724 235.2c11.6 91.64 86.08 166.7 177.6 178.9c53.8 7.189 104.3-6.236 144.7-33.46l119.7 119.7c15.62 15.62 40.95 15.62 56.57 0C515.9 484.7 515.9 459.3 500.3 443.7zM79.1 208c0-70.58 57.42-128 128-128s128 57.42 128 128c0 70.58-57.42 128-128 128S79.1 278.6 79.1 208z'></path>
|
|
|
|
</svg>
|
|
|
|
</button>
|
2024-07-11 12:52:48 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-07-29 06:26:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
2024-08-06 10:46:38 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
type FiltersProps = {
|
|
|
|
filterOptions: FilterOptions
|
|
|
|
setFilterOptions: Dispatch<SetStateAction<FilterOptions>>
|
2024-07-29 06:26:26 +00:00
|
|
|
}
|
2024-07-11 12:52:48 +00:00
|
|
|
|
2024-08-06 10:46:38 +00:00
|
|
|
const Filters = React.memo(
|
|
|
|
({ filterOptions, setFilterOptions }: FiltersProps) => {
|
2024-08-29 17:13:36 +00:00
|
|
|
const userState = useAppSelector((state) => state.user)
|
|
|
|
|
2024-08-06 10:46:38 +00:00
|
|
|
return (
|
|
|
|
<div className='IBMSecMain'>
|
|
|
|
<div className='FiltersMain'>
|
|
|
|
<div className='FiltersMainElement'>
|
|
|
|
<div className='dropdown dropdownMain'>
|
|
|
|
<button
|
|
|
|
className='btn dropdown-toggle btnMain btnMainDropdown'
|
|
|
|
aria-expanded='false'
|
|
|
|
data-bs-toggle='dropdown'
|
|
|
|
type='button'
|
|
|
|
>
|
|
|
|
{filterOptions.sort}
|
|
|
|
</button>
|
2024-07-29 06:26:26 +00:00
|
|
|
|
2024-08-06 10:46:38 +00:00
|
|
|
<div className='dropdown-menu dropdownMainMenu'>
|
|
|
|
{Object.values(SortBy).map((item, index) => (
|
|
|
|
<div
|
|
|
|
key={`sortByItem-${index}`}
|
|
|
|
className='dropdown-item dropdownMainMenuItem'
|
|
|
|
onClick={() =>
|
|
|
|
setFilterOptions((prev) => ({
|
|
|
|
...prev,
|
|
|
|
sort: item
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{item}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className='FiltersMainElement'>
|
|
|
|
<div className='dropdown dropdownMain'>
|
|
|
|
<button
|
|
|
|
className='btn dropdown-toggle btnMain btnMainDropdown'
|
|
|
|
aria-expanded='false'
|
|
|
|
data-bs-toggle='dropdown'
|
|
|
|
type='button'
|
|
|
|
>
|
|
|
|
{filterOptions.moderated}
|
|
|
|
</button>
|
|
|
|
<div className='dropdown-menu dropdownMainMenu'>
|
2024-08-29 17:13:36 +00:00
|
|
|
{Object.values(ModeratedFilter).map((item, index) => {
|
|
|
|
if (item === ModeratedFilter.Unmoderated_Fully) {
|
|
|
|
const isAdmin =
|
|
|
|
userState.user?.npub ===
|
|
|
|
import.meta.env.VITE_REPORTING_NPUB
|
|
|
|
|
|
|
|
if (!isAdmin) return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
key={`moderatedFilterItem-${index}`}
|
|
|
|
className='dropdown-item dropdownMainMenuItem'
|
|
|
|
onClick={() =>
|
|
|
|
setFilterOptions((prev) => ({
|
|
|
|
...prev,
|
|
|
|
moderated: item
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{item}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})}
|
2024-08-06 10:46:38 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className='FiltersMainElement'>
|
|
|
|
<div className='dropdown dropdownMain'>
|
|
|
|
<button
|
|
|
|
className='btn dropdown-toggle btnMain btnMainDropdown'
|
|
|
|
aria-expanded='false'
|
|
|
|
data-bs-toggle='dropdown'
|
|
|
|
type='button'
|
|
|
|
>
|
|
|
|
{filterOptions.nsfw}
|
|
|
|
</button>
|
|
|
|
<div className='dropdown-menu dropdownMainMenu'>
|
|
|
|
{Object.values(NSFWFilter).map((item, index) => (
|
|
|
|
<div
|
|
|
|
key={`nsfwFilterItem-${index}`}
|
|
|
|
className='dropdown-item dropdownMainMenuItem'
|
|
|
|
onClick={() =>
|
|
|
|
setFilterOptions((prev) => ({
|
|
|
|
...prev,
|
|
|
|
nsfw: item
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{item}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className='FiltersMainElement'>
|
|
|
|
<div className='dropdown dropdownMain'>
|
|
|
|
<button
|
|
|
|
className='btn dropdown-toggle btnMain btnMainDropdown'
|
|
|
|
aria-expanded='false'
|
|
|
|
data-bs-toggle='dropdown'
|
|
|
|
type='button'
|
|
|
|
>
|
|
|
|
{filterOptions.source === window.location.host
|
|
|
|
? `Show From: ${filterOptions.source}`
|
|
|
|
: 'Show All'}
|
|
|
|
</button>
|
|
|
|
<div className='dropdown-menu dropdownMainMenu'>
|
2024-07-29 06:26:26 +00:00
|
|
|
<div
|
|
|
|
className='dropdown-item dropdownMainMenuItem'
|
2024-08-06 10:46:38 +00:00
|
|
|
onClick={() =>
|
|
|
|
setFilterOptions((prev) => ({
|
|
|
|
...prev,
|
|
|
|
source: window.location.host
|
|
|
|
}))
|
|
|
|
}
|
2024-07-29 06:26:26 +00:00
|
|
|
>
|
2024-08-06 10:46:38 +00:00
|
|
|
Show From: {window.location.host}
|
2024-07-29 06:26:26 +00:00
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className='dropdown-item dropdownMainMenuItem'
|
2024-08-06 10:46:38 +00:00
|
|
|
onClick={() =>
|
|
|
|
setFilterOptions((prev) => ({
|
|
|
|
...prev,
|
|
|
|
source: 'Show All'
|
|
|
|
}))
|
|
|
|
}
|
2024-07-11 12:52:48 +00:00
|
|
|
>
|
2024-08-06 10:46:38 +00:00
|
|
|
Show All
|
2024-07-11 12:52:48 +00:00
|
|
|
</div>
|
2024-08-06 10:46:38 +00:00
|
|
|
</div>
|
2024-07-29 06:26:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-08-06 10:46:38 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|