poi-plugin-quest-info-2 0.12.2 → 0.12.4

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/src/patch.ts CHANGED
@@ -19,7 +19,7 @@ const isLegacyQuestPluginEnabled = async () => {
19
19
  const poiStore = await getPoiStore()
20
20
  const legacyQuestPlugin = poiStore
21
21
  .getState()
22
- .plugins.find((i) => i.id === LEGACY_QUEST_PLUGIN_ID)
22
+ .plugins?.find((i) => i.id === LEGACY_QUEST_PLUGIN_ID)
23
23
  if (legacyQuestPlugin && legacyQuestPlugin.enabled) {
24
24
  return true
25
25
  }
@@ -40,13 +40,21 @@ const getQuestState = (maybeLanguage: string) => {
40
40
  : QuestData[maybeLanguage]
41
41
 
42
42
  return Object.fromEntries(
43
- Object.entries(data).map(([apiNo, data]) => [
44
- apiNo,
45
- {
46
- wiki_id: data.code,
47
- condition: [(data as any).memo2, data.desc].filter(Boolean).join(' | '),
48
- },
49
- ]),
43
+ Object.entries(data).map(([apiNo, d]) => {
44
+ const typedData = d as (typeof data)[keyof typeof data]
45
+ return [
46
+ apiNo,
47
+ {
48
+ wiki_id: typedData.code,
49
+ condition: [
50
+ 'memo2' in typedData ? typedData.memo2 : undefined,
51
+ typedData.desc,
52
+ ]
53
+ .filter(Boolean)
54
+ .join(' | '),
55
+ },
56
+ ]
57
+ }),
50
58
  )
51
59
  }
52
60
 
@@ -57,13 +65,17 @@ const getQuestState = (maybeLanguage: string) => {
57
65
  */
58
66
  export const patchLegacyQuestPluginReducer = async () => {
59
67
  if (await isLegacyQuestPluginEnabled()) {
60
- // no clear if legacy quest plugin enabled
68
+ // skip patch if legacy quest plugin enabled
61
69
  return
62
70
  }
63
71
 
64
72
  try {
65
- const i18next: i18n = await importFromPoi('views/env-parts/i18next')
66
- const language = i18next.language
73
+ const i18next: i18n | { default: i18n; __esModule: true } =
74
+ await importFromPoi('views/env-parts/i18next')
75
+ // Fix https://github.com/poooi/poi/issues/2539
76
+ const language =
77
+ '__esModule' in i18next ? i18next.default.language : i18next.language
78
+
67
79
  const initState = {
68
80
  [HACK_KEY]: true,
69
81
  quests: getQuestState(language),
@@ -102,13 +114,13 @@ export const patchLegacyQuestPluginReducer = async () => {
102
114
  */
103
115
  export const clearPatchLegacyQuestPluginReducer = async () => {
104
116
  if (await isLegacyQuestPluginEnabled()) {
105
- // no clear if legacy quest plugin enabled
117
+ // skip clear if legacy quest plugin enabled
106
118
  return
107
119
  }
108
120
  try {
109
121
  const { extendReducer } = await importFromPoi('views/create-store')
110
122
  const clearReducer = undefined
111
- extendReducer('poi-plugin-quest-info', clearReducer)
123
+ extendReducer(LEGACY_QUEST_PLUGIN_ID, clearReducer)
112
124
  } catch (e) {
113
125
  console.error('Clear hack quest plugin reducer error', e)
114
126
  }