Skip to content

Commit

Permalink
Merge pull request #314 from chriswmartin/merge-vanilla-updates-2
Browse files Browse the repository at this point in the history
Merge vanilla updates into glitch - round 2
  • Loading branch information
hannahwhy committed Jan 9, 2018
2 parents 991371a + aef4b1a commit 622c8fd
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 49 deletions.
6 changes: 5 additions & 1 deletion app/javascript/flavours/glitch/actions/favourites.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export const FAVOURITED_STATUSES_EXPAND_FAIL = 'FAVOURITED_STATUSES_EXPAND_FA

export function fetchFavouritedStatuses() {
return (dispatch, getState) => {
if (getState().getIn(['status_lists', 'favourites', 'isLoading'])) {
return;
}

dispatch(fetchFavouritedStatusesRequest());

api(getState).get('/api/v1/favourites').then(response => {
Expand Down Expand Up @@ -46,7 +50,7 @@ export function expandFavouritedStatuses() {
return (dispatch, getState) => {
const url = getState().getIn(['status_lists', 'favourites', 'next'], null);

if (url === null) {
if (url === null || getState().getIn(['status_lists', 'favourites', 'isLoading'])) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion app/javascript/flavours/glitch/actions/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const fetchRelatedRelationships = (dispatch, notifications) => {

const unescapeHTML = (html) => {
const wrapper = document.createElement('div');
html = html.replace(/<br \/>|<br>|\n/, ' ');
html = html.replace(/<br \/>|<br>|\n/g, ' ');
wrapper.innerHTML = html;
return wrapper.textContent;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export {
register,
};

export function changeAlerts(key, value) {
export function changeAlerts(path, value) {
return dispatch => {
dispatch(setAlerts(key, value));
dispatch(setAlerts(path, value));
dispatch(saveSettings());
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from 'axios';
import api from 'flavours/glitch/util/api';
import { pushNotificationsSetting } from 'flavours/glitch/util/settings';
import { setBrowserSupport, setSubscription, clearSubscription } from './setter';

Expand Down Expand Up @@ -35,7 +35,7 @@ const subscribe = (registration) =>
const unsubscribe = ({ registration, subscription }) =>
subscription ? subscription.unsubscribe().then(() => registration) : registration;

const sendSubscriptionToBackend = (subscription, me) => {
const sendSubscriptionToBackend = (getState, subscription, me) => {
const params = { subscription };

if (me) {
Expand All @@ -45,7 +45,7 @@ const sendSubscriptionToBackend = (subscription, me) => {
}
}

return axios.post('/api/web/push_subscriptions', params).then(response => response.data);
return api(getState).post('/api/web/push_subscriptions', params).then(response => response.data);
};

// Last one checks for payload support: https://web-push-book.gauntface.com/chapter-06/01-non-standards-browsers/#no-payload
Expand Down Expand Up @@ -85,13 +85,13 @@ export function register () {
} else {
// Something went wrong, try to subscribe again
return unsubscribe({ registration, subscription }).then(subscribe).then(
subscription => sendSubscriptionToBackend(subscription, me));
subscription => sendSubscriptionToBackend(getState, subscription, me));
}
}

// No subscription, try to subscribe
return subscribe(registration).then(
subscription => sendSubscriptionToBackend(subscription, me));
subscription => sendSubscriptionToBackend(getState, subscription, me));
})
.then(subscription => {
// If we got a PushSubscription (and not a subscription object from the backend)
Expand Down Expand Up @@ -137,7 +137,7 @@ export function saveSettings() {
const alerts = state.get('alerts');
const data = { alerts };

axios.put(`/api/web/push_subscriptions/${subscription.get('id')}`, {
api(getState).put(`/api/web/push_subscriptions/${subscription.get('id')}`, {
data,
}).then(() => {
const me = getState().getIn(['meta', 'me']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export function clearSubscription () {
};
}

export function setAlerts (key, value) {
export function setAlerts (path, value) {
return dispatch => {
dispatch({
type: SET_ALERTS,
key,
path,
value,
});
};
Expand Down
10 changes: 5 additions & 5 deletions app/javascript/flavours/glitch/actions/settings.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import axios from 'axios';
import api from 'flavours/glitch/util/api';
import { debounce } from 'lodash';

export const SETTING_CHANGE = 'SETTING_CHANGE';
export const SETTING_SAVE = 'SETTING_SAVE';

export function changeSetting(key, value) {
export function changeSetting(path, value) {
return dispatch => {
dispatch({
type: SETTING_CHANGE,
key,
path,
value,
});

Expand All @@ -21,9 +21,9 @@ const debouncedSave = debounce((dispatch, getState) => {
return;
}

const data = getState().get('settings').filter((_, key) => key !== 'saved').toJS();
const data = getState().get('settings').filter((_, path) => path !== 'saved').toJS();

axios.put('/api/web/settings', { data }).then(() => dispatch({ type: SETTING_SAVE }));
api(getState).put('/api/web/settings', { data }).then(() => dispatch({ type: SETTING_SAVE }));
}, 5000, { trailing: true });

export function saveSettings() {
Expand Down
8 changes: 4 additions & 4 deletions app/javascript/flavours/glitch/components/account.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { Fragment } from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import Avatar from './avatar';
Expand Down Expand Up @@ -94,12 +94,12 @@ export default class Account extends ImmutablePureComponent {
hidingNotificationsButton = <IconButton active icon='bell-slash' title={intl.formatMessage(messages.mute_notifications, { name: account.get('username') })} onClick={this.handleMuteNotifications} />;
}
buttons = (
<div>
<Fragment>
<IconButton active icon='volume-up' title={intl.formatMessage(messages.unmute, { name: account.get('username') })} onClick={this.handleMute} />
{hidingNotificationsButton}
</div>
</Fragment>
);
} else {
} else if (!account.get('moved')) {
buttons = <IconButton icon={following ? 'user-times' : 'user-plus'} title={intl.formatMessage(following ? messages.unfollow : messages.follow)} onClick={this.handleFollow} active={following} />;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const mapStateToProps = state => ({

const mapDispatchToProps = dispatch => ({

onChange (key, checked) {
dispatch(changeSetting(['community', ...key], checked));
onChange (path, checked) {
dispatch(changeSetting(['community', ...path], checked));
},

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const mapStateToProps = state => ({

const mapDispatchToProps = dispatch => ({

onChange (key, checked) {
dispatch(changeSetting(['direct', ...key], checked));
onChange (path, checked) {
dispatch(changeSetting(['direct', ...path], checked));
},

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { addColumn, removeColumn, moveColumn } from 'flavours/glitch/actions/col
import StatusList from 'flavours/glitch/components/status_list';
import { defineMessages, injectIntl } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { debounce } from 'lodash';

const messages = defineMessages({
heading: { id: 'column.favourites', defaultMessage: 'Favourites' },
});

const mapStateToProps = state => ({
statusIds: state.getIn(['status_lists', 'favourites', 'items']),
isLoading: state.getIn(['status_lists', 'favourites', 'isLoading'], true),
hasMore: !!state.getIn(['status_lists', 'favourites', 'next']),
});

Expand All @@ -30,6 +32,7 @@ export default class Favourites extends ImmutablePureComponent {
columnId: PropTypes.string,
multiColumn: PropTypes.bool,
hasMore: PropTypes.bool,
isLoading: PropTypes.bool,
};

componentWillMount () {
Expand Down Expand Up @@ -59,12 +62,12 @@ export default class Favourites extends ImmutablePureComponent {
this.column = c;
}

handleScrollToBottom = () => {
handleScrollToBottom = debounce(() => {
this.props.dispatch(expandFavouritedStatuses());
}
}, 300, { leading: true })

render () {
const { intl, statusIds, columnId, multiColumn, hasMore } = this.props;
const { intl, statusIds, columnId, multiColumn, hasMore, isLoading } = this.props;
const pinned = !!columnId;

return (
Expand All @@ -85,6 +88,7 @@ export default class Favourites extends ImmutablePureComponent {
statusIds={statusIds}
scrollKey={`favourited_statuses-${columnId}`}
hasMore={hasMore}
isLoading={isLoading}
onScrollToBottom={this.handleScrollToBottom}
/>
</Column>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class GettingStarted extends ImmutablePureComponent {
render () {
const { intl, myAccount, columns, multiColumn, lists } = this.props;

let navItems = [];
const navItems = [];
let listItems = [];

if (multiColumn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const mapStateToProps = state => ({

const mapDispatchToProps = dispatch => ({

onChange (key, checked) {
dispatch(changeSetting(['home', ...key], checked));
onChange (path, checked) {
dispatch(changeSetting(['home', ...path], checked));
},

onSave () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default class ColumnSettings extends React.PureComponent {
onClear: PropTypes.func.isRequired,
};

onPushChange = (key, checked) => {
this.props.onChange(['push', ...key], checked);
onPushChange = (path, checked) => {
this.props.onChange(['push', ...path], checked);
}

render () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const mapStateToProps = state => ({

const mapDispatchToProps = (dispatch, { intl }) => ({

onChange (key, checked) {
if (key[0] === 'push') {
dispatch(changePushNotifications(key.slice(1), checked));
onChange (path, checked) {
if (path[0] === 'push') {
dispatch(changePushNotifications(path.slice(1), checked));
} else {
dispatch(changeSetting(['notifications', ...key], checked));
dispatch(changeSetting(['notifications', ...path], checked));
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const mapStateToProps = state => ({

const mapDispatchToProps = dispatch => ({

onChange (key, checked) {
dispatch(changeSetting(['public', ...key], checked));
onChange (path, checked) {
dispatch(changeSetting(['public', ...path], checked));
},

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { FormattedMessage, injectIntl } from 'react-intl';
import axios from 'axios';
import api from 'flavours/glitch/util/api';

@injectIntl
export default class EmbedModal extends ImmutablePureComponent {
Expand All @@ -23,7 +23,7 @@ export default class EmbedModal extends ImmutablePureComponent {

this.setState({ loading: true });

axios.post('/api/web/embed', { url }).then(res => {
api().post('/api/web/embed', { url }).then(res => {
this.setState({ loading: false, oembed: res.data });

const iframeDocument = this.iframe.contentWindow.document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function push_subscriptions(state = initialState, action) {
case CLEAR_SUBSCRIPTION:
return initialState;
case SET_ALERTS:
return state.setIn(action.key, action.value);
return state.setIn(action.path, action.value);
default:
return state;
}
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/flavours/glitch/reducers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default function settings(state = initialState, action) {
return hydrate(state, action.state.get('settings'));
case SETTING_CHANGE:
return state
.setIn(action.key, action.value)
.setIn(action.path, action.value)
.set('saved', false);
case COLUMN_ADD:
return state
Expand Down
12 changes: 12 additions & 0 deletions app/javascript/flavours/glitch/reducers/status_lists.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {
FAVOURITED_STATUSES_FETCH_REQUEST,
FAVOURITED_STATUSES_FETCH_SUCCESS,
FAVOURITED_STATUSES_FETCH_FAIL,
FAVOURITED_STATUSES_EXPAND_REQUEST,
FAVOURITED_STATUSES_EXPAND_SUCCESS,
FAVOURITED_STATUSES_EXPAND_FAIL,
} from 'flavours/glitch/actions/favourites';
import {
PINNED_STATUSES_FETCH_SUCCESS,
Expand Down Expand Up @@ -30,13 +34,15 @@ const normalizeList = (state, listType, statuses, next) => {
return state.update(listType, listMap => listMap.withMutations(map => {
map.set('next', next);
map.set('loaded', true);
map.set('isLoading', false);
map.set('items', ImmutableList(statuses.map(item => item.id)));
}));
};

const appendToList = (state, listType, statuses, next) => {
return state.update(listType, listMap => listMap.withMutations(map => {
map.set('next', next);
map.set('isLoading', false);
map.set('items', map.get('items').concat(statuses.map(item => item.id)));
}));
};
Expand All @@ -55,6 +61,12 @@ const removeOneFromList = (state, listType, status) => {

export default function statusLists(state = initialState, action) {
switch(action.type) {
case FAVOURITED_STATUSES_FETCH_REQUEST:
case FAVOURITED_STATUSES_EXPAND_REQUEST:
return state.setIn(['favourites', 'isLoading'], true);
case FAVOURITED_STATUSES_FETCH_FAIL:
case FAVOURITED_STATUSES_EXPAND_FAIL:
return state.setIn(['favourites', 'isLoading'], false);
case FAVOURITED_STATUSES_FETCH_SUCCESS:
return normalizeList(state, 'favourites', action.statuses, action.next);
case FAVOURITED_STATUSES_EXPAND_SUCCESS:
Expand Down
10 changes: 6 additions & 4 deletions app/javascript/flavours/glitch/styles/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,12 @@
}
}

&__content {
max-width: calc(100% - 90px);
}

&__title {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
word-wrap: break-word;
}

&__timestamp {
Expand All @@ -413,7 +415,7 @@
color: $ui-primary-color;
font-family: 'mastodon-font-monospace', monospace;
font-size: 12px;
white-space: nowrap;
word-wrap: break-word;
min-height: 20px;
}

Expand Down
5 changes: 5 additions & 0 deletions app/javascript/flavours/glitch/styles/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,11 @@
cursor: default;
}

.getting-started__wrapper,
.getting_started {
background: $ui-base-color;
}

.getting-started__wrapper {
position: relative;
overflow-y: auto;
Expand Down
Loading

0 comments on commit 622c8fd

Please sign in to comment.