Skip to content

Commit af0efbe

Browse files
committed
fix: quest conditions with similar quest titles
1 parent dc84bcc commit af0efbe

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

server/src/models/Pokestop.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,9 @@ class Pokestop extends Model {
894894
(filters.onlyAllPokestops ||
895895
(filters[newQuest.key] &&
896896
(filters[newQuest.key].adv && !filters[newQuest.key].all
897-
? filters[newQuest.key].adv.includes(quest.quest_title)
897+
? filters[newQuest.key].adv.includes(
898+
`${quest.quest_title}__${quest.quest_target}`,
899+
)
898900
: true)) ||
899901
filters[`u${quest.quest_reward_type}`])
900902
) {

src/components/filters/QuestConditions.jsx

+9-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export function QuestConditionSelector({ id }) {
2626

2727
const [open, setOpen] = React.useState(false)
2828

29+
const handleClose = () => setOpen(false)
30+
31+
const handleOpen = () => setOpen(true)
32+
2933
// Provides a reset if that condition is no longer available
3034
React.useEffect(() => {
3135
if (hasQuests) {
@@ -39,7 +43,9 @@ export function QuestConditionSelector({ id }) {
3943
? value
4044
.split(',')
4145
.filter((each) =>
42-
questConditions.find(({ title }) => title === each),
46+
questConditions.find(
47+
({ title, target }) => `${title}__${target}` === each,
48+
),
4349
)
4450
: []
4551
setValue(filtered.length ? filtered.join(',') : '')
@@ -50,14 +56,6 @@ export function QuestConditionSelector({ id }) {
5056
}
5157
}, [questConditions, id, hasQuests])
5258

53-
const handleClose = () => {
54-
setOpen(false)
55-
}
56-
57-
const handleOpen = () => {
58-
setOpen(true)
59-
}
60-
6159
if (!questConditions) return null
6260

6361
return (
@@ -89,6 +87,7 @@ export function QuestConditionSelector({ id }) {
8987
? e.target.value.filter(Boolean).join(',')
9088
: e.target.value,
9189
)
90+
if (e.target.value.length === 0) handleClose()
9291
}
9392
}}
9493
fcSx={{ my: 1 }}
@@ -100,7 +99,7 @@ export function QuestConditionSelector({ id }) {
10099
.slice()
101100
.sort((a, b) => a.title.localeCompare(b.title))
102101
.map(({ title, target }) => (
103-
<MenuItem key={`${title}-${target}`} value={title}>
102+
<MenuItem key={`${title}-${target}`} value={`${title}__${target}`}>
104103
<QuestTitle questTitle={title} questTarget={target} />
105104
</MenuItem>
106105
))}

src/features/drawer/pokestops/Quests.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ const BaseQuestQuickSelect = () => {
3838
</CollapsibleItem>
3939
)
4040
}
41+
4142
export const QuestQuickSelect = React.memo(BaseQuestQuickSelect)

src/hooks/useMapData.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,30 @@ export function useMapData(once = false) {
104104
questConditions,
105105
},
106106
}))
107-
useStorage.setState((prev) => ({
108-
filters: deepMerge({}, filters, prev.filters),
109-
}))
107+
useStorage.setState((prev) => {
108+
const newFilters = deepMerge({}, filters, prev.filters)
109+
110+
// Migration for quest conditions to use target as well
111+
Object.entries(newFilters?.pokestops?.filter || {}).forEach(
112+
([key, filter]) => {
113+
if (filter.adv && questConditions[key]) {
114+
const newAdv = filter.adv
115+
.split(',')
116+
.flatMap((each) =>
117+
questConditions[key]
118+
.filter(({ title }) => title === each)
119+
.map(({ target }) => `${each}__${target}`),
120+
)
121+
if (newAdv.length) {
122+
filter.adv = newAdv.join(',')
123+
}
124+
}
125+
},
126+
)
127+
return {
128+
filters: newFilters,
129+
}
130+
})
110131
}
111132
}, [data])
112133

0 commit comments

Comments
 (0)