poi-plugin-quest-info-2 0.6.7 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Toolbar.tsx +28 -15
- package/src/poi/hooks.ts +10 -1
- package/src/poi/types.ts +11 -8
- package/src/reducer.ts +4 -2
- package/src/store/filterTags.ts +49 -1
- package/src/store/quest.ts +2 -4
- package/src/tags.ts +5 -5
package/package.json
CHANGED
package/src/Toolbar.tsx
CHANGED
|
@@ -8,11 +8,10 @@ import { IN_POI } from './poi/env'
|
|
|
8
8
|
import { usePluginTranslation } from './poi/hooks'
|
|
9
9
|
import type { UnionQuest } from './questHelper'
|
|
10
10
|
import { useQuest, useSyncWithGame } from './store'
|
|
11
|
-
import { useFilterTags } from './store/filterTags'
|
|
11
|
+
import { useFilterTags, useSyncGameTagEffect } from './store/filterTags'
|
|
12
12
|
import { useSearchInput } from './store/search'
|
|
13
13
|
import {
|
|
14
14
|
ALL_CATEGORY_TAG,
|
|
15
|
-
ALL_TAGS,
|
|
16
15
|
ALL_TYPE_TAG,
|
|
17
16
|
CATEGORY_TAGS,
|
|
18
17
|
TYPE_TAGS,
|
|
@@ -95,6 +94,8 @@ export const SearchInput: React.FC = () => {
|
|
|
95
94
|
const Tags = () => {
|
|
96
95
|
const { t } = usePluginTranslation()
|
|
97
96
|
|
|
97
|
+
useSyncGameTagEffect()
|
|
98
|
+
|
|
98
99
|
const { typeTags, categoryTags, setCategoryTags, setTypeTags } =
|
|
99
100
|
useFilterTags()
|
|
100
101
|
|
|
@@ -150,14 +151,8 @@ export const Toolbar = () => {
|
|
|
150
151
|
)
|
|
151
152
|
}
|
|
152
153
|
|
|
153
|
-
const
|
|
154
|
+
const useInputStringFilter = () => {
|
|
154
155
|
const { searchInput } = useSearchInput()
|
|
155
|
-
const { typeTags, categoryTags } = useFilterTags()
|
|
156
|
-
|
|
157
|
-
const activatedTags = { ...typeTags, ...categoryTags }
|
|
158
|
-
const activatedTagsName = ALL_TAGS.filter((tag) => activatedTags[tag.name])
|
|
159
|
-
const tagsFilter = activatedTagsName.map((tag) => tag.filter)
|
|
160
|
-
|
|
161
156
|
const throttledSearchInput = useThrottle(searchInput)
|
|
162
157
|
const searchKeywords = throttledSearchInput
|
|
163
158
|
.split(' ')
|
|
@@ -179,14 +174,32 @@ const useToolbarFilter = () => {
|
|
|
179
174
|
},
|
|
180
175
|
[searchKeywords]
|
|
181
176
|
)
|
|
177
|
+
return stringFilter
|
|
178
|
+
}
|
|
182
179
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
180
|
+
const And =
|
|
181
|
+
<T extends (...args: any[]) => boolean>(...fnArray: T[]) =>
|
|
182
|
+
(...args: Parameters<T>) =>
|
|
183
|
+
fnArray.every((fn) => fn(...args))
|
|
184
|
+
|
|
185
|
+
const Or =
|
|
186
|
+
<T extends (...args: any[]) => boolean>(...fnArray: T[]) =>
|
|
187
|
+
(...args: Parameters<T>) =>
|
|
188
|
+
fnArray.some((fn) => fn(...args))
|
|
189
189
|
|
|
190
|
+
const useToolbarFilter = () => {
|
|
191
|
+
const stringFilter = useInputStringFilter()
|
|
192
|
+
const { typeTags, categoryTags } = useFilterTags()
|
|
193
|
+
|
|
194
|
+
const typeTagsFilter = Or(
|
|
195
|
+
...TYPE_TAGS.filter((tag) => typeTags[tag.name]).map((tag) => tag.filter)
|
|
196
|
+
)
|
|
197
|
+
const categoryTagsFilter = Or(
|
|
198
|
+
...CATEGORY_TAGS.filter((tag) => categoryTags[tag.name]).map(
|
|
199
|
+
(tag) => tag.filter
|
|
200
|
+
)
|
|
201
|
+
)
|
|
202
|
+
const toolbarFilter = And(stringFilter, typeTagsFilter, categoryTagsFilter)
|
|
190
203
|
return toolbarFilter
|
|
191
204
|
}
|
|
192
205
|
|
package/src/poi/hooks.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'
|
|
|
2
2
|
import { useTranslation } from 'react-i18next'
|
|
3
3
|
import { observePluginStore, observePoiStore } from './store'
|
|
4
4
|
import { name as PACKAGE_NAME } from '../../package.json'
|
|
5
|
-
import
|
|
5
|
+
import { GameQuest, PoiQuestState, PoiState, QuestTab } from './types'
|
|
6
6
|
|
|
7
7
|
export const useActiveQuest = () => {
|
|
8
8
|
const [activeQuests, setActiveQuests] = useState<PoiQuestState>({})
|
|
@@ -34,6 +34,15 @@ export const useGameQuest = () => {
|
|
|
34
34
|
return quests
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
export const useGameTab = () => {
|
|
38
|
+
const [tab, setTab] = useState<QuestTab>(QuestTab.ALL)
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const listener = (tabId: QuestTab | null) => setTab(tabId ?? QuestTab.ALL)
|
|
41
|
+
return observePluginStore(listener, (i) => i?._?.tabId)
|
|
42
|
+
}, [])
|
|
43
|
+
return tab
|
|
44
|
+
}
|
|
45
|
+
|
|
37
46
|
const UNKNOWN_TAB = 'unknown'
|
|
38
47
|
const useActiveTab = () => {
|
|
39
48
|
const [activeMainTab, setActiveMainTab] = useState<string>(UNKNOWN_TAB)
|
package/src/poi/types.ts
CHANGED
|
@@ -60,19 +60,22 @@ export type GameQuest = {
|
|
|
60
60
|
api_bonus_flag: 1
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
export enum QuestTab {
|
|
64
|
+
ALL = '0',
|
|
65
|
+
IN_PROGRESS = '9',
|
|
66
|
+
DAILY = '1',
|
|
67
|
+
WEEKLY = '2',
|
|
68
|
+
MONTHLY = '3',
|
|
69
|
+
ONCE = '4',
|
|
70
|
+
OTHERS = '5',
|
|
71
|
+
}
|
|
72
|
+
|
|
63
73
|
type QuestListAction = {
|
|
64
74
|
type: '@@Response/kcsapi/api_get_member/questlist'
|
|
65
75
|
path: '/kcsapi/api_get_member/questlist'
|
|
66
76
|
postBody: {
|
|
67
77
|
api_verno: '1'
|
|
68
|
-
api_tab_id:
|
|
69
|
-
| '0' // All
|
|
70
|
-
| '9' // In progress
|
|
71
|
-
| '1' // Daily
|
|
72
|
-
| '2' // Weekly
|
|
73
|
-
| '3' // Monthly
|
|
74
|
-
| '4' // Once
|
|
75
|
-
| '5' // Others
|
|
78
|
+
api_tab_id: QuestTab
|
|
76
79
|
}
|
|
77
80
|
body: {
|
|
78
81
|
api_completed_kind: number
|
package/src/reducer.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { GameQuest, PoiAction, QuestTab } from './poi/types'
|
|
2
2
|
|
|
3
3
|
const initState = {
|
|
4
4
|
questList: null as null | GameQuest[],
|
|
5
|
+
tabId: QuestTab.ALL,
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
export type PluginState = { _: typeof initState }
|
|
@@ -12,11 +13,12 @@ export const reducer = (
|
|
|
12
13
|
): typeof initState => {
|
|
13
14
|
switch (action.type) {
|
|
14
15
|
case '@@Response/kcsapi/api_get_member/questlist': {
|
|
15
|
-
const { body } = action
|
|
16
|
+
const { body, postBody } = action
|
|
16
17
|
|
|
17
18
|
return {
|
|
18
19
|
...state,
|
|
19
20
|
questList: body.api_list,
|
|
21
|
+
tabId: postBody.api_tab_id,
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
default:
|
package/src/store/filterTags.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { useCallback } from 'react'
|
|
2
|
+
import { useUpdateEffect } from 'react-use'
|
|
3
|
+
import { useGameTab } from '../poi/hooks'
|
|
4
|
+
import { QuestTab } from '../poi/types'
|
|
2
5
|
import {
|
|
3
6
|
ALL_CATEGORY_TAG,
|
|
4
7
|
ALL_TYPE_TAG,
|
|
5
8
|
CATEGORY_TAGS,
|
|
6
9
|
TYPE_TAGS,
|
|
7
10
|
} from '../tags'
|
|
8
|
-
import { useStore } from './store'
|
|
11
|
+
import { useStore, useSyncWithGame } from './store'
|
|
9
12
|
|
|
10
13
|
export const useFilterTags = () => {
|
|
11
14
|
const {
|
|
@@ -29,6 +32,13 @@ export const useFilterTags = () => {
|
|
|
29
32
|
},
|
|
30
33
|
[updateStore]
|
|
31
34
|
)
|
|
35
|
+
const manualSetTypeTags = useCallback(
|
|
36
|
+
(data: Record<string, boolean>) => {
|
|
37
|
+
updateStore({ typeTags: data })
|
|
38
|
+
},
|
|
39
|
+
[updateStore]
|
|
40
|
+
)
|
|
41
|
+
|
|
32
42
|
const setTypeTagsAll = useCallback(() => {
|
|
33
43
|
setTypeTags(ALL_TYPE_TAG.name)
|
|
34
44
|
}, [setTypeTags])
|
|
@@ -39,6 +49,44 @@ export const useFilterTags = () => {
|
|
|
39
49
|
setCategoryTags,
|
|
40
50
|
setCategoryTagsAll,
|
|
41
51
|
setTypeTags,
|
|
52
|
+
manualSetTypeTags,
|
|
42
53
|
setTypeTagsAll,
|
|
43
54
|
}
|
|
44
55
|
}
|
|
56
|
+
|
|
57
|
+
export const useSyncGameTagEffect = () => {
|
|
58
|
+
const { syncWithGame } = useSyncWithGame()
|
|
59
|
+
const filterTags = useFilterTags()
|
|
60
|
+
const tab = useGameTab()
|
|
61
|
+
|
|
62
|
+
useUpdateEffect(() => {
|
|
63
|
+
if (!syncWithGame) {
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
switch (tab) {
|
|
67
|
+
case QuestTab.ALL:
|
|
68
|
+
filterTags.setTypeTagsAll()
|
|
69
|
+
break
|
|
70
|
+
case QuestTab.DAILY:
|
|
71
|
+
filterTags.setTypeTags('Daily')
|
|
72
|
+
break
|
|
73
|
+
case QuestTab.WEEKLY:
|
|
74
|
+
filterTags.setTypeTags('Weekly')
|
|
75
|
+
break
|
|
76
|
+
case QuestTab.MONTHLY:
|
|
77
|
+
filterTags.setTypeTags('Monthly')
|
|
78
|
+
break
|
|
79
|
+
case QuestTab.IN_PROGRESS:
|
|
80
|
+
filterTags.setTypeTags('In Progress')
|
|
81
|
+
break
|
|
82
|
+
case QuestTab.OTHERS:
|
|
83
|
+
filterTags.manualSetTypeTags({ Quarterly: true, Yearly: true })
|
|
84
|
+
break
|
|
85
|
+
case QuestTab.ONCE:
|
|
86
|
+
filterTags.setTypeTags('One-time')
|
|
87
|
+
break
|
|
88
|
+
default:
|
|
89
|
+
break
|
|
90
|
+
}
|
|
91
|
+
}, [syncWithGame, tab])
|
|
92
|
+
}
|
package/src/store/quest.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { useGameQuest, usePluginTranslation } from '../poi/hooks'
|
|
|
4
4
|
import { getCategory } from '../questHelper'
|
|
5
5
|
import type { UnionQuest } from '../questHelper'
|
|
6
6
|
import { useKcwikiData, checkIsKcwikiSupportedLanguages } from './kcwiki'
|
|
7
|
-
import { useStore } from './store'
|
|
7
|
+
import { useStore, useSyncWithGame } from './store'
|
|
8
8
|
|
|
9
9
|
const DEFAULT_LANG = 'ja-JP'
|
|
10
10
|
|
|
@@ -40,9 +40,7 @@ const useQuestMap = () => {
|
|
|
40
40
|
export const useQuest = (): UnionQuest[] => {
|
|
41
41
|
const docQuestMap = useQuestMap()
|
|
42
42
|
const gameQuest = useGameQuest()
|
|
43
|
-
const {
|
|
44
|
-
store: { syncWithGame },
|
|
45
|
-
} = useStore()
|
|
43
|
+
const { syncWithGame } = useSyncWithGame()
|
|
46
44
|
|
|
47
45
|
if (syncWithGame && gameQuest.length) {
|
|
48
46
|
return gameQuest.map((quest) => {
|
package/src/tags.ts
CHANGED
|
@@ -49,18 +49,18 @@ export const CATEGORY_TAGS = [
|
|
|
49
49
|
|
|
50
50
|
export const TYPE_TAGS = [
|
|
51
51
|
ALL_TYPE_TAG,
|
|
52
|
-
...(IN_POI
|
|
52
|
+
...(IN_POI
|
|
53
|
+
? ([{ name: 'In Progress', filter: isInProgressQuest }] as const)
|
|
54
|
+
: []),
|
|
53
55
|
...(hasNewQuest
|
|
54
|
-
? [{ name: 'New', filter: isNewQuest, suffix: newQuestNumber }]
|
|
56
|
+
? ([{ name: 'New', filter: isNewQuest, suffix: newQuestNumber }] as const)
|
|
55
57
|
: []),
|
|
56
58
|
{ name: 'Daily', filter: isDailyQuest },
|
|
57
59
|
{ name: 'Weekly', filter: isWeeklyQuest },
|
|
58
60
|
{ name: 'Monthly', filter: isMonthlyQuest },
|
|
61
|
+
{ name: 'One-time', filter: isSingleQuest },
|
|
59
62
|
{ name: 'Quarterly', filter: isQuarterlyQuest },
|
|
60
63
|
{ name: 'Yearly', filter: isYearlyQuest },
|
|
61
|
-
{ name: 'One-time', filter: isSingleQuest },
|
|
62
64
|
] as const
|
|
63
65
|
|
|
64
66
|
// TODO tag In Progress / Lock / Completed
|
|
65
|
-
|
|
66
|
-
export const ALL_TAGS = [...CATEGORY_TAGS, ...TYPE_TAGS]
|