diff options
author | 2022-08-21 03:19:03 +0200 | |
---|---|---|
committer | 2022-08-21 03:19:03 +0200 | |
commit | 70dd02be202ae1b87ef8f7a2563ba09a3e7b0947 (patch) | |
tree | ddd34efea882a00e324000f84062c4cce28da814 /subprojects/frontend/src/editor/SearchToolbar.tsx | |
parent | feat(frontend): overlay window controls (diff) | |
download | refinery-70dd02be202ae1b87ef8f7a2563ba09a3e7b0947.tar.gz refinery-70dd02be202ae1b87ef8f7a2563ba09a3e7b0947.tar.zst refinery-70dd02be202ae1b87ef8f7a2563ba09a3e7b0947.zip |
refactor(frontend): improve code splitting
Diffstat (limited to 'subprojects/frontend/src/editor/SearchToolbar.tsx')
-rw-r--r-- | subprojects/frontend/src/editor/SearchToolbar.tsx | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/subprojects/frontend/src/editor/SearchToolbar.tsx b/subprojects/frontend/src/editor/SearchToolbar.tsx index 45f1336d..7e6ff4f7 100644 --- a/subprojects/frontend/src/editor/SearchToolbar.tsx +++ b/subprojects/frontend/src/editor/SearchToolbar.tsx | |||
@@ -20,12 +20,16 @@ import type SearchPanelStore from './SearchPanelStore'; | |||
20 | const SPLIT_MEDIA_QUERY = '@media (max-width: 1200px)'; | 20 | const SPLIT_MEDIA_QUERY = '@media (max-width: 1200px)'; |
21 | const ABBREVIATE_MEDIA_QUERY = '@media (max-width: 720px)'; | 21 | const ABBREVIATE_MEDIA_QUERY = '@media (max-width: 720px)'; |
22 | 22 | ||
23 | function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | 23 | function SearchToolbar({ |
24 | searchPanelStore, | ||
25 | }: { | ||
26 | searchPanelStore: SearchPanelStore; | ||
27 | }): JSX.Element { | ||
24 | const { | 28 | const { |
25 | id: panelId, | 29 | id: panelId, |
26 | query: { search, valid, caseSensitive, literal, regexp, replace }, | 30 | query: { search, valid, caseSensitive, literal, regexp, replace }, |
27 | invalidRegexp, | 31 | invalidRegexp, |
28 | } = store; | 32 | } = searchPanelStore; |
29 | const split = useMediaQuery(SPLIT_MEDIA_QUERY); | 33 | const split = useMediaQuery(SPLIT_MEDIA_QUERY); |
30 | const abbreviate = useMediaQuery(ABBREVIATE_MEDIA_QUERY); | 34 | const abbreviate = useMediaQuery(ABBREVIATE_MEDIA_QUERY); |
31 | const [showRepalceState, setShowReplaceState] = useState(false); | 35 | const [showRepalceState, setShowReplaceState] = useState(false); |
@@ -37,8 +41,8 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
37 | 41 | ||
38 | const searchFieldRef = useCallback( | 42 | const searchFieldRef = useCallback( |
39 | (element: HTMLInputElement | null) => | 43 | (element: HTMLInputElement | null) => |
40 | store.setSearchField(element ?? undefined), | 44 | searchPanelStore.setSearchField(element ?? undefined), |
41 | [store], | 45 | [searchPanelStore], |
42 | ); | 46 | ); |
43 | 47 | ||
44 | return ( | 48 | return ( |
@@ -68,15 +72,15 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
68 | value={search} | 72 | value={search} |
69 | error={invalidRegexp} | 73 | error={invalidRegexp} |
70 | onChange={(event) => | 74 | onChange={(event) => |
71 | store.updateQuery({ search: event.target.value }) | 75 | searchPanelStore.updateQuery({ search: event.target.value }) |
72 | } | 76 | } |
73 | onKeyDown={(event) => { | 77 | onKeyDown={(event) => { |
74 | if (event.key === 'Enter') { | 78 | if (event.key === 'Enter') { |
75 | event.preventDefault(); | 79 | event.preventDefault(); |
76 | if (event.shiftKey) { | 80 | if (event.shiftKey) { |
77 | store.findPrevious(); | 81 | searchPanelStore.findPrevious(); |
78 | } else { | 82 | } else { |
79 | store.findNext(); | 83 | searchPanelStore.findNext(); |
80 | } | 84 | } |
81 | } | 85 | } |
82 | }} | 86 | }} |
@@ -108,7 +112,7 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
108 | <IconButton | 112 | <IconButton |
109 | aria-label="Previous" | 113 | aria-label="Previous" |
110 | disabled={!valid} | 114 | disabled={!valid} |
111 | onClick={() => store.findPrevious()} | 115 | onClick={() => searchPanelStore.findPrevious()} |
112 | color="inherit" | 116 | color="inherit" |
113 | > | 117 | > |
114 | <KeyboardArrowUpIcon fontSize="small" /> | 118 | <KeyboardArrowUpIcon fontSize="small" /> |
@@ -116,7 +120,7 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
116 | <IconButton | 120 | <IconButton |
117 | aria-label="Next" | 121 | aria-label="Next" |
118 | disabled={!valid} | 122 | disabled={!valid} |
119 | onClick={() => store.findNext()} | 123 | onClick={() => searchPanelStore.findNext()} |
120 | color="inherit" | 124 | color="inherit" |
121 | > | 125 | > |
122 | <KeyboardArrowDownIcon fontSize="small" /> | 126 | <KeyboardArrowDownIcon fontSize="small" /> |
@@ -133,7 +137,9 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
133 | <Checkbox | 137 | <Checkbox |
134 | checked={caseSensitive} | 138 | checked={caseSensitive} |
135 | onChange={(event) => | 139 | onChange={(event) => |
136 | store.updateQuery({ caseSensitive: event.target.checked }) | 140 | searchPanelStore.updateQuery({ |
141 | caseSensitive: event.target.checked, | ||
142 | }) | ||
137 | } | 143 | } |
138 | size="small" | 144 | size="small" |
139 | /> | 145 | /> |
@@ -146,7 +152,9 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
146 | <Checkbox | 152 | <Checkbox |
147 | checked={literal} | 153 | checked={literal} |
148 | onChange={(event) => | 154 | onChange={(event) => |
149 | store.updateQuery({ literal: event.target.checked }) | 155 | searchPanelStore.updateQuery({ |
156 | literal: event.target.checked, | ||
157 | }) | ||
150 | } | 158 | } |
151 | size="small" | 159 | size="small" |
152 | /> | 160 | /> |
@@ -159,7 +167,9 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
159 | <Checkbox | 167 | <Checkbox |
160 | checked={regexp} | 168 | checked={regexp} |
161 | onChange={(event) => | 169 | onChange={(event) => |
162 | store.updateQuery({ regexp: event.target.checked }) | 170 | searchPanelStore.updateQuery({ |
171 | regexp: event.target.checked, | ||
172 | }) | ||
163 | } | 173 | } |
164 | size="small" | 174 | size="small" |
165 | /> | 175 | /> |
@@ -172,7 +182,7 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
172 | selected={showReplace} | 182 | selected={showReplace} |
173 | onClick={() => { | 183 | onClick={() => { |
174 | if (showReplace) { | 184 | if (showReplace) { |
175 | store.updateQuery({ replace: '' }); | 185 | searchPanelStore.updateQuery({ replace: '' }); |
176 | setShowReplaceState(false); | 186 | setShowReplaceState(false); |
177 | } else { | 187 | } else { |
178 | setShowReplaceState(true); | 188 | setShowReplaceState(true); |
@@ -201,12 +211,12 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
201 | aria-label="Replace with" | 211 | aria-label="Replace with" |
202 | value={replace} | 212 | value={replace} |
203 | onChange={(event) => | 213 | onChange={(event) => |
204 | store.updateQuery({ replace: event.target.value }) | 214 | searchPanelStore.updateQuery({ replace: event.target.value }) |
205 | } | 215 | } |
206 | onKeyDown={(event) => { | 216 | onKeyDown={(event) => { |
207 | if (event.key === 'Enter') { | 217 | if (event.key === 'Enter') { |
208 | event.preventDefault(); | 218 | event.preventDefault(); |
209 | store.replaceNext(); | 219 | searchPanelStore.replaceNext(); |
210 | } | 220 | } |
211 | }} | 221 | }} |
212 | variant="standard" | 222 | variant="standard" |
@@ -221,7 +231,7 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
221 | > | 231 | > |
222 | <Button | 232 | <Button |
223 | disabled={!valid} | 233 | disabled={!valid} |
224 | onClick={() => store.replaceNext()} | 234 | onClick={() => searchPanelStore.replaceNext()} |
225 | color="inherit" | 235 | color="inherit" |
226 | startIcon={<FindReplaceIcon fontSize="inherit" />} | 236 | startIcon={<FindReplaceIcon fontSize="inherit" />} |
227 | > | 237 | > |
@@ -229,7 +239,7 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
229 | </Button> | 239 | </Button> |
230 | <Button | 240 | <Button |
231 | disabled={!valid} | 241 | disabled={!valid} |
232 | onClick={() => store.replaceAll()} | 242 | onClick={() => searchPanelStore.replaceAll()} |
233 | color="inherit" | 243 | color="inherit" |
234 | startIcon={<FindReplaceIcon fontSize="inherit" />} | 244 | startIcon={<FindReplaceIcon fontSize="inherit" />} |
235 | > | 245 | > |
@@ -241,7 +251,7 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { | |||
241 | <Stack direction="row" alignSelf="stretch" alignItems="start" mt="1px"> | 251 | <Stack direction="row" alignSelf="stretch" alignItems="start" mt="1px"> |
242 | <IconButton | 252 | <IconButton |
243 | aria-label="Close find/replace" | 253 | aria-label="Close find/replace" |
244 | onClick={() => store.close()} | 254 | onClick={() => searchPanelStore.close()} |
245 | color="inherit" | 255 | color="inherit" |
246 | > | 256 | > |
247 | <CloseIcon fontSize="small" /> | 257 | <CloseIcon fontSize="small" /> |