logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe
commit: 8d064c253644cba25c3b1eef424db6daa4a13471
parent: 4b8b31c4075016c70fac236ea938a91737c76216
Author: Morgan Bazalgette <the@howl.moe>
Date:   Sat, 21 Apr 2018 17:58:19 +0200

Add support for instance-specific panel

Closes #12

Diffstat:

Aapp/javascript/mastodon/actions/pleroma.js107+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dapp/javascript/mastodon/actions/tos.js37-------------------------------------
Mapp/javascript/mastodon/features/getting_started/index.js33++++++++++++++++++++++++++++-----
Mapp/javascript/mastodon/reducers/index.js2++
Aapp/javascript/mastodon/reducers/pleroma.js18++++++++++++++++++
5 files changed, 155 insertions(+), 42 deletions(-)

diff --git a/app/javascript/mastodon/actions/pleroma.js b/app/javascript/mastodon/actions/pleroma.js @@ -0,0 +1,107 @@ +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, + }; +}; diff --git a/app/javascript/mastodon/actions/tos.js b/app/javascript/mastodon/actions/tos.js @@ -1,37 +0,0 @@ -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, - }; -}; diff --git a/app/javascript/mastodon/features/getting_started/index.js b/app/javascript/mastodon/features/getting_started/index.js @@ -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> ); diff --git a/app/javascript/mastodon/reducers/index.js b/app/javascript/mastodon/reducers/index.js @@ -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); diff --git a/app/javascript/mastodon/reducers/pleroma.js b/app/javascript/mastodon/reducers/pleroma.js @@ -0,0 +1,18 @@ +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; +};