Skip to content

Commit

Permalink
feat(popup): bootstrap browser popup with react+redux (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmenant committed Oct 4, 2018
1 parent 4615e44 commit b09782f
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 37 deletions.
3 changes: 2 additions & 1 deletion manifest/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export default Object.freeze({
'48': 'img/logo/48x48.png',
'128': 'img/logo/128x128.png'
},
'default_title': 'LMEM options',
'default_title': 'Le Même en Mieux',
'default_popup': 'popup.html',
},
'permissions': [
'geolocation',
Expand Down
5 changes: 0 additions & 5 deletions src/app/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from './actions/kraftBackend';
import updateDraftRecommendations from './actions/updateDraftRecommendations';

import { OPEN_PREFERENCE_PANEL } from '../constants/ActionTypes';
import {LMEM_BACKEND_ORIGIN, LMEM_SCRIPTS_ORIGIN} from '../constants/origins';

/**
Expand Down Expand Up @@ -118,10 +117,6 @@ configureStore(store => {

store.dispatch(dispatchInitialStateFromBackend()); // store initialization from the kraft server

chrome.browserAction.onClicked.addListener(() => {
store.dispatch({ type: OPEN_PREFERENCE_PANEL });
});

if (process.env.NODE_ENV !== 'production') {
require('./inject');
}
Expand Down
46 changes: 46 additions & 0 deletions src/app/popup/PopupRoot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { PropTypes } from 'react';
import { Provider, connect } from 'react-redux';

import PopupScreen from './PopupScreen';
import uiActions from '../content/actions/ui.js';

import { IMAGES_URL } from '../constants/assetsUrls';
import {
PREFERENCE_SCREEN_PANEL_ABOUT,
PREFERENCE_SCREEN_PANEL_SOURCES,
} from '../constants/ui';

const {
openPrefScreen,
} = uiActions();


function mapStateToProps(state) {
return {
imagesUrl: IMAGES_URL,
};
}

function mapDispatchToProps(dispatch) {
return {
openPrefScreenAbout() { dispatch(openPrefScreen(PREFERENCE_SCREEN_PANEL_ABOUT)); },
// FIXME there is no reducer on this action, 'panel' is not used
openPrefScreenSources() { dispatch(openPrefScreen(PREFERENCE_SCREEN_PANEL_SOURCES)); },
};
}

const Popup = connect(mapStateToProps, mapDispatchToProps)(PopupScreen);

const PopupRoot = ({ store }) => (
<Provider store={store}>
<Popup />
</Provider>
);

PopupRoot.propTypes = {
store: PropTypes.object.isRequired
};

export default PopupRoot;


13 changes: 13 additions & 0 deletions src/app/popup/PopupScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { Component, PropTypes } from 'react';

export default function PopupScreen({ imagesUrl, openPrefScreenAbout, openPrefScreenSources }) {
return (
<section>
<p>Popup ok.</p>
<p>Image Src: {imagesUrl}</p>
<div><a onClick={openPrefScreenAbout} href>Préférences</a></div>
<div><a onClick={openPrefScreenSources} href>Sources de recommandation</a></div>
</section>
);
}

10 changes: 10 additions & 0 deletions src/app/popup/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { render } from 'react-dom';

import PopupRoot from './PopupRoot';

import 'style!../styles/main.scss'; // eslint-disable-line import/no-unresolved

const store = chrome.extension.getBackgroundPage().store;

render(<PopupRoot store={store} />, document.getElementById('root'));
9 changes: 9 additions & 0 deletions views/popup.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
doctype html

html
head
meta(charset="utf-8")
title LMEM Popup
body
#root
script(src=config.output.publicPath + '/js/popup.bundle.js')
16 changes: 13 additions & 3 deletions webpack/base.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import path from 'path';
import webpack from 'webpack';

const srcPath = path.join(__dirname, '../src/app');

const baseConfig = ({ input, output = {}, globals = {}, plugins = [], loaders = [] }) => ({
entry: input,
entry: Object.assign(
{
background: [path.join(srcPath, './background/')],
content: [path.join(srcPath, './content/')],
options: [path.join(srcPath, './options/')],
popup: [path.join(srcPath, './popup/')],
},
input
),
output: Object.assign(
{
filename: 'js/[name].bundle.js',
Expand All @@ -17,8 +27,8 @@ const baseConfig = ({ input, output = {}, globals = {}, plugins = [], loaders =
],
resolve: {
alias: {
app: path.join(__dirname, '../src/app'),
extension: path.join(__dirname, '../src/app/background')
app: srcPath,
extension: path.join(srcPath, './background')
},
extensions: ['', '.js']
},
Expand Down
5 changes: 0 additions & 5 deletions webpack/chromium.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import baseConfig from './base.config';
const srcPath = path.join(__dirname, '../src/app/');

export default baseConfig({
input: {
background: [`${srcPath}background/`],
content: [`${srcPath}content/`],
options: [`${srcPath}options/`],
},
output: {
path: path.join(__dirname, '../build/chromium'),
publicPath: '.',
Expand Down
8 changes: 1 addition & 7 deletions webpack/dev.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import path from 'path';
import baseConfig from './base.config';
const srcPath = path.join(__dirname, '../src/app/');
const testPath = path.join(__dirname, '../test/');


export default baseConfig({
input: {
background: [`${srcPath}background/`],
content: [`${srcPath}content/`],
options: [`${srcPath}options/`],
test: [`${testPath}integration/`]
test: [path.join(__dirname, '../test/integration/')],
},
output: {
path: path.join(__dirname, '../build/dev'),
Expand Down
11 changes: 6 additions & 5 deletions webpack/firefox.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import baseConfig from './base.config';
const srcPath = path.join(__dirname, '../src/app/');

export default baseConfig({
input: {
background: [`${srcPath}background/`],
content: [`${srcPath}content/`],
options: [`${srcPath}options/`],
},
output: {
path: path.join(__dirname, '../build/firefox'),
publicPath: '.', // No remote URL with Firefox
Expand All @@ -20,6 +15,12 @@ export default baseConfig({
}],
plugins: [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
comments: false,
compressor: {
warnings: false
}
})
],
globals: {
'process.env': {
Expand Down
11 changes: 0 additions & 11 deletions webpack/staging.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@ import baseConfig from './base.config';
const srcPath = path.join(__dirname, '../src/app/');

export default baseConfig({
input: {
background: [`${srcPath}background/`],
content: [`${srcPath}content/`],
options: [`${srcPath}options/`]
},
output: {
path: path.join(__dirname, '../build/staging'),
publicPath: '.',
sftp: {
// See .ftppass https://github.com/gtg092x/gulp-sftp#authentication
auth: 'keyMain',
host: 'sftp.dc0.gpaas.net',
remotePath: '/lamp0/web/vhosts/testing-ui.lmem.net/htdocs/'
}
},
globals: {
'process.env': {
Expand Down

0 comments on commit b09782f

Please sign in to comment.