Find as a controller

jh-changes
Shin'ya Ueoka 6 years ago
parent ad1f3c07fb
commit fcd15f4f09
  1. 2
      .eslintrc
  2. 2
      src/console/actions/console.ts
  3. 3
      src/console/components/Console.tsx
  4. 36
      src/content/components/top-content/find.ts
  5. 2
      src/content/components/top-content/index.ts
  6. 24
      src/content/controllers/FindController.ts
  7. 16
      src/content/index.ts
  8. 2
      src/content/usecases/FindUseCase.ts
  9. 66
      src/shared/messages.ts

@ -79,6 +79,6 @@
"react/jsx-indent": ["error", 2],
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"@typescript-eslint/no-unused-vars": "error"
"@typescript-eslint/no-unused-vars": ["error", { args: "none" }],
}
}

@ -53,7 +53,7 @@ const enterCommand = async(
return hideCommand();
};
const enterFind = (text: string): actions.ConsoleAction => {
const enterFind = (text?: string): actions.ConsoleAction => {
window.top.postMessage(JSON.stringify({
type: messages.CONSOLE_ENTER_FIND,
text,

@ -38,7 +38,8 @@ class Console extends React.Component<Props> {
if (this.props.mode === 'command') {
return this.props.dispatch(consoleActions.enterCommand(value));
} else if (this.props.mode === 'find') {
return this.props.dispatch(consoleActions.enterFind(value));
return this.props.dispatch(consoleActions.enterFind(
value === '' ? undefined : value));
}
}

@ -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();
}
}

@ -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);

@ -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();
}
}

@ -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
}

@ -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);

@ -42,162 +42,162 @@ export const SETTINGS_QUERY = 'settings.query';
export const CONSOLE_FRAME_MESSAGE = 'console.frame.message';
interface BackgroundOperationMessage {
export interface BackgroundOperationMessage {
type: typeof BACKGROUND_OPERATION;
operation: operations.Operation;
}
interface ConsoleUnfocusMessage {
export interface ConsoleUnfocusMessage {
type: typeof CONSOLE_UNFOCUS;
}
interface ConsoleEnterCommandMessage {
export interface ConsoleEnterCommandMessage {
type: typeof CONSOLE_ENTER_COMMAND;
text: string;
}
interface ConsoleEnterFindMessage {
export interface ConsoleEnterFindMessage {
type: typeof CONSOLE_ENTER_FIND;
text: string;
text?: string;
}
interface ConsoleQueryCompletionsMessage {
export interface ConsoleQueryCompletionsMessage {
type: typeof CONSOLE_QUERY_COMPLETIONS;
text: string;
}
interface ConsoleShowCommandMessage {
export interface ConsoleShowCommandMessage {
type: typeof CONSOLE_SHOW_COMMAND;
command: string;
}
interface ConsoleShowErrorMessage {
export interface ConsoleShowErrorMessage {
type: typeof CONSOLE_SHOW_ERROR;
text: string;
}
interface ConsoleShowInfoMessage {
export interface ConsoleShowInfoMessage {
type: typeof CONSOLE_SHOW_INFO;
text: string;
}
interface ConsoleShowFindMessage {
export interface ConsoleShowFindMessage {
type: typeof CONSOLE_SHOW_FIND;
}
interface ConsoleHideMessage {
export interface ConsoleHideMessage {
type: typeof CONSOLE_HIDE;
}
interface FollowStartMessage {
export interface FollowStartMessage {
type: typeof FOLLOW_START;
newTab: boolean;
background: boolean;
}
interface FollowRequestCountTargetsMessage {
export interface FollowRequestCountTargetsMessage {
type: typeof FOLLOW_REQUEST_COUNT_TARGETS;
viewSize: { width: number, height: number };
framePosition: { x: number, y: number };
}
interface FollowResponseCountTargetsMessage {
export interface FollowResponseCountTargetsMessage {
type: typeof FOLLOW_RESPONSE_COUNT_TARGETS;
count: number;
}
interface FollowCreateHintsMessage {
export interface FollowCreateHintsMessage {
type: typeof FOLLOW_CREATE_HINTS;
keysArray: string[];
newTab: boolean;
background: boolean;
}
interface FollowShowHintsMessage {
export interface FollowShowHintsMessage {
type: typeof FOLLOW_SHOW_HINTS;
keys: string;
}
interface FollowRemoveHintsMessage {
export interface FollowRemoveHintsMessage {
type: typeof FOLLOW_REMOVE_HINTS;
}
interface FollowActivateMessage {
export interface FollowActivateMessage {
type: typeof FOLLOW_ACTIVATE;
keys: string;
}
interface FollowKeyPressMessage {
export interface FollowKeyPressMessage {
type: typeof FOLLOW_KEY_PRESS;
key: string;
ctrlKey: boolean;
}
interface MarkSetGlobalMessage {
export interface MarkSetGlobalMessage {
type: typeof MARK_SET_GLOBAL;
key: string;
x: number;
y: number;
}
interface MarkJumpGlobalMessage {
export interface MarkJumpGlobalMessage {
type: typeof MARK_JUMP_GLOBAL;
key: string;
}
interface TabScrollToMessage {
export interface TabScrollToMessage {
type: typeof TAB_SCROLL_TO;
x: number;
y: number;
}
interface FindNextMessage {
export interface FindNextMessage {
type: typeof FIND_NEXT;
}
interface FindPrevMessage {
export interface FindPrevMessage {
type: typeof FIND_PREV;
}
interface FindGetKeywordMessage {
export interface FindGetKeywordMessage {
type: typeof FIND_GET_KEYWORD;
}
interface FindSetKeywordMessage {
export interface FindSetKeywordMessage {
type: typeof FIND_SET_KEYWORD;
keyword: string;
found: boolean;
}
interface AddonEnabledQueryMessage {
export interface AddonEnabledQueryMessage {
type: typeof ADDON_ENABLED_QUERY;
}
interface AddonEnabledResponseMessage {
export interface AddonEnabledResponseMessage {
type: typeof ADDON_ENABLED_RESPONSE;
enabled: boolean;
}
interface AddonToggleEnabledMessage {
export interface AddonToggleEnabledMessage {
type: typeof ADDON_TOGGLE_ENABLED;
}
interface OpenUrlMessage {
export interface OpenUrlMessage {
type: typeof OPEN_URL;
url: string;
newTab: boolean;
background: boolean;
}
interface SettingsChangedMessage {
export interface SettingsChangedMessage {
type: typeof SETTINGS_CHANGED;
}
interface SettingsQueryMessage {
export interface SettingsQueryMessage {
type: typeof SETTINGS_QUERY;
}
interface ConsoleFrameMessageMessage {
export interface ConsoleFrameMessageMessage {
type: typeof CONSOLE_FRAME_MESSAGE;
message: any;
}