Merge pull request #1861 from ClearlyClaire/glitch-soc/features/logged-out-webui
Port logged-out Web UI to glitch-socth-downstream
commit
93efea5049
@ -0,0 +1,8 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Api::V2::InstancesController < Api::V1::InstancesController
|
||||||
|
def show
|
||||||
|
expires_in 3.minutes, public: true
|
||||||
|
render_with_cache json: InstancePresenter.new, serializer: REST::InstanceSerializer, root: 'instance'
|
||||||
|
end
|
||||||
|
end
|
@ -1,27 +0,0 @@
|
|||||||
import api from 'flavours/glitch/util/api';
|
|
||||||
|
|
||||||
export const RULES_FETCH_REQUEST = 'RULES_FETCH_REQUEST';
|
|
||||||
export const RULES_FETCH_SUCCESS = 'RULES_FETCH_SUCCESS';
|
|
||||||
export const RULES_FETCH_FAIL = 'RULES_FETCH_FAIL';
|
|
||||||
|
|
||||||
export const fetchRules = () => (dispatch, getState) => {
|
|
||||||
dispatch(fetchRulesRequest());
|
|
||||||
|
|
||||||
api(getState)
|
|
||||||
.get('/api/v1/instance').then(({ data }) => dispatch(fetchRulesSuccess(data.rules)))
|
|
||||||
.catch(err => dispatch(fetchRulesFail(err)));
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchRulesRequest = () => ({
|
|
||||||
type: RULES_FETCH_REQUEST,
|
|
||||||
});
|
|
||||||
|
|
||||||
const fetchRulesSuccess = rules => ({
|
|
||||||
type: RULES_FETCH_SUCCESS,
|
|
||||||
rules,
|
|
||||||
});
|
|
||||||
|
|
||||||
const fetchRulesFail = error => ({
|
|
||||||
type: RULES_FETCH_FAIL,
|
|
||||||
error,
|
|
||||||
});
|
|
@ -0,0 +1,30 @@
|
|||||||
|
import api from 'flavours/glitch/util/api';
|
||||||
|
import { importFetchedAccount } from './importer';
|
||||||
|
|
||||||
|
export const SERVER_FETCH_REQUEST = 'Server_FETCH_REQUEST';
|
||||||
|
export const SERVER_FETCH_SUCCESS = 'Server_FETCH_SUCCESS';
|
||||||
|
export const SERVER_FETCH_FAIL = 'Server_FETCH_FAIL';
|
||||||
|
|
||||||
|
export const fetchServer = () => (dispatch, getState) => {
|
||||||
|
dispatch(fetchServerRequest());
|
||||||
|
|
||||||
|
api(getState)
|
||||||
|
.get('/api/v2/instance').then(({ data }) => {
|
||||||
|
if (data.contact.account) dispatch(importFetchedAccount(data.contact.account));
|
||||||
|
dispatch(fetchServerSuccess(data));
|
||||||
|
}).catch(err => dispatch(fetchServerFail(err)));
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchServerRequest = () => ({
|
||||||
|
type: SERVER_FETCH_REQUEST,
|
||||||
|
});
|
||||||
|
|
||||||
|
const fetchServerSuccess = server => ({
|
||||||
|
type: SERVER_FETCH_SUCCESS,
|
||||||
|
server,
|
||||||
|
});
|
||||||
|
|
||||||
|
const fetchServerFail = error => ({
|
||||||
|
type: SERVER_FETCH_FAIL,
|
||||||
|
error,
|
||||||
|
});
|
@ -0,0 +1,12 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
|
const NotSignedInIndicator = () => (
|
||||||
|
<div className='scrollable scrollable--flex'>
|
||||||
|
<div className='empty-column-indicator'>
|
||||||
|
<FormattedMessage id='not_signed_in_indicator.not_signed_in' defaultMessage='You need to sign in to access this resource.' />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default NotSignedInIndicator;
|
@ -0,0 +1,91 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { domain } from 'flavours/glitch/util/initial_state';
|
||||||
|
import { fetchServer } from 'flavours/glitch/actions/server';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import Account from 'flavours/glitch/containers/account_container';
|
||||||
|
import ShortNumber from 'flavours/glitch/components/short_number';
|
||||||
|
import Skeleton from 'flavours/glitch/components/skeleton';
|
||||||
|
import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
aboutActiveUsers: { id: 'server_banner.about_active_users', defaultMessage: 'People using this server during the last 30 days (Monthly Active Users)' },
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapStateToProps = state => ({
|
||||||
|
server: state.get('server'),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default @connect(mapStateToProps)
|
||||||
|
@injectIntl
|
||||||
|
class ServerBanner extends React.PureComponent {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
server: PropTypes.object,
|
||||||
|
dispatch: PropTypes.func,
|
||||||
|
intl: PropTypes.object,
|
||||||
|
};
|
||||||
|
|
||||||
|
componentDidMount () {
|
||||||
|
const { dispatch } = this.props;
|
||||||
|
dispatch(fetchServer());
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { server, intl } = this.props;
|
||||||
|
const isLoading = server.get('isLoading');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='server-banner'>
|
||||||
|
<div className='server-banner__introduction'>
|
||||||
|
<FormattedMessage id='server_banner.introduction' defaultMessage='{domain} is part of the decentralized social network powered by {mastodon}.' values={{ domain: <strong>{domain}</strong>, mastodon: <a href='https://joinmastodon.org' target='_blank'>Mastodon</a> }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<img src={server.get('thumbnail')} alt={server.get('title')} className='server-banner__hero' />
|
||||||
|
|
||||||
|
<div className='server-banner__description'>
|
||||||
|
{isLoading ? (
|
||||||
|
<>
|
||||||
|
<Skeleton width='100%' />
|
||||||
|
<br />
|
||||||
|
<Skeleton width='100%' />
|
||||||
|
<br />
|
||||||
|
<Skeleton width='70%' />
|
||||||
|
</>
|
||||||
|
) : server.get('description')}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='server-banner__meta'>
|
||||||
|
<div className='server-banner__meta__column'>
|
||||||
|
<h4><FormattedMessage id='server_banner.administered_by' defaultMessage='Administered by:' /></h4>
|
||||||
|
|
||||||
|
<Account id={server.getIn(['contact', 'account', 'id'])} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='server-banner__meta__column'>
|
||||||
|
<h4><FormattedMessage id='server_banner.server_stats' defaultMessage='Server stats:' /></h4>
|
||||||
|
|
||||||
|
{isLoading ? (
|
||||||
|
<>
|
||||||
|
<strong className='server-banner__number'><Skeleton width='10ch' /></strong>
|
||||||
|
<br />
|
||||||
|
<span className='server-banner__number-label'><Skeleton width='5ch' /></span>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<strong className='server-banner__number'><ShortNumber value={server.getIn(['usage', 'users', 'active_month'])} /></strong>
|
||||||
|
<br />
|
||||||
|
<span className='server-banner__number-label' title={intl.formatMessage(messages.aboutActiveUsers)}><FormattedMessage id='server_banner.active_users' defaultMessage='active users' /></span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr className='spacer' />
|
||||||
|
|
||||||
|
<a className='button button--block button-secondary' href='/about/more' target='_blank'><FormattedMessage id='server_banner.learn_more' defaultMessage='Learn more' /></a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,132 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
import { registrationsOpen } from 'flavours/glitch/util/initial_state';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import Icon from 'flavours/glitch/components/icon';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
const mapStateToProps = (state, { accountId }) => ({
|
||||||
|
displayNameHtml: state.getIn(['accounts', accountId, 'display_name_html']),
|
||||||
|
});
|
||||||
|
|
||||||
|
class Copypaste extends React.PureComponent {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
value: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
state = {
|
||||||
|
copied: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
setRef = c => {
|
||||||
|
this.input = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleInputClick = () => {
|
||||||
|
this.setState({ copied: false });
|
||||||
|
this.input.focus();
|
||||||
|
this.input.select();
|
||||||
|
this.input.setSelectionRange(0, this.input.value.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleButtonClick = () => {
|
||||||
|
const { value } = this.props;
|
||||||
|
navigator.clipboard.writeText(value);
|
||||||
|
this.input.blur();
|
||||||
|
this.setState({ copied: true });
|
||||||
|
this.timeout = setTimeout(() => this.setState({ copied: false }), 700);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount () {
|
||||||
|
if (this.timeout) clearTimeout(this.timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { value } = this.props;
|
||||||
|
const { copied } = this.state;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classNames('copypaste', { copied })}>
|
||||||
|
<input
|
||||||
|
type='text'
|
||||||
|
ref={this.setRef}
|
||||||
|
value={value}
|
||||||
|
readOnly
|
||||||
|
onClick={this.handleInputClick}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<button className='button' onClick={this.handleButtonClick}>
|
||||||
|
{copied ? <FormattedMessage id='copypaste.copied' defaultMessage='Copied' /> : <FormattedMessage id='copypaste.copy' defaultMessage='Copy' />}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default @connect(mapStateToProps)
|
||||||
|
class InteractionModal extends React.PureComponent {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
displayNameHtml: PropTypes.string,
|
||||||
|
url: PropTypes.string,
|
||||||
|
type: PropTypes.oneOf(['reply', 'reblog', 'favourite', 'follow']),
|
||||||
|
};
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { url, type, displayNameHtml } = this.props;
|
||||||
|
|
||||||
|
const name = <bdi dangerouslySetInnerHTML={{ __html: displayNameHtml }} />;
|
||||||
|
|
||||||
|
let title, actionDescription, icon;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case 'reply':
|
||||||
|
icon = <Icon id='reply' />;
|
||||||
|
title = <FormattedMessage id='interaction_modal.title.reply' defaultMessage="Reply to {name}'s post" values={{ name }} />;
|
||||||
|
actionDescription = <FormattedMessage id='interaction_modal.description.reply' defaultMessage='With an account on Mastodon, you can respond to this post.' />;
|
||||||
|
break;
|
||||||
|
case 'reblog':
|
||||||
|
icon = <Icon id='retweet' />;
|
||||||
|
title = <FormattedMessage id='interaction_modal.title.reblog' defaultMessage="Boost {name}'s post" values={{ name }} />;
|
||||||
|
actionDescription = <FormattedMessage id='interaction_modal.description.reblog' defaultMessage='With an account on Mastodon, you can boost this post to share it with your own followers.' />;
|
||||||
|
break;
|
||||||
|
case 'favourite':
|
||||||
|
icon = <Icon id='star' />;
|
||||||
|
title = <FormattedMessage id='interaction_modal.title.favourite' defaultMessage="Favourite {name}'s post" values={{ name }} />;
|
||||||
|
actionDescription = <FormattedMessage id='interaction_modal.description.favourite' defaultMessage='With an account on Mastodon, you can favourite this post to let the author know you appreciate it and save it for later.' />;
|
||||||
|
break;
|
||||||
|
case 'follow':
|
||||||
|
icon = <Icon id='user-plus' />;
|
||||||
|
title = <FormattedMessage id='interaction_modal.title.follow' defaultMessage='Follow {name}' values={{ name }} />;
|
||||||
|
actionDescription = <FormattedMessage id='interaction_modal.description.follow' defaultMessage='With an account on Mastodon, you can follow {name} to receive their posts in your home feed.' values={{ name }} />;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='modal-root__modal interaction-modal'>
|
||||||
|
<div className='interaction-modal__lead'>
|
||||||
|
<h3><span className='interaction-modal__icon'>{icon}</span> {title}</h3>
|
||||||
|
<p>{actionDescription} <FormattedMessage id='interaction_modal.preamble' defaultMessage="Since Mastodon is decentralized, you can use your existing account hosted by another Mastodon server or compatible platform if you don't have an account on this one." /></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='interaction-modal__choices'>
|
||||||
|
<div className='interaction-modal__choices__choice'>
|
||||||
|
<h3><FormattedMessage id='interaction_modal.on_this_server' defaultMessage='On this server' /></h3>
|
||||||
|
<a href='/auth/sign_in' className='button button--block'><FormattedMessage id='sign_in_banner.sign_in' defaultMessage='Sign in' /></a>
|
||||||
|
<a href={registrationsOpen ? '/auth/sign_up' : 'https://joinmastodon.org/servers'} className='button button--block button-tertiary'><FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' /></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='interaction-modal__choices__choice'>
|
||||||
|
<h3><FormattedMessage id='interaction_modal.on_another_server' defaultMessage='On a different server' /></h3>
|
||||||
|
<p><FormattedMessage id='interaction_modal.other_server_instructions' defaultMessage='Simply copy and paste this URL into the search bar of your favourite app or the web interface where you are signed in.' /></p>
|
||||||
|
<Copypaste value={url} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,16 +1,42 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import SearchContainer from 'flavours/glitch/features/compose/containers/search_container';
|
import SearchContainer from 'flavours/glitch/features/compose/containers/search_container';
|
||||||
import ComposeFormContainer from 'flavours/glitch/features/compose/containers/compose_form_container';
|
import ComposeFormContainer from 'flavours/glitch/features/compose/containers/compose_form_container';
|
||||||
import NavigationContainer from 'flavours/glitch/features/compose/containers/navigation_container';
|
import NavigationContainer from 'flavours/glitch/features/compose/containers/navigation_container';
|
||||||
import LinkFooter from './link_footer';
|
import LinkFooter from './link_footer';
|
||||||
|
import ServerBanner from 'flavours/glitch/components/server_banner';
|
||||||
|
|
||||||
const ComposePanel = () => (
|
export default
|
||||||
|
class ComposePanel extends React.PureComponent {
|
||||||
|
|
||||||
|
static contextTypes = {
|
||||||
|
identity: PropTypes.object.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { signedIn } = this.context.identity;
|
||||||
|
|
||||||
|
return (
|
||||||
<div className='compose-panel'>
|
<div className='compose-panel'>
|
||||||
<SearchContainer openInRoute />
|
<SearchContainer openInRoute />
|
||||||
|
|
||||||
|
{!signedIn && (
|
||||||
|
<React.Fragment>
|
||||||
|
<ServerBanner />
|
||||||
|
<div className='flex-spacer' />
|
||||||
|
</React.Fragment>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{signedIn && (
|
||||||
|
<React.Fragment>
|
||||||
<NavigationContainer />
|
<NavigationContainer />
|
||||||
<ComposeFormContainer singleColumn />
|
<ComposeFormContainer singleColumn />
|
||||||
|
</React.Fragment>
|
||||||
|
)}
|
||||||
|
|
||||||
<LinkFooter withHotkeys />
|
<LinkFooter withHotkeys />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default ComposePanel;
|
};
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
import { registrationsOpen } from 'flavours/glitch/util/initial_state';
|
||||||
|
|
||||||
|
const SignInBanner = () => (
|
||||||
|
<div className='sign-in-banner'>
|
||||||
|
<p><FormattedMessage id='sign_in_banner.text' defaultMessage='Sign in to follow profiles or hashtags, favourite, share and reply to posts, or interact from your account on a different server.' /></p>
|
||||||
|
<a href='/auth/sign_in' className='button button--block'><FormattedMessage id='sign_in_banner.sign_in' defaultMessage='Sign in' /></a>
|
||||||
|
<a href={registrationsOpen ? '/auth/sign_up' : 'https://joinmastodon.org/servers'} className='button button--block button-tertiary'><FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' /></a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default SignInBanner;
|
@ -1,8 +1,10 @@
|
|||||||
import 'packs/public-path';
|
import 'packs/public-path';
|
||||||
import loadPolyfills from 'flavours/glitch/util/load_polyfills';
|
import loadPolyfills from 'flavours/glitch/util/load_polyfills';
|
||||||
|
|
||||||
loadPolyfills().then(() => {
|
loadPolyfills().then(async () => {
|
||||||
require('flavours/glitch/util/main').default();
|
const { default: main } = await import('flavours/glitch/util/main');
|
||||||
|
|
||||||
|
return main();
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
import { RULES_FETCH_SUCCESS } from 'flavours/glitch/actions/rules';
|
|
||||||
import { List as ImmutableList, fromJS } from 'immutable';
|
|
||||||
|
|
||||||
const initialState = ImmutableList();
|
|
||||||
|
|
||||||
export default function rules(state = initialState, action) {
|
|
||||||
switch (action.type) {
|
|
||||||
case RULES_FETCH_SUCCESS:
|
|
||||||
return fromJS(action.rules);
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,19 @@
|
|||||||
|
import { SERVER_FETCH_REQUEST, SERVER_FETCH_SUCCESS, SERVER_FETCH_FAIL } from 'flavours/glitch/actions/server';
|
||||||
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
const initialState = ImmutableMap({
|
||||||
|
isLoading: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default function server(state = initialState, action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case SERVER_FETCH_REQUEST:
|
||||||
|
return state.set('isLoading', true);
|
||||||
|
case SERVER_FETCH_SUCCESS:
|
||||||
|
return fromJS(action.server).set('isLoading', false);
|
||||||
|
case SERVER_FETCH_FAIL:
|
||||||
|
return state.set('isLoading', false);
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
.sign-in-banner {
|
||||||
|
padding: 10px;
|
||||||
|
|
||||||
|
p {
|
||||||
|
color: $darker-text-color;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-banner {
|
||||||
|
padding: 20px 0;
|
||||||
|
|
||||||
|
&__introduction {
|
||||||
|
color: $darker-text-color;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
|
||||||
|
strong {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: underline;
|
||||||
|
|
||||||
|
&:hover,
|
||||||
|
&:active,
|
||||||
|
&:focus {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__hero {
|
||||||
|
display: block;
|
||||||
|
border-radius: 4px;
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
aspect-ratio: 1.9;
|
||||||
|
border: 0;
|
||||||
|
background: $ui-base-color;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__description {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__meta {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
max-width: 100%;
|
||||||
|
|
||||||
|
&__column {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: calc(50% - 5px);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__number {
|
||||||
|
font-weight: 600;
|
||||||
|
color: $primary-text-color;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__number-label {
|
||||||
|
color: $darker-text-color;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: $darker-text-color;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.account {
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.account__avatar-wrapper {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spacer {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,32 @@
|
|||||||
export default function ready(loaded) {
|
// @ts-check
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {(() => void) | (() => Promise<void>)} callback
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
export default function ready(callback) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
function loaded() {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = callback();
|
||||||
|
} catch (err) {
|
||||||
|
reject(err);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof result?.then === 'function') {
|
||||||
|
result.then(resolve).catch(reject);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (['interactive', 'complete'].includes(document.readyState)) {
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
||||||
loaded();
|
loaded();
|
||||||
} else {
|
} else {
|
||||||
document.addEventListener('DOMContentLoaded', loaded);
|
document.addEventListener('DOMContentLoaded', loaded);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
import api from '../api';
|
|
||||||
|
|
||||||
export const RULES_FETCH_REQUEST = 'RULES_FETCH_REQUEST';
|
|
||||||
export const RULES_FETCH_SUCCESS = 'RULES_FETCH_SUCCESS';
|
|
||||||
export const RULES_FETCH_FAIL = 'RULES_FETCH_FAIL';
|
|
||||||
|
|
||||||
export const fetchRules = () => (dispatch, getState) => {
|
|
||||||
dispatch(fetchRulesRequest());
|
|
||||||
|
|
||||||
api(getState)
|
|
||||||
.get('/api/v1/instance').then(({ data }) => dispatch(fetchRulesSuccess(data.rules)))
|
|
||||||
.catch(err => dispatch(fetchRulesFail(err)));
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchRulesRequest = () => ({
|
|
||||||
type: RULES_FETCH_REQUEST,
|
|
||||||
});
|
|
||||||
|
|
||||||
const fetchRulesSuccess = rules => ({
|
|
||||||
type: RULES_FETCH_SUCCESS,
|
|
||||||
rules,
|
|
||||||
});
|
|
||||||
|
|
||||||
const fetchRulesFail = error => ({
|
|
||||||
type: RULES_FETCH_FAIL,
|
|
||||||
error,
|
|
||||||
});
|
|
@ -0,0 +1,30 @@
|
|||||||
|
import api from '../api';
|
||||||
|
import { importFetchedAccount } from './importer';
|
||||||
|
|
||||||
|
export const SERVER_FETCH_REQUEST = 'Server_FETCH_REQUEST';
|
||||||
|
export const SERVER_FETCH_SUCCESS = 'Server_FETCH_SUCCESS';
|
||||||
|
export const SERVER_FETCH_FAIL = 'Server_FETCH_FAIL';
|
||||||
|
|
||||||
|
export const fetchServer = () => (dispatch, getState) => {
|
||||||
|
dispatch(fetchServerRequest());
|
||||||
|
|
||||||
|
api(getState)
|
||||||
|
.get('/api/v2/instance').then(({ data }) => {
|
||||||
|
if (data.contact.account) dispatch(importFetchedAccount(data.contact.account));
|
||||||
|
dispatch(fetchServerSuccess(data));
|
||||||
|
}).catch(err => dispatch(fetchServerFail(err)));
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchServerRequest = () => ({
|
||||||
|
type: SERVER_FETCH_REQUEST,
|
||||||
|
});
|
||||||
|
|
||||||
|
const fetchServerSuccess = server => ({
|
||||||
|
type: SERVER_FETCH_SUCCESS,
|
||||||
|
server,
|
||||||
|
});
|
||||||
|
|
||||||
|
const fetchServerFail = error => ({
|
||||||
|
type: SERVER_FETCH_FAIL,
|
||||||
|
error,
|
||||||
|
});
|
@ -0,0 +1,91 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { domain } from 'mastodon/initial_state';
|
||||||
|
import { fetchServer } from 'mastodon/actions/server';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import Account from 'mastodon/containers/account_container';
|
||||||
|
import ShortNumber from 'mastodon/components/short_number';
|
||||||
|
import Skeleton from 'mastodon/components/skeleton';
|
||||||
|
import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
aboutActiveUsers: { id: 'server_banner.about_active_users', defaultMessage: 'People using this server during the last 30 days (Monthly Active Users)' },
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapStateToProps = state => ({
|
||||||
|
server: state.get('server'),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default @connect(mapStateToProps)
|
||||||
|
@injectIntl
|
||||||
|
class ServerBanner extends React.PureComponent {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
server: PropTypes.object,
|
||||||
|
dispatch: PropTypes.func,
|
||||||
|
intl: PropTypes.object,
|
||||||
|
};
|
||||||
|
|
||||||
|
componentDidMount () {
|
||||||
|
const { dispatch } = this.props;
|
||||||
|
dispatch(fetchServer());
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { server, intl } = this.props;
|
||||||
|
const isLoading = server.get('isLoading');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='server-banner'>
|
||||||
|
<div className='server-banner__introduction'>
|
||||||
|
<FormattedMessage id='server_banner.introduction' defaultMessage='{domain} is part of the decentralized social network powered by {mastodon}.' values={{ domain: <strong>{domain}</strong>, mastodon: <a href='https://joinmastodon.org' target='_blank'>Mastodon</a> }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<img src={server.get('thumbnail')} alt={server.get('title')} className='server-banner__hero' />
|
||||||
|
|
||||||
|
<div className='server-banner__description'>
|
||||||
|
{isLoading ? (
|
||||||
|
<>
|
||||||
|
<Skeleton width='100%' />
|
||||||
|
<br />
|
||||||
|
<Skeleton width='100%' />
|
||||||
|
<br />
|
||||||
|
<Skeleton width='70%' />
|
||||||
|
</>
|
||||||
|
) : server.get('description')}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='server-banner__meta'>
|
||||||
|
<div className='server-banner__meta__column'>
|
||||||
|
<h4><FormattedMessage id='server_banner.administered_by' defaultMessage='Administered by:' /></h4>
|
||||||
|
|
||||||
|
<Account id={server.getIn(['contact', 'account', 'id'])} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='server-banner__meta__column'>
|
||||||
|
<h4><FormattedMessage id='server_banner.server_stats' defaultMessage='Server stats:' /></h4>
|
||||||
|
|
||||||
|
{isLoading ? (
|
||||||
|
<>
|
||||||
|
<strong className='server-banner__number'><Skeleton width='10ch' /></strong>
|
||||||
|
<br />
|
||||||
|
<span className='server-banner__number-label'><Skeleton width='5ch' /></span>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<strong className='server-banner__number'><ShortNumber value={server.getIn(['usage', 'users', 'active_month'])} /></strong>
|
||||||
|
<br />
|
||||||
|
<span className='server-banner__number-label' title={intl.formatMessage(messages.aboutActiveUsers)}><FormattedMessage id='server_banner.active_users' defaultMessage='active users' /></span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr className='spacer' />
|
||||||
|
|
||||||
|
<a className='button button--block button-secondary' href='/about/more' target='_blank'><FormattedMessage id='server_banner.learn_more' defaultMessage='Learn more' /></a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,13 +0,0 @@
|
|||||||
import { RULES_FETCH_SUCCESS } from 'mastodon/actions/rules';
|
|
||||||
import { List as ImmutableList, fromJS } from 'immutable';
|
|
||||||
|
|
||||||
const initialState = ImmutableList();
|
|
||||||
|
|
||||||
export default function rules(state = initialState, action) {
|
|
||||||
switch (action.type) {
|
|
||||||
case RULES_FETCH_SUCCESS:
|
|
||||||
return fromJS(action.rules);
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,19 @@
|
|||||||
|
import { SERVER_FETCH_REQUEST, SERVER_FETCH_SUCCESS, SERVER_FETCH_FAIL } from 'mastodon/actions/server';
|
||||||
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
const initialState = ImmutableMap({
|
||||||
|
isLoading: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default function server(state = initialState, action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case SERVER_FETCH_REQUEST:
|
||||||
|
return state.set('isLoading', true);
|
||||||
|
case SERVER_FETCH_SUCCESS:
|
||||||
|
return fromJS(action.server).set('isLoading', false);
|
||||||
|
case SERVER_FETCH_FAIL:
|
||||||
|
return state.set('isLoading', false);
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,115 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class REST::V1::InstanceSerializer < ActiveModel::Serializer
|
||||||
|
include RoutingHelper
|
||||||
|
|
||||||
|
attributes :uri, :title, :short_description, :description, :email,
|
||||||
|
:version, :urls, :stats, :thumbnail, :max_toot_chars, :poll_limits,
|
||||||
|
:languages, :registrations, :approval_required, :invites_enabled,
|
||||||
|
:configuration
|
||||||
|
|
||||||
|
has_one :contact_account, serializer: REST::AccountSerializer
|
||||||
|
|
||||||
|
has_many :rules, serializer: REST::RuleSerializer
|
||||||
|
|
||||||
|
def uri
|
||||||
|
object.domain
|
||||||
|
end
|
||||||
|
|
||||||
|
def short_description
|
||||||
|
object.description
|
||||||
|
end
|
||||||
|
|
||||||
|
def description
|
||||||
|
Setting.site_description # Legacy
|
||||||
|
end
|
||||||
|
|
||||||
|
def email
|
||||||
|
object.contact.email
|
||||||
|
end
|
||||||
|
|
||||||
|
def contact_account
|
||||||
|
object.contact.account
|
||||||
|
end
|
||||||
|
|
||||||
|
def thumbnail
|
||||||
|
instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('media/images/preview.png')
|
||||||
|
end
|
||||||
|
|
||||||
|
def max_toot_chars
|
||||||
|
StatusLengthValidator::MAX_CHARS
|
||||||
|
end
|
||||||
|
|
||||||
|
def poll_limits
|
||||||
|
{
|
||||||
|
max_options: PollValidator::MAX_OPTIONS,
|
||||||
|
max_option_chars: PollValidator::MAX_OPTION_CHARS,
|
||||||
|
min_expiration: PollValidator::MIN_EXPIRATION,
|
||||||
|
max_expiration: PollValidator::MAX_EXPIRATION,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def stats
|
||||||
|
{
|
||||||
|
user_count: instance_presenter.user_count,
|
||||||
|
status_count: instance_presenter.status_count,
|
||||||
|
domain_count: instance_presenter.domain_count,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def urls
|
||||||
|
{ streaming_api: Rails.configuration.x.streaming_api_base_url }
|
||||||
|
end
|
||||||
|
|
||||||
|
def usage
|
||||||
|
{
|
||||||
|
users: {
|
||||||
|
active_month: instance_presenter.active_user_count(4),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def configuration
|
||||||
|
{
|
||||||
|
statuses: {
|
||||||
|
max_characters: StatusLengthValidator::MAX_CHARS,
|
||||||
|
max_media_attachments: 4,
|
||||||
|
characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS,
|
||||||
|
},
|
||||||
|
|
||||||
|
media_attachments: {
|
||||||
|
supported_mime_types: MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES + MediaAttachment::AUDIO_MIME_TYPES,
|
||||||
|
image_size_limit: MediaAttachment::IMAGE_LIMIT,
|
||||||
|
image_matrix_limit: Attachmentable::MAX_MATRIX_LIMIT,
|
||||||
|
video_size_limit: MediaAttachment::VIDEO_LIMIT,
|
||||||
|
video_frame_rate_limit: MediaAttachment::MAX_VIDEO_FRAME_RATE,
|
||||||
|
video_matrix_limit: MediaAttachment::MAX_VIDEO_MATRIX_LIMIT,
|
||||||
|
},
|
||||||
|
|
||||||
|
polls: {
|
||||||
|
max_options: PollValidator::MAX_OPTIONS,
|
||||||
|
max_characters_per_option: PollValidator::MAX_OPTION_CHARS,
|
||||||
|
min_expiration: PollValidator::MIN_EXPIRATION,
|
||||||
|
max_expiration: PollValidator::MAX_EXPIRATION,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def registrations
|
||||||
|
Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
|
||||||
|
end
|
||||||
|
|
||||||
|
def approval_required
|
||||||
|
Setting.registrations_mode == 'approved'
|
||||||
|
end
|
||||||
|
|
||||||
|
def invites_enabled
|
||||||
|
UserRole.everyone.can?(:invite_users)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def instance_presenter
|
||||||
|
@instance_presenter ||= InstancePresenter.new
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue