Compare commits
3 Commits
d5924ebf4b
...
1623f80e88
Author | SHA1 | Date | |
---|---|---|---|
|
1623f80e88 | ||
|
93a7419006 | ||
|
474a1b0f0a |
@ -7,5 +7,4 @@ Rise of the Ronin,,https://image.nostr.build/5eba5c6efed335e1e6c74e7af29790a9cc5
|
|||||||
NINJA GAIDEN 4,,https://image.nostr.build/2b49b1571ba90450f95a9eb306d2ef9f3ad632dc6282125cc1651d17da17a439.jpg
|
NINJA GAIDEN 4,,https://image.nostr.build/2b49b1571ba90450f95a9eb306d2ef9f3ad632dc6282125cc1651d17da17a439.jpg
|
||||||
Batman Arkham Asylum,,https://image.nostr.build/ba5c07be4747957380213ad86ab83b8a4cb6b8ef0123ebb9863318ed1de6e43e.jpg
|
Batman Arkham Asylum,,https://image.nostr.build/ba5c07be4747957380213ad86ab83b8a4cb6b8ef0123ebb9863318ed1de6e43e.jpg
|
||||||
Kingdom Hearts,,https://image.nostr.build/883b71c52b5b498aac20218b52af471ba89afb5cbb7072dc403da7446ca04e39.jpg
|
Kingdom Hearts,,https://image.nostr.build/883b71c52b5b498aac20218b52af471ba89afb5cbb7072dc403da7446ca04e39.jpg
|
||||||
Kingdom Hearts II,,https://image.nostr.build/24b6002029e91e4ad99b56aca9f20b076feb594ae48b320ba9122254add6b57e.jpg
|
Kingdom Hearts II,,https://image.nostr.build/24b6002029e91e4ad99b56aca9f20b076feb594ae48b320ba9122254add6b57e.jpg
|
||||||
The Killing Antidote,,https://image.nostr.build/4fdb2c26e3830f2a9a5f02d2b09d6ee9bb47135031389022f92f1cc4416ebc0a.jpg
|
|
|
@ -9,7 +9,7 @@ import '../../styles/pagination.css'
|
|||||||
import '../../styles/search.css'
|
import '../../styles/search.css'
|
||||||
import '../../styles/styles.css'
|
import '../../styles/styles.css'
|
||||||
import { PaginationWithPageNumbers } from 'components/Pagination'
|
import { PaginationWithPageNumbers } from 'components/Pagination'
|
||||||
import { normalizeSearchString, scrollIntoView } from 'utils'
|
import { scrollIntoView } from 'utils'
|
||||||
import { LoadingSpinner } from 'components/LoadingSpinner'
|
import { LoadingSpinner } from 'components/LoadingSpinner'
|
||||||
import { Filter } from 'components/Filters'
|
import { Filter } from 'components/Filters'
|
||||||
import { Dropdown } from 'components/Filters/Dropdown'
|
import { Dropdown } from 'components/Filters/Dropdown'
|
||||||
@ -63,17 +63,15 @@ export const BlogsPage = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let filtered = blogs?.filter(filterNsfwFn) || []
|
let filtered = blogs?.filter(filterNsfwFn) || []
|
||||||
const normalizedSearchTerm = normalizeSearchString(searchTerm)
|
const lowerCaseSearchTerm = searchTerm.toLowerCase()
|
||||||
|
|
||||||
if (normalizedSearchTerm !== '') {
|
if (searchTerm !== '') {
|
||||||
const filterSearchTermFn = (blog: Partial<BlogCardDetails>) =>
|
const filterSearchTermFn = (blog: Partial<BlogCardDetails>) =>
|
||||||
normalizeSearchString(blog.title || '').includes(
|
(blog.title || '').toLowerCase().includes(lowerCaseSearchTerm) ||
|
||||||
normalizedSearchTerm
|
(blog.summary || '').toLowerCase().includes(lowerCaseSearchTerm) ||
|
||||||
) ||
|
(blog.content || '').toLowerCase().includes(lowerCaseSearchTerm) ||
|
||||||
(blog.summary || '').toLowerCase().includes(normalizedSearchTerm) ||
|
|
||||||
(blog.content || '').toLowerCase().includes(normalizedSearchTerm) ||
|
|
||||||
(blog.tTags || []).findIndex((tag) =>
|
(blog.tTags || []).findIndex((tag) =>
|
||||||
tag.toLowerCase().includes(normalizedSearchTerm)
|
tag.toLowerCase().includes(lowerCaseSearchTerm)
|
||||||
) > -1
|
) > -1
|
||||||
filtered = filtered.filter(filterSearchTermFn)
|
filtered = filtered.filter(filterSearchTermFn)
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ import {
|
|||||||
isModDataComplete,
|
isModDataComplete,
|
||||||
memoizedNormalizeSearchString,
|
memoizedNormalizeSearchString,
|
||||||
normalizeSearchString,
|
normalizeSearchString,
|
||||||
normalizeUserSearchString,
|
|
||||||
scrollIntoView
|
scrollIntoView
|
||||||
} from 'utils'
|
} from 'utils'
|
||||||
import { useCuratedSet } from 'hooks/useCuratedSet'
|
import { useCuratedSet } from 'hooks/useCuratedSet'
|
||||||
@ -296,17 +295,18 @@ const ModsResult = ({
|
|||||||
}, [searchTerm])
|
}, [searchTerm])
|
||||||
|
|
||||||
const filteredMods = useMemo(() => {
|
const filteredMods = useMemo(() => {
|
||||||
const normalizedSearchTerm = normalizeSearchString(searchTerm)
|
|
||||||
// Search page requires search term
|
// Search page requires search term
|
||||||
if (normalizedSearchTerm === '') return []
|
if (searchTerm === '') return []
|
||||||
|
|
||||||
|
const lowerCaseSearchTerm = searchTerm.toLowerCase()
|
||||||
|
|
||||||
const filterFn = (mod: ModDetails) =>
|
const filterFn = (mod: ModDetails) =>
|
||||||
normalizeSearchString(mod.title).includes(normalizedSearchTerm) ||
|
mod.title.toLowerCase().includes(lowerCaseSearchTerm) ||
|
||||||
memoizedNormalizeSearchString(mod.game).includes(normalizedSearchTerm) ||
|
mod.game.toLowerCase().includes(lowerCaseSearchTerm) ||
|
||||||
mod.summary.toLowerCase().includes(normalizedSearchTerm) ||
|
mod.summary.toLowerCase().includes(lowerCaseSearchTerm) ||
|
||||||
mod.body.toLowerCase().includes(normalizedSearchTerm) ||
|
mod.body.toLowerCase().includes(lowerCaseSearchTerm) ||
|
||||||
mod.tags.findIndex((tag) =>
|
mod.tags.findIndex((tag) =>
|
||||||
tag.toLowerCase().includes(normalizedSearchTerm)
|
tag.toLowerCase().includes(lowerCaseSearchTerm)
|
||||||
) > -1
|
) > -1
|
||||||
|
|
||||||
const filterSourceFn = (mod: ModDetails) => {
|
const filterSourceFn = (mod: ModDetails) => {
|
||||||
@ -379,14 +379,13 @@ const UsersResult = ({
|
|||||||
const userState = useAppSelector((state) => state.user)
|
const userState = useAppSelector((state) => state.user)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const normalizedSearchTerm = normalizeUserSearchString(searchTerm)
|
if (searchTerm === '') {
|
||||||
if (normalizedSearchTerm === '') {
|
|
||||||
setProfiles([])
|
setProfiles([])
|
||||||
} else {
|
} else {
|
||||||
const sub = ndk.subscribe(
|
const sub = ndk.subscribe(
|
||||||
{
|
{
|
||||||
kinds: [NDKKind.Metadata],
|
kinds: [NDKKind.Metadata],
|
||||||
search: normalizedSearchTerm
|
search: searchTerm
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
closeOnEose: true,
|
closeOnEose: true,
|
||||||
@ -398,7 +397,7 @@ const UsersResult = ({
|
|||||||
|
|
||||||
// Stop the sub after 10 seconds if we are still searching the same term as before
|
// Stop the sub after 10 seconds if we are still searching the same term as before
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
if (sub.filter.search === normalizedSearchTerm) {
|
if (sub.filter.search === searchTerm) {
|
||||||
sub.stop()
|
sub.stop()
|
||||||
}
|
}
|
||||||
}, 10000)
|
}, 10000)
|
||||||
@ -503,8 +502,9 @@ const GamesResult = ({ searchTerm }: GamesResultProps) => {
|
|||||||
}, [searchTerm])
|
}, [searchTerm])
|
||||||
|
|
||||||
const filteredGames = useMemo(() => {
|
const filteredGames = useMemo(() => {
|
||||||
|
if (searchTerm === '') return []
|
||||||
|
|
||||||
const normalizedSearchTerm = normalizeSearchString(searchTerm)
|
const normalizedSearchTerm = normalizeSearchString(searchTerm)
|
||||||
if (normalizedSearchTerm === '') return []
|
|
||||||
|
|
||||||
return games.filter((game) =>
|
return games.filter((game) =>
|
||||||
memoizedNormalizeSearchString(game['Game Name']).includes(
|
memoizedNormalizeSearchString(game['Game Name']).includes(
|
||||||
|
@ -238,7 +238,6 @@ const romanRegex = new RegExp(
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const normalizeSearchString = (str: string): string => {
|
export const normalizeSearchString = (str: string): string => {
|
||||||
str = str.trim()
|
|
||||||
str = str.toLowerCase()
|
str = str.toLowerCase()
|
||||||
str = str.replace(romanRegex, (match) => ROMAN_TO_ARABIC_MAP[match])
|
str = str.replace(romanRegex, (match) => ROMAN_TO_ARABIC_MAP[match])
|
||||||
str = removeAccents(str)
|
str = removeAccents(str)
|
||||||
@ -259,17 +258,6 @@ const memoizeNormalize = (func: (str: string) => string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Memoize normalized search strings
|
|
||||||
* Should only be used for games (large list)
|
|
||||||
*/
|
|
||||||
export const memoizedNormalizeSearchString = memoizeNormalize(
|
export const memoizedNormalizeSearchString = memoizeNormalize(
|
||||||
normalizeSearchString
|
normalizeSearchString
|
||||||
)
|
)
|
||||||
|
|
||||||
export const normalizeUserSearchString = (str: string): string => {
|
|
||||||
str = str.trim()
|
|
||||||
str = str.toLowerCase()
|
|
||||||
str = removeAccents(str)
|
|
||||||
return str
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user