Add support for instance-specific panel

Closes #12
parent 4b8b31c4
import api from '../api';
export const TOS_FETCH_REQUEST = 'TOS_FETCH_REQUEST';
export const TOS_FETCH_SUCCESS = 'TOS_FETCH_SUCCESS';
export const TOS_FETCH_FAIL = 'TOS_FETCH_FAIL';
export const PANEL_FETCH_REQUEST = 'PANEL_FETCH_REQUEST';
export const PANEL_FETCH_SUCCESS = 'PANEL_FETCH_SUCCESS';
export const PANEL_FETCH_FAIL = 'PANEL_FETCH_FAIL';
export const PLEROMA_CONFIG_FETCH_REQUEST = 'PLEROMA_CONFIG_FETCH_REQUEST';
export const PLEROMA_CONFIG_FETCH_SUCCESS = 'PLEROMA_CONFIG_FETCH_SUCCESS';
export const PLEROMA_CONFIG_FETCH_FAIL = 'PLEROMA_CONFIG_FETCH_FAIL';
export function fetchTOS() {
return (dispatch, getState) => {
dispatch(fetchTOSRequest());
api(getState).get('/static/terms-of-service.html').then(response => {
dispatch(fetchTOSSuccess(response.data));
}).catch(error => {
dispatch(fetchTOSFail(error));
});
};
};
export function fetchPanel() {
return (dispatch, getState) => {
dispatch(fetchPanelRequest());
api(getState).get('/instance/panel.html').then(response => {
dispatch(fetchPanelSuccess(response.data));
}).catch(error => {
dispatch(fetchPanelFail(error));
});
};
};
export function fetchPleromaConfig() {
return (dispatch, getState) => {
dispatch(fetchPleromaConfigRequest());
api(getState).get('/static/config.json').then(response => {
dispatch(fetchPleromaConfigSuccess(response.data));
}).catch(error => {
dispatch(fetchPleromaConfigFail(error));
});
};
};
export function fetchTOSRequest() {
return {
type: TOS_FETCH_REQUEST,
};
};
export function fetchTOSSuccess(tos) {
return {
type: TOS_FETCH_SUCCESS,
tos,
};
};
export function fetchTOSFail(error) {
return {
type: TOS_FETCH_FAIL,
error,
};
};
export function fetchPanelRequest() {
return {
type: PANEL_FETCH_REQUEST,
};
};
export function fetchPanelSuccess(panel) {
return {
type: PANEL_FETCH_SUCCESS,
panel,
};
};
export function fetchPanelFail(error) {
return {
type: PANEL_FETCH_FAIL,
error,
};
};
export function fetchPleromaConfigRequest() {
return {
type: PLEROMA_CONFIG_FETCH_REQUEST,
};
};
export function fetchPleromaConfigSuccess(config) {
return {
type: PLEROMA_CONFIG_FETCH_SUCCESS,
config,
};
};
export function fetchPleromaConfigFail(error) {
return {
type: PLEROMA_CONFIG_FETCH_FAIL,
error,
};
};
import api from '../api';
export const TOS_FETCH_REQUEST = 'TOS_FETCH_REQUEST';
export const TOS_FETCH_SUCCESS = 'TOS_FETCH_SUCCESS';
export const TOS_FETCH_FAIL = 'TOS_FETCH_FAIL';
export function fetchTOS() {
return (dispatch, getState) => {
dispatch(fetchTOSRequest());
api(getState).get('/static/terms-of-service.html').then(response => {
dispatch(fetchTOSSuccess(response));
}).catch(error => {
dispatch(fetchTOSFail(error));
});
};
};
export function fetchTOSRequest() {
return {
type: TOS_FETCH_REQUEST,
};
};
export function fetchTOSSuccess(data) {
return {
type: TOS_FETCH_SUCCESS,
data,
};
};
export function fetchTOSFail(error) {
return {
type: TOS_FETCH_FAIL,
error,
};
};
......@@ -9,6 +9,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { me } from '../../initial_state';
import { fetchFollowRequests } from '../../actions/accounts';
import { fetchPanel, fetchPleromaConfig } from '../../actions/pleroma';
import { List as ImmutableList } from 'immutable';
const messages = defineMessages({
......@@ -32,10 +33,14 @@ const mapStateToProps = state => ({
columns: state.getIn(['settings', 'columns']),
unreadFollowRequests: state.getIn(['user_lists', 'follow_requests', 'items'], ImmutableList()).size,
unreadNotifications: state.getIn(['notifications', 'unread']),
customPanelEnabled: state.getIn(['custom_panel', 'enabled']),
customPanel: state.getIn(['custom_panel', 'panel']),
});
const mapDispatchToProps = dispatch => ({
fetchFollowRequests: () => dispatch(fetchFollowRequests()),
fetchPanel: () => dispatch(fetchPanel()),
fetchPleromaConfig: () => dispatch(fetchPleromaConfig()),
});
const badgeDisplay = (number, limit) => {
......@@ -58,20 +63,27 @@ export default class GettingStarted extends ImmutablePureComponent {
columns: ImmutablePropTypes.list,
multiColumn: PropTypes.bool,
fetchFollowRequests: PropTypes.func.isRequired,
fetchPanel: PropTypes.func.isRequired,
fetchPleromaConfig: PropTypes.func.isRequired,
unreadFollowRequests: PropTypes.number,
unreadNotifications: PropTypes.number,
customPanelEnabled: PropTypes.bool,
customPanel: PropTypes.string.isRequired,
};
componentDidMount () {
const { myAccount, fetchFollowRequests } = this.props;
const { myAccount, fetchFollowRequests, fetchPleromaConfig, fetchPanel } = this.props;
if (myAccount.get('locked')) {
fetchFollowRequests();
}
fetchPleromaConfig();
fetchPanel();
}
render () {
const { intl, myAccount, columns, multiColumn, unreadFollowRequests, unreadNotifications } = this.props;
const { intl, myAccount, columns, multiColumn, unreadFollowRequests, unreadNotifications, customPanelEnabled, customPanel } = this.props;
const navItems = [];
......@@ -105,6 +117,19 @@ export default class GettingStarted extends ImmutablePureComponent {
navItems.push(<ColumnLink key='7' icon='question' text={intl.formatMessage(messages.keyboard_shortcuts)} to='/keyboard-shortcuts' />);
}
const dot = ' • ';
const staticContent = (customPanelEnabled ? <div dangerouslySetInnerHTML={{__html: customPanel}} style={{marginLeft: -12, marginRight: -12}} /> :
<p>
<a href='https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/FAQ.md' rel='noopener' target='_blank'><FormattedMessage id='getting_started.faq' defaultMessage='FAQ' /></a>
{dot}
<a href='https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/User-guide.md' rel='noopener' target='_blank'><FormattedMessage id='getting_started.userguide' defaultMessage='User Guide' /></a>
{dot}
<a href='https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/Apps.md' rel='noopener' target='_blank'><FormattedMessage id='getting_started.appsshort' defaultMessage='Apps' /></a>
{dot}
<a href='https://pleroma.social'><FormattedMessage id='getting_started.pleroma' defaultMessage='Pleroma' /></a>
</p>
);
return (
<Column icon='asterisk' heading={intl.formatMessage(messages.heading)} hideHeadingOnMobile>
<div className='getting-started__wrapper'>
......@@ -117,9 +142,7 @@ export default class GettingStarted extends ImmutablePureComponent {
</div>
<div className='static-content getting-started'>
<p>
<a href='https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/FAQ.md' rel='noopener' target='_blank'><FormattedMessage id='getting_started.faq' defaultMessage='FAQ' /></a> • <a href='https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/User-guide.md' rel='noopener' target='_blank'><FormattedMessage id='getting_started.userguide' defaultMessage='User Guide' /></a> • <a href='https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/Apps.md' rel='noopener' target='_blank'><FormattedMessage id='getting_started.appsshort' defaultMessage='Apps' /></a> • <a href='https://pleroma.social'><FormattedMessage id='getting_started.pleroma' defaultMessage='Pleroma' /></a>
</p>
{staticContent}
</div>
</Column>
);
......
......@@ -23,6 +23,7 @@ import notifications from './notifications';
import height_cache from './height_cache';
import custom_emojis from './custom_emojis';
import listEditor from './list_editor';
import { custom_panel } from './pleroma';
const reducers = {
dropdown_menu,
......@@ -49,6 +50,7 @@ const reducers = {
height_cache,
custom_emojis,
listEditor,
custom_panel,
};
export default combineReducers(reducers);
import { Map as ImmutableMap } from 'immutable';
import { PANEL_FETCH_SUCCESS, PLEROMA_CONFIG_FETCH_SUCCESS } from '../actions/pleroma';
const initialPanel = ImmutableMap({
enabled: false,
panel: ''
});
export function custom_panel(state = initialPanel, action) {
switch (action.type) {
case PANEL_FETCH_SUCCESS:
return state.set('panel', action.panel); break;
case PLEROMA_CONFIG_FETCH_SUCCESS:
return state.set('enabled', (action.config || {}).showInstanceSpecificPanel || false);
}
return state;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment