feat share: Ability to share files using Web Activities
feat pick: Ability to pick files for other apps
This commit is contained in:
15
src/js/actions/pick.js
Normal file
15
src/js/actions/pick.js
Normal file
@ -0,0 +1,15 @@
|
||||
import { PICK } from 'actions/types';
|
||||
|
||||
export function enable(request) {
|
||||
return {
|
||||
type: PICK,
|
||||
active: request
|
||||
}
|
||||
}
|
||||
|
||||
export function disable() {
|
||||
return {
|
||||
type: PICK,
|
||||
active: false
|
||||
}
|
||||
}
|
@ -20,14 +20,15 @@ const TYPES = {
|
||||
MOVE_FILE: Symbol('MOVE_FILE'),
|
||||
|
||||
MENU: Symbol('MENU'),
|
||||
|
||||
DIALOG: Symbol('DIALOG'),
|
||||
|
||||
SPINNER: Symbol('SPINNER'),
|
||||
|
||||
SETTINGS: Symbol('SETTINGS'),
|
||||
|
||||
SEARCH: Symbol('SEARCH')
|
||||
SEARCH: Symbol('SEARCH'),
|
||||
|
||||
PICK: Symbol('PICK')
|
||||
};
|
||||
|
||||
export default TYPES;
|
||||
|
8
src/js/activities.js
Normal file
8
src/js/activities.js
Normal file
@ -0,0 +1,8 @@
|
||||
import { enable } from 'actions/pick';
|
||||
import store from 'store';
|
||||
|
||||
navigator.mozSetMessageHandler('activity', request => {
|
||||
if (request.source.name === 'pick') {
|
||||
store.dispatch(enable(request));
|
||||
}
|
||||
});
|
@ -8,8 +8,9 @@ export default class Menu extends Component {
|
||||
items = items || [];
|
||||
|
||||
let els = items.map((item, index) => {
|
||||
let disabled = !(typeof item.enabled === 'function' ? item.enabled() : true)
|
||||
let className = disabled ? 'disabled' : '';
|
||||
let enabled = typeof item.enabled === 'function' ? item.enabled() : true
|
||||
console.log(enabled);
|
||||
let className = enabled ? '' : 'disabled';
|
||||
|
||||
return <li key={index} className={className} onClick={item.action.bind(this)}>{item.name}</li>
|
||||
});
|
||||
|
@ -103,7 +103,8 @@ export default {
|
||||
let action = search(input.value);
|
||||
this.props.dispatch(action);
|
||||
this.props.dispatch(hideAll());
|
||||
}
|
||||
},
|
||||
className: 'success'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import React from 'react';
|
||||
import Root from 'components/root';
|
||||
import store from 'store';
|
||||
import { Provider } from 'react-redux';
|
||||
import './activities';
|
||||
|
||||
let wrapper = document.getElementById('wrapper');
|
||||
React.render(<Provider store={store}>{() => <Root />}</Provider>, wrapper);
|
||||
|
@ -33,6 +33,36 @@ const entryMenu = {
|
||||
store.dispatch(selectView(false));
|
||||
store.dispatch(hideAll());
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'Share',
|
||||
action() {
|
||||
let active = store.getState().get('activeFile');
|
||||
|
||||
new MozActivity({
|
||||
name: 'share',
|
||||
data: {
|
||||
number: 1,
|
||||
blobs: active
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'Pick',
|
||||
enabled() {
|
||||
return store.getState().get('pick');
|
||||
},
|
||||
action() {
|
||||
let request = store.getState().get('pick');
|
||||
|
||||
let active = store.getState().get('activeFile');
|
||||
let blob = active[0];
|
||||
request.postResult({
|
||||
type: blob.type,
|
||||
blob
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
@ -58,7 +88,7 @@ const moreMenu = {
|
||||
store.dispatch(show('deleteDialog', {description}));
|
||||
},
|
||||
enabled() {
|
||||
return store.getState().get('activeFile');
|
||||
return store.getState().get('selectView');
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -96,7 +126,21 @@ const moreMenu = {
|
||||
store.dispatch(move(active, cwd));
|
||||
store.dispatch(hideAll());
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'Share',
|
||||
action() {
|
||||
let active = store.getState().get('activeFile');
|
||||
|
||||
new MozActivity({
|
||||
name: 'share',
|
||||
data: {
|
||||
number: active.length,
|
||||
blobs: active
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import settings from './settings';
|
||||
import selectView from './select-view';
|
||||
import spinner from './spinner';
|
||||
import search from './search';
|
||||
import pick from './pick';
|
||||
|
||||
export default function(state = new Immutable.Map(), action) {
|
||||
console.log('action', action);
|
||||
@ -20,6 +21,7 @@ export default function(state = new Immutable.Map(), action) {
|
||||
search: search(state.get('search'), action),
|
||||
spinner: spinner(state.get('spinner'), action),
|
||||
selectView: selectView(state.get('selectView'), action),
|
||||
pick: pick(state.get('pick'), action),
|
||||
activeFile: activeFile(state.get('activeFile'), action),
|
||||
navigation: navigation(state.get('navigation'), action),
|
||||
settings: settings(state.get('settings'), action),
|
||||
|
9
src/js/reducers/pick.js
Normal file
9
src/js/reducers/pick.js
Normal file
@ -0,0 +1,9 @@
|
||||
import { PICK } from 'actions/types';
|
||||
|
||||
export default function(state = false, action) {
|
||||
if (action.type === PICK) {
|
||||
return action.active;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
@ -36,5 +36,15 @@
|
||||
"https://marketplace.firefox.com",
|
||||
"https://marketplace-dev.allizom.org"
|
||||
],
|
||||
"default_locale": "en"
|
||||
"default_locale": "en",
|
||||
"activities": {
|
||||
"pick": {
|
||||
"href": "./index.html",
|
||||
"disposition": "inline",
|
||||
"filters": {
|
||||
"type": "*"
|
||||
},
|
||||
"returnValue": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user