2018-12-17 20:03:36 +01:00
|
|
|
import Bottle from 'bottlejs';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
2018-12-18 14:54:54 +01:00
|
|
|
import { connect as reduxConnect } from 'react-redux';
|
2018-12-17 22:18:47 +01:00
|
|
|
import { assoc, pick } from 'ramda';
|
|
|
|
import axios from 'axios';
|
2018-12-17 20:03:36 +01:00
|
|
|
import App from '../App';
|
|
|
|
import ScrollToTop from '../common/ScrollToTop';
|
|
|
|
import MainHeader from '../common/MainHeader';
|
2018-12-18 19:45:09 +01:00
|
|
|
import { resetSelectedServer } from '../servers/reducers/selectedServer';
|
2018-12-17 20:03:36 +01:00
|
|
|
import Home from '../common/Home';
|
2018-12-17 20:24:31 +01:00
|
|
|
import MenuLayout from '../common/MenuLayout';
|
2018-12-17 22:18:47 +01:00
|
|
|
import ShortUrls from '../short-urls/ShortUrls';
|
|
|
|
import SearchBar from '../short-urls/SearchBar';
|
|
|
|
import { listShortUrls } from '../short-urls/reducers/shortUrlsList';
|
|
|
|
import ShortUrlsList from '../short-urls/ShortUrlsList';
|
|
|
|
import { resetShortUrlParams } from '../short-urls/reducers/shortUrlsListParams';
|
|
|
|
import { ColorGenerator } from '../utils/ColorGenerator';
|
|
|
|
import { Storage } from '../utils/Storage';
|
|
|
|
import ShortUrlsRow from '../short-urls/helpers/ShortUrlsRow';
|
|
|
|
import ShortUrlsRowMenu from '../short-urls/helpers/ShortUrlsRowMenu';
|
|
|
|
import AsideMenu from '../common/AsideMenu';
|
2018-12-17 23:11:55 +01:00
|
|
|
import CreateShortUrl from '../short-urls/CreateShortUrl';
|
|
|
|
import { createShortUrl, resetCreateShortUrl } from '../short-urls/reducers/shortUrlCreation';
|
|
|
|
import DeleteShortUrlModal from '../short-urls/helpers/DeleteShortUrlModal';
|
|
|
|
import { deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted } from '../short-urls/reducers/shortUrlDeletion';
|
|
|
|
import EditTagsModal from '../short-urls/helpers/EditTagsModal';
|
|
|
|
import { editShortUrlTags, resetShortUrlsTags, shortUrlTagsEdited } from '../short-urls/reducers/shortUrlTags';
|
2018-12-18 10:14:25 +01:00
|
|
|
import buildShlinkApiClient from '../api/ShlinkApiClientBuilder';
|
2018-12-18 19:45:09 +01:00
|
|
|
import provideServersServices from '../servers/services/provideServices';
|
2018-12-18 14:54:54 +01:00
|
|
|
import provideVisitsServices from '../visits/services/provideServices';
|
|
|
|
import provideTagsServices from '../tags/services/provideServices';
|
2018-12-17 20:03:36 +01:00
|
|
|
|
|
|
|
const bottle = new Bottle();
|
2018-12-18 04:34:37 +01:00
|
|
|
const { container } = bottle;
|
|
|
|
|
2018-12-18 10:14:25 +01:00
|
|
|
const mapActionService = (map, actionName) => ({
|
|
|
|
...map,
|
2018-12-18 04:34:37 +01:00
|
|
|
|
2018-12-18 10:14:25 +01:00
|
|
|
// Wrap actual action service in a function so that it is lazily created the first time it is called
|
|
|
|
[actionName]: (...args) => container[actionName](...args),
|
|
|
|
});
|
2018-12-18 14:54:54 +01:00
|
|
|
const connect = (propsFromState, actionServiceNames) =>
|
|
|
|
reduxConnect(
|
2018-12-18 19:45:09 +01:00
|
|
|
propsFromState ? pick(propsFromState) : null,
|
2018-12-18 04:34:37 +01:00
|
|
|
Array.isArray(actionServiceNames) ? actionServiceNames.reduce(mapActionService, {}) : actionServiceNames
|
|
|
|
);
|
2018-12-17 20:03:36 +01:00
|
|
|
|
2018-12-17 22:18:47 +01:00
|
|
|
bottle.constant('ScrollToTop', ScrollToTop);
|
|
|
|
bottle.decorator('ScrollToTop', withRouter);
|
|
|
|
|
2018-12-18 19:45:09 +01:00
|
|
|
bottle.serviceFactory('App', App, 'MainHeader', 'Home', 'MenuLayout', 'CreateServer');
|
|
|
|
|
2018-12-17 22:18:47 +01:00
|
|
|
bottle.serviceFactory('MainHeader', MainHeader, 'ServersDropdown');
|
|
|
|
bottle.decorator('MainHeader', withRouter);
|
|
|
|
|
|
|
|
bottle.serviceFactory('Home', () => Home);
|
2018-12-18 14:54:54 +01:00
|
|
|
bottle.decorator('Home', connect([ 'servers' ], { resetSelectedServer }));
|
2018-12-17 22:18:47 +01:00
|
|
|
|
2018-12-18 14:32:02 +01:00
|
|
|
bottle.serviceFactory(
|
|
|
|
'MenuLayout',
|
|
|
|
MenuLayout,
|
|
|
|
'TagsList',
|
|
|
|
'ShortUrls',
|
|
|
|
'AsideMenu',
|
|
|
|
'CreateShortUrl',
|
|
|
|
'ShortUrlVisits'
|
|
|
|
);
|
2018-12-18 19:45:09 +01:00
|
|
|
bottle.decorator('MenuLayout', connect([ 'selectedServer', 'shortUrlsListParams' ], [ 'selectServer' ]));
|
2018-12-18 04:34:37 +01:00
|
|
|
bottle.decorator('MenuLayout', withRouter);
|
2018-12-17 22:18:47 +01:00
|
|
|
|
2018-12-18 19:45:09 +01:00
|
|
|
bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton');
|
2018-12-17 22:18:47 +01:00
|
|
|
|
2018-12-18 19:45:09 +01:00
|
|
|
bottle.constant('localStorage', global.localStorage);
|
|
|
|
bottle.service('Storage', Storage, 'localStorage');
|
|
|
|
bottle.service('ColorGenerator', ColorGenerator, 'Storage');
|
2018-12-17 20:03:36 +01:00
|
|
|
|
2018-12-18 19:45:09 +01:00
|
|
|
bottle.constant('axios', axios);
|
|
|
|
bottle.serviceFactory('buildShlinkApiClient', buildShlinkApiClient, 'axios');
|
2018-12-17 22:18:47 +01:00
|
|
|
|
|
|
|
bottle.serviceFactory('ShortUrls', ShortUrls, 'SearchBar', 'ShortUrlsList');
|
2018-12-18 14:54:54 +01:00
|
|
|
bottle.decorator('ShortUrls', reduxConnect(
|
2018-12-17 22:18:47 +01:00
|
|
|
(state) => assoc('shortUrlsList', state.shortUrlsList.shortUrls, state.shortUrlsList)
|
|
|
|
));
|
|
|
|
|
2018-12-18 11:28:15 +01:00
|
|
|
bottle.serviceFactory('SearchBar', SearchBar, 'ColorGenerator');
|
2018-12-18 14:54:54 +01:00
|
|
|
bottle.decorator('SearchBar', connect([ 'shortUrlsListParams' ], { listShortUrls }));
|
2018-12-17 22:18:47 +01:00
|
|
|
|
|
|
|
bottle.serviceFactory('ShortUrlsList', ShortUrlsList, 'ShortUrlsRow');
|
2018-12-18 14:54:54 +01:00
|
|
|
bottle.decorator('ShortUrlsList', connect(
|
2018-12-18 04:34:37 +01:00
|
|
|
[ 'selectedServer', 'shortUrlsListParams' ],
|
2018-12-18 19:45:09 +01:00
|
|
|
[ 'listShortUrls', 'resetShortUrlParams' ]
|
2018-12-17 22:18:47 +01:00
|
|
|
));
|
|
|
|
|
2018-12-18 11:28:15 +01:00
|
|
|
bottle.serviceFactory('ShortUrlsRow', ShortUrlsRow, 'ShortUrlsRowMenu', 'ColorGenerator');
|
2018-12-17 22:18:47 +01:00
|
|
|
|
2018-12-17 23:11:55 +01:00
|
|
|
bottle.serviceFactory('ShortUrlsRowMenu', ShortUrlsRowMenu, 'DeleteShortUrlModal', 'EditTagsModal');
|
2018-12-17 22:18:47 +01:00
|
|
|
|
2018-12-17 23:11:55 +01:00
|
|
|
bottle.serviceFactory('CreateShortUrl', CreateShortUrl, 'TagsSelector');
|
2018-12-18 14:54:54 +01:00
|
|
|
bottle.decorator('CreateShortUrl', connect([ 'shortUrlCreationResult' ], {
|
2018-12-17 23:11:55 +01:00
|
|
|
createShortUrl,
|
|
|
|
resetCreateShortUrl,
|
|
|
|
}));
|
|
|
|
|
|
|
|
bottle.serviceFactory('DeleteShortUrlModal', () => DeleteShortUrlModal);
|
2018-12-18 14:54:54 +01:00
|
|
|
bottle.decorator('DeleteShortUrlModal', connect(
|
2018-12-18 04:34:37 +01:00
|
|
|
[ 'shortUrlDeletion' ],
|
2018-12-17 23:11:55 +01:00
|
|
|
{ deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted }
|
|
|
|
));
|
2018-12-18 04:54:32 +01:00
|
|
|
|
2018-12-17 23:11:55 +01:00
|
|
|
bottle.serviceFactory('EditTagsModal', EditTagsModal, 'TagsSelector');
|
2018-12-18 14:54:54 +01:00
|
|
|
bottle.decorator('EditTagsModal', connect(
|
2018-12-18 04:34:37 +01:00
|
|
|
[ 'shortUrlTags' ],
|
2018-12-18 04:54:32 +01:00
|
|
|
[ 'editShortUrlTags', 'resetShortUrlsTags', 'shortUrlTagsEdited' ]
|
2018-12-17 23:11:55 +01:00
|
|
|
));
|
|
|
|
|
2018-12-18 10:14:25 +01:00
|
|
|
bottle.serviceFactory('editShortUrlTags', editShortUrlTags, 'buildShlinkApiClient');
|
2018-12-18 05:03:38 +01:00
|
|
|
bottle.serviceFactory('resetShortUrlsTags', () => resetShortUrlsTags);
|
|
|
|
bottle.serviceFactory('shortUrlTagsEdited', () => shortUrlTagsEdited);
|
|
|
|
|
2018-12-18 19:45:09 +01:00
|
|
|
bottle.serviceFactory('listShortUrls', listShortUrls, 'buildShlinkApiClient');
|
|
|
|
bottle.serviceFactory('resetShortUrlParams', () => resetShortUrlParams);
|
|
|
|
|
|
|
|
provideServersServices(bottle, connect, withRouter);
|
2018-12-18 14:54:54 +01:00
|
|
|
provideTagsServices(bottle, connect);
|
|
|
|
provideVisitsServices(bottle, connect);
|
2018-12-18 14:32:02 +01:00
|
|
|
|
2018-12-18 04:34:37 +01:00
|
|
|
export default container;
|