Skip to content

Commit a535251

Browse files
authored
Merge branch 'main' into fix/refresh_startup
2 parents b901547 + b8d61c1 commit a535251

File tree

3 files changed

+82
-32
lines changed

3 files changed

+82
-32
lines changed

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
22
"name": "hyperplay",
3-
"version": "0.23.2",
3+
"version": "0.23.3",
44
"private": true,
55
"main": "build/main/main.js",
6-
"productName": "HyperPlay",
76
"homepage": "./",
87
"license": "GPL-3.0-only",
98
"description": "HyperPlay",
@@ -232,7 +231,7 @@
232231
"@hyperplay/extension-provider": "^0.0.9",
233232
"@hyperplay/mock-backend": "^0.0.1",
234233
"@hyperplay/overlay": "^1.0.0",
235-
"@hyperplay/patcher": "^0.0.21",
234+
"@hyperplay/patcher": "0.0.22",
236235
"@hyperplay/providers": "^0.1.0",
237236
"@hyperplay/proxy-server": "^0.0.11"
238237
},

pnpm-lock.yaml

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/frontend/screens/Quests/index.tsx

+75-24
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Quest } from '@hyperplay/utils'
1212
import { QuestRewardClaimedToast } from 'frontend/components/UI/QuestRewardClaimedToast'
1313
import useGetHyperPlayListings from 'frontend/hooks/useGetHyperPlayListings'
1414
import useGetQuests from 'frontend/hooks/useGetQuests'
15+
import Fuse from 'fuse.js'
1516
import {
1617
Alert,
1718
Background,
@@ -41,6 +42,15 @@ export function QuestsPage() {
4142
const [searchText, setSearchText] = useState(searchParam ?? '')
4243
const [activeFilter, setActiveFilter] = useState<QuestFilter>('all')
4344

45+
interface FuseResult<T> {
46+
id: number
47+
project_id: string
48+
name: string
49+
title: string
50+
item: T
51+
refIndex: number
52+
}
53+
4454
useEffect(() => {
4555
window.api.trackScreen('Quests Page')
4656
}, [])
@@ -117,47 +127,86 @@ export function QuestsPage() {
117127
)
118128
}
119129
})
130+
//Search Quest
131+
const fuseOptions = {
132+
keys: ['name', 'title'],
133+
threshold: 0.2
134+
}
135+
136+
const questsWithGameNames =
137+
quests?.map((quest) => {
138+
const gameName = listings?.[quest.project_id]?.project_meta?.name ?? ''
139+
return {
140+
...quest,
141+
title: gameName,
142+
name: quest.name
143+
}
144+
}) ?? []
145+
146+
const fuse = new Fuse(questsWithGameNames ?? [], fuseOptions)
147+
148+
let searchFilteredQuests: FuseResult<Quest>[] = []
149+
if (searchText) {
150+
searchFilteredQuests = fuse.search(searchText) as FuseResult<Quest>[]
151+
} else if (quests) {
152+
searchFilteredQuests = quests.map((quest) => ({
153+
id: quest.id,
154+
project_id: quest.project_id,
155+
name: quest.name,
156+
title: listings?.[quest.project_id]?.project_meta?.name ?? '',
157+
item: quest,
158+
refIndex: 0
159+
}))
160+
}
120161

121-
const gameTitleMatches = (quest: Quest) => {
122-
const title = listings ? listings[quest.project_id]?.project_meta?.name : ''
123-
return title?.toLowerCase().startsWith(searchText.toLowerCase())
162+
const searchQuests = (quests: Quest[], query: string) => {
163+
if (!query) return quests
164+
const results = fuse.search(query)
165+
return results.map((result) => result.item)
124166
}
125167

126-
const searchFilteredQuests = quests?.filter((quest) => {
127-
const questTitleMatch = quest.name
128-
.toLowerCase()
129-
.startsWith(searchText.toLowerCase())
130-
const gameTitleMatch = gameTitleMatches(quest)
131-
const searchByKeywords = searchText
132-
.toLowerCase()
133-
.split(' ')
134-
.some(
135-
(term) =>
136-
quest.name?.toLowerCase().includes(term) ||
137-
quest.description?.toLowerCase().includes(term)
168+
const filteredQuests = searchQuests(quests ?? [], searchText)
169+
170+
useEffect(() => {
171+
if (filteredQuests.length > 0) {
172+
const currentQuestExists = filteredQuests.find(
173+
(quest) => quest.id === selectedQuestId
138174
)
139-
return questTitleMatch || gameTitleMatch || searchByKeywords
140-
})
175+
if (!currentQuestExists) {
176+
const firstQuest = filteredQuests[0]
177+
if (firstQuest) {
178+
const searchParams = new URLSearchParams(window.location.search)
179+
const newUrl = `/quests/${firstQuest.id}${
180+
searchParams.toString() ? `?${searchParams.toString()}` : ''
181+
}#card-${firstQuest.id}`
182+
navigate(newUrl)
183+
}
184+
}
185+
}
186+
}, [filteredQuests, navigate, selectedQuestId])
141187

142-
const initialQuestId = searchFilteredQuests?.[0]?.id ?? null
188+
const initialQuestId = searchFilteredQuests?.[0]?.item?.id ?? null
143189
const visibleQuestId = selectedQuestId ?? initialQuestId
144190

145191
const imagesToPreload: string[] = []
146192
const gameElements =
147-
searchFilteredQuests?.map(({ id, project_id, name, ...rest }) => {
193+
searchFilteredQuests?.map((result: FuseResult<Quest>) => {
148194
const imageUrl = listings
149-
? listings[project_id]?.project_meta?.main_capsule
195+
? listings[result.item.project_id]?.project_meta?.main_capsule
150196
: ''
151197
if (imageUrl) {
152198
imagesToPreload.push(imageUrl)
153199
}
154-
const title = listings ? listings[project_id]?.project_meta?.name : ''
200+
const title = listings
201+
? listings[result.item.project_id]?.project_meta?.name
202+
: ''
203+
const id = result.item.id
204+
const name = result.item.name
155205
return (
156206
<QuestCard
157207
key={id}
158208
image={imageUrl ?? ''}
159209
title={title}
160-
{...rest}
161210
onClick={() => {
162211
if (selectedQuestId !== id) {
163212
navigate(`/quests/${id}`)
@@ -171,9 +220,11 @@ export function QuestsPage() {
171220
}) ?? []
172221

173222
let suggestedSearchTitles = undefined
174-
175223
if (searchText) {
176-
suggestedSearchTitles = searchFilteredQuests?.map((val) => val.name)
224+
suggestedSearchTitles = searchFilteredQuests?.map((val) => {
225+
const gameName = listings?.[val.item.project_id]?.project_meta?.name ?? ''
226+
return `${val.item.name} (${gameName})`
227+
})
177228
}
178229

179230
return (

0 commit comments

Comments
 (0)