poi-plugin-quest-info-2 0.9.14 → 0.10.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.
@@ -1,13 +1,15 @@
1
1
  import { Card, Elevation, H5 } from '@blueprintjs/core'
2
2
  import React, { forwardRef } from 'react'
3
+ import Highlighter from 'react-highlight-words'
3
4
  import type { StyledComponentProps } from 'styled-components'
4
5
  import { usePluginTranslation } from '../../poi/hooks'
5
6
  import {
7
+ QUEST_STATUS,
6
8
  getQuestPrePost,
7
9
  guessQuestCategory,
8
- QUEST_STATUS,
9
10
  } from '../../questHelper'
10
11
  import { useQuestStatus } from '../../store/quest'
12
+ import { useStableSearchWords } from '../../store/search'
11
13
  import { QuestTag } from '../QuestTag'
12
14
  import {
13
15
  CardActionWrapper,
@@ -24,7 +26,7 @@ export type QuestCardProps = {
24
26
  gameId: number
25
27
  code: string
26
28
  name: string
27
- desc: string | JSX.Element
29
+ desc: string
28
30
  tip?: string
29
31
  tip2?: string
30
32
  status?: QUEST_STATUS
@@ -70,6 +72,7 @@ export const QuestCard = forwardRef<
70
72
  const status = useQuestStatus(gameId)
71
73
  const headIcon = questIconMap[guessQuestCategory(code).type]
72
74
  const TailIcon = questStatusMap[status]
75
+ const searchWords = useStableSearchWords()
73
76
 
74
77
  return (
75
78
  <FlexCard
@@ -80,10 +83,38 @@ export const QuestCard = forwardRef<
80
83
  >
81
84
  <CardMedia src={headIcon}></CardMedia>
82
85
  <CardBody>
83
- <H5>{[code, name].filter((i) => i != undefined).join(' - ')}</H5>
84
- <div>{desc}</div>
85
- {tip2 && <b>{tip2}</b>}
86
- {tip && <i>{tip}</i>}
86
+ <H5>
87
+ <Highlighter
88
+ searchWords={searchWords}
89
+ autoEscape={false}
90
+ textToHighlight={[code, name]
91
+ .filter((i) => i != undefined)
92
+ .join(' - ')}
93
+ />
94
+ </H5>
95
+ <Highlighter
96
+ searchWords={searchWords}
97
+ autoEscape={false}
98
+ textToHighlight={desc}
99
+ />
100
+ {tip2 && (
101
+ <b>
102
+ <Highlighter
103
+ searchWords={searchWords}
104
+ autoEscape={false}
105
+ textToHighlight={tip2}
106
+ />
107
+ </b>
108
+ )}
109
+ {tip && (
110
+ <i>
111
+ <Highlighter
112
+ searchWords={searchWords}
113
+ autoEscape={false}
114
+ textToHighlight={tip}
115
+ />
116
+ </i>
117
+ )}
87
118
 
88
119
  <CardAction gameId={gameId}></CardAction>
89
120
  </CardBody>
@@ -1,4 +1,5 @@
1
1
  import { useCallback } from 'react'
2
+ import { useThrottle } from 'react-use'
2
3
  import { useStore } from './store'
3
4
 
4
5
  export const useSearchInput = () => {
@@ -15,3 +16,15 @@ export const useSearchInput = () => {
15
16
  setSearchInput,
16
17
  }
17
18
  }
19
+
20
+ export const useStableSearchWords = () => {
21
+ const { searchInput } = useSearchInput()
22
+ const throttledSearchInput = useThrottle(searchInput)
23
+ const searchKeywords = throttledSearchInput
24
+ .split(' ')
25
+ // Remove empty string
26
+ .filter((i) => !!i)
27
+ .map((i) => i.toUpperCase())
28
+
29
+ return searchKeywords
30
+ }