filter ignore case

#154
This commit is contained in:
pompurin404 2024-09-12 12:10:34 +08:00
parent 6fb80a848f
commit 3119e0ed37
No known key found for this signature in database
6 changed files with 14 additions and 4 deletions

View File

@ -7,6 +7,7 @@
- 代理组图标支持SVG格式
- 优化覆写启用逻辑
- 覆写支持全局启用
- 筛选过滤忽略大小写
### Bug Fixes

View File

@ -10,6 +10,7 @@ import ConnectionDetailModal from '@renderer/components/connections/connection-d
import { CgClose } from 'react-icons/cg'
import { useAppConfig } from '@renderer/hooks/use-app-config'
import { HiSortAscending, HiSortDescending } from 'react-icons/hi'
import { includesIgnoreCase } from '@renderer/utils/includes'
let preData: IMihomoConnectionDetail[] = []
@ -57,7 +58,7 @@ const Connections: React.FC = () => {
if (filter === '') return connections
return connections?.filter((connection) => {
const raw = JSON.stringify(connection)
return raw.includes(filter)
return includesIgnoreCase(raw, filter)
})
}, [connections, filter, connectionDirection, connectionOrderBy])

View File

@ -4,6 +4,7 @@ import { useEffect, useMemo, useRef, useState } from 'react'
import { Button, Divider, Input } from '@nextui-org/react'
import { Virtuoso, VirtuosoHandle } from 'react-virtuoso'
import { IoLocationSharp } from 'react-icons/io5'
import { includesIgnoreCase } from '@renderer/utils/includes'
const Logs: React.FC = () => {
const [logs, setLogs] = useState<IMihomoLogInfo[]>([])
@ -14,7 +15,7 @@ const Logs: React.FC = () => {
const filteredLogs = useMemo(() => {
if (filter === '') return logs
return logs.filter((log) => {
return log.payload.includes(filter) || log.type.includes(filter)
return includesIgnoreCase(log.payload, filter) || includesIgnoreCase(log.type, filter)
})
}, [logs, filter])

View File

@ -18,6 +18,7 @@ import { IoIosArrowBack } from 'react-icons/io'
import { MdOutlineSpeed } from 'react-icons/md'
import { useGroups } from '@renderer/hooks/use-groups'
import CollapseInput from '@renderer/components/base/collapse-input'
import { includesIgnoreCase } from '@renderer/utils/includes'
const Proxies: React.FC = () => {
const { groups = [], mutate } = useGroups()
@ -40,7 +41,7 @@ const Proxies: React.FC = () => {
groups.forEach((group, index) => {
if (isOpen[index]) {
let groupProxies = group.all.filter((proxy) =>
proxy.name.toLowerCase().includes(searchValue[index].toLowerCase())
includesIgnoreCase(proxy.name, searchValue[index])
)
const count = Math.floor(groupProxies.length / cols)
groupCounts.push(groupProxies.length % cols === 0 ? count : count + 1)

View File

@ -4,6 +4,7 @@ import { Virtuoso } from 'react-virtuoso'
import { useMemo, useState } from 'react'
import { Divider, Input } from '@nextui-org/react'
import { useRules } from '@renderer/hooks/use-rules'
import { includesIgnoreCase } from '@renderer/utils/includes'
const Rules: React.FC = () => {
const { rules } = useRules()
@ -14,7 +15,9 @@ const Rules: React.FC = () => {
if (filter === '') return rules.rules
return rules.rules.filter((rule) => {
return (
rule.payload.includes(filter) || rule.type.includes(filter) || rule.proxy.includes(filter)
includesIgnoreCase(rule.payload, filter) ||
includesIgnoreCase(rule.type, filter) ||
includesIgnoreCase(rule.proxy, filter)
)
})
}, [rules, filter])

View File

@ -0,0 +1,3 @@
export function includesIgnoreCase(mainStr: string = '', subStr: string = ''): boolean {
return mainStr.toLowerCase().includes(subStr.toLowerCase())
}