poi-plugin-quest-info-2 0.9.15 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # poi-plugin-quest-info-2
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5e2ba3a: Highlight search results
8
+
3
9
  ## 0.9.15
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poi-plugin-quest-info-2",
3
- "version": "0.9.15",
3
+ "version": "0.10.0",
4
4
  "private": false,
5
5
  "description": "show quest info",
6
6
  "homepage": "https://github.com/lawvs/poi-plugin-quest-2/",
@@ -37,6 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "moize": "^6.1.1",
40
+ "react-highlight-words": "^0.20.0",
40
41
  "react-use": "^17.3.1",
41
42
  "react-virtualized-auto-sizer": "^1.0.6",
42
43
  "react-window": "^1.8.7"
@@ -51,6 +52,7 @@
51
52
  "@storybook/react": "^6.3.4",
52
53
  "@types/jest": "^27.4.1",
53
54
  "@types/pangu": "^3.3.0",
55
+ "@types/react-highlight-words": "^0.16.4",
54
56
  "@types/react-virtualized-auto-sizer": "^1.0.1",
55
57
  "@types/react-window": "^1.8.5",
56
58
  "@types/sharp": "^0.27.1",
package/src/Toolbar.tsx CHANGED
@@ -2,7 +2,6 @@ import { Button, InputGroup } from '@blueprintjs/core'
2
2
  import { IconNames } from '@blueprintjs/icons'
3
3
  import type { ChangeEvent } from 'react'
4
4
  import React, { useCallback } from 'react'
5
- import { useThrottle } from 'react-use'
6
5
  import styled from 'styled-components'
7
6
  import { usePluginTranslation } from './poi/hooks'
8
7
  import { QUEST_STATUS, UnionQuest } from './questHelper'
@@ -13,8 +12,8 @@ import {
13
12
  useSyncGameTagEffect,
14
13
  } from './store/filterTags'
15
14
  import { useGlobalQuestStatusQuery } from './store/gameQuest'
16
- import { useSearchInput } from './store/search'
17
- import { CategoryTags, CATEGORY_TAGS, TypeTags, TYPE_TAGS } from './tags'
15
+ import { useSearchInput, useStableSearchWords } from './store/search'
16
+ import { CATEGORY_TAGS, CategoryTags, TYPE_TAGS, TypeTags } from './tags'
18
17
  import { And, Or } from './utils'
19
18
 
20
19
  const ToolbarWrapper = styled.div`
@@ -71,14 +70,7 @@ export const Toolbar = () => {
71
70
  }
72
71
 
73
72
  const useInputStringFilter = () => {
74
- const { searchInput } = useSearchInput()
75
- const throttledSearchInput = useThrottle(searchInput)
76
- const searchKeywords = throttledSearchInput
77
- .split(' ')
78
- // Remove empty string
79
- .filter((i) => !!i)
80
- .map((i) => i.toUpperCase())
81
-
73
+ const searchKeywords = useStableSearchWords()
82
74
  const stringFilter = useCallback(
83
75
  (quest: UnionQuest) => {
84
76
  if (!searchKeywords || !searchKeywords.length) {
@@ -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
+ }