|
1 | 1 | import { createCommandsMiddleware } from './commands'; |
2 | 2 | import { createMentionsMiddleware } from './mentions'; |
3 | 3 | import { createTextComposerPreValidationMiddleware } from './validation'; |
| 4 | +import { MiddlewareExecutor } from '../../../middleware'; |
4 | 5 | import type { |
5 | 6 | ExecuteParams, |
6 | 7 | MiddlewareExecutionResult, |
7 | 8 | MiddlewareHandler, |
8 | 9 | } from '../../../middleware'; |
9 | | -import { MiddlewareExecutor } from '../../../middleware'; |
10 | | -import { withCancellation } from '../../../utils/concurrency'; |
11 | 10 | import type { |
12 | 11 | Suggestion, |
| 12 | + Suggestions, |
13 | 13 | TextComposerMiddlewareExecutorOptions, |
14 | 14 | TextComposerState, |
15 | 15 | } from './types'; |
@@ -58,28 +58,14 @@ export class TextComposerMiddlewareExecutor< |
58 | 58 | initialValue: initialState, |
59 | 59 | }); |
60 | 60 |
|
61 | | - if (result && result.state.suggestions) { |
62 | | - try { |
63 | | - const searchResult = await withCancellation( |
64 | | - 'textComposer-suggestions-search', |
65 | | - async () => { |
66 | | - await result.state.suggestions?.searchSource.search( |
67 | | - result.state.suggestions?.query, |
68 | | - ); |
69 | | - }, |
70 | | - ); |
71 | | - if (searchResult === 'canceled') return { ...result, status: 'discard' }; |
72 | | - } catch (error) { |
73 | | - // Clear suggestions on search error |
74 | | - return { |
75 | | - ...result, |
76 | | - state: { |
77 | | - ...result.state, |
78 | | - suggestions: undefined, |
79 | | - }, |
80 | | - }; |
81 | | - } |
82 | | - } |
| 61 | + const { query, searchSource } = result.state.suggestions ?? ({} as Suggestions); |
| 62 | + /** |
| 63 | + * Catching error just for sanity purposes. |
| 64 | + * The BaseSearchSource.search() method returns debounced result. |
| 65 | + * That means the result of the previous search call as the debounced call result is unknown at the moment. |
| 66 | + * Custom search source implementation should handle errors meaningfully internally. |
| 67 | + */ |
| 68 | + searchSource?.search(query)?.catch(console.error); |
83 | 69 |
|
84 | 70 | return result; |
85 | 71 | } |
|
0 commit comments