aboutsummaryrefslogtreecommitdiff
path: root/src/reducers/background.js
blob: 1bba13ba338b68121936953a1493ae31722c1e2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import * as tabs from '../background/tabs';
import * as zooms from '../background/zooms';
import * as consoleActions from '../actions/console';
import actions from '../actions';

const doCompletion = (command, keywords, sender) => {
  if (command === 'buffer') {
    return tabs.getCompletions(keywords).then((tabs) => {
      let items = tabs.map((tab) => {
        return {
          caption: tab.title,
          content: tab.title,
          url: tab.url,
          icon: tab.favIconUrl
        }
      });
      let completions = {
        name: "Buffers",
        items: items
      };
      return browser.tabs.sendMessage(
        sender,
        consoleActions.setCompletions([completions]));
    });
  }
  return Promise.resolve();
};

export default function reducer(state, action = {}, sender) {
  // TODO hide sender object
  switch (action.type) {
  case actions.BACKGROUND_REQUEST_COMPLETIONS:
    return doCompletion(action.command, action.keywords, sender.tab.id);
  default:
    return Promise.resolve();
  }
}