diff options
Diffstat (limited to 'src/content')
-rw-r--r-- | src/content/components/top-content/find.ts | 36 | ||||
-rw-r--r-- | src/content/components/top-content/index.ts | 2 | ||||
-rw-r--r-- | src/content/controllers/FindController.ts | 24 | ||||
-rw-r--r-- | src/content/index.ts | 16 | ||||
-rw-r--r-- | src/content/usecases/FindUseCase.ts | 2 |
5 files changed, 41 insertions, 39 deletions
diff --git a/src/content/components/top-content/find.ts b/src/content/components/top-content/find.ts deleted file mode 100644 index c25cbeb..0000000 --- a/src/content/components/top-content/find.ts +++ /dev/null @@ -1,36 +0,0 @@ -import * as messages from '../../../shared/messages'; -import MessageListener from '../../MessageListener'; - -import FindUseCase from '../../usecases/FindUseCase'; - -let findUseCase = new FindUseCase(); - -export default class FindComponent { - constructor() { - new MessageListener().onWebMessage(this.onMessage.bind(this)); - } - - onMessage(message: messages.Message) { - switch (message.type) { - case messages.CONSOLE_ENTER_FIND: - return this.start(message.text); - case messages.FIND_NEXT: - return this.next(); - case messages.FIND_PREV: - return this.prev(); - } - return Promise.resolve(); - } - - start(text: string) { - return findUseCase.startFind(text.length === 0 ? null : text); - } - - next() { - return findUseCase.findNext(); - } - - prev() { - return findUseCase.findPrev(); - } -} diff --git a/src/content/components/top-content/index.ts b/src/content/components/top-content/index.ts index de14b3f..0f07653 100644 --- a/src/content/components/top-content/index.ts +++ b/src/content/components/top-content/index.ts @@ -1,6 +1,5 @@ import CommonComponent from '../common'; import FollowController from './follow-controller'; -import FindComponent from './find'; import * as consoleFrames from '../../console-frames'; import * as messages from '../../../shared/messages'; import MessageListener from '../../MessageListener'; @@ -18,7 +17,6 @@ export default class TopContent { new CommonComponent(win, store); // eslint-disable-line no-new new FollowController(win, store); // eslint-disable-line no-new - new FindComponent(); // eslint-disable-line no-new // TODO make component consoleFrames.initialize(this.win.document); diff --git a/src/content/controllers/FindController.ts b/src/content/controllers/FindController.ts new file mode 100644 index 0000000..cf27a8d --- /dev/null +++ b/src/content/controllers/FindController.ts @@ -0,0 +1,24 @@ +import * as messages from '../../shared/messages'; +import FindUseCase from '../usecases/FindUseCase'; + +export default class FindController { + private findUseCase: FindUseCase; + + constructor({ + findUseCase = new FindUseCase(), + } = {}) { + this.findUseCase = findUseCase; + } + + async start(m: messages.ConsoleEnterFindMessage): Promise<void> { + await this.findUseCase.startFind(m.text); + } + + async next(_: messages.FindNextMessage): Promise<void> { + await this.findUseCase.findNext(); + } + + async prev(_: messages.FindPrevMessage): Promise<void> { + await this.findUseCase.findPrev(); + } +} diff --git a/src/content/index.ts b/src/content/index.ts index 9d791fc..4024b98 100644 --- a/src/content/index.ts +++ b/src/content/index.ts @@ -2,11 +2,27 @@ import TopContentComponent from './components/top-content'; import FrameContentComponent from './components/frame-content'; import consoleFrameStyle from './site-style'; import { newStore } from './store'; +import MessageListener from './MessageListener'; +import FindController from './controllers/FindController'; +import * as messages from '../shared/messages'; const store = newStore(); if (window.self === window.top) { new TopContentComponent(window, store); // eslint-disable-line no-new + + let findController = new FindController(); + new MessageListener().onWebMessage((message: messages.Message) => { + switch (message.type) { + case messages.CONSOLE_ENTER_FIND: + return findController.start(message); + case messages.FIND_NEXT: + return findController.next(message); + case messages.FIND_PREV: + return findController.prev(message); + } + return undefined; + }); } else { new FrameContentComponent(window, store); // eslint-disable-line no-new } diff --git a/src/content/usecases/FindUseCase.ts b/src/content/usecases/FindUseCase.ts index 4fda323..74cbc97 100644 --- a/src/content/usecases/FindUseCase.ts +++ b/src/content/usecases/FindUseCase.ts @@ -25,7 +25,7 @@ export default class FindUseCase { this.consoleClient = consoleClient; } - async startFind(keyword: string | null): Promise<void> { + async startFind(keyword?: string): Promise<void> { this.presenter.clearSelection(); if (keyword) { this.saveKeyword(keyword); |