2017-05-02 17:04:16 -07:00
|
|
|
import React from 'react';
|
2016-09-19 14:25:59 -07:00
|
|
|
import NotificationsContainer from './containers/notifications_container';
|
2017-04-21 11:05:35 -07:00
|
|
|
import PropTypes from 'prop-types';
|
2016-11-21 01:03:55 -08:00
|
|
|
import LoadingBarContainer from './containers/loading_bar_container';
|
|
|
|
import ModalContainer from './containers/modal_container';
|
2017-01-19 01:54:18 -08:00
|
|
|
import { connect } from 'react-redux';
|
2017-08-29 05:16:21 -07:00
|
|
|
import { Redirect, withRouter } from 'react-router-dom';
|
2017-12-03 23:26:40 -08:00
|
|
|
import { isMobile } from 'flavours/glitch/util/is_mobile';
|
2017-05-06 02:05:32 -07:00
|
|
|
import { debounce } from 'lodash';
|
2017-12-03 23:26:40 -08:00
|
|
|
import { uploadCompose, resetCompose } from 'flavours/glitch/actions/compose';
|
2018-05-27 10:10:37 -07:00
|
|
|
import { expandHomeTimeline } from 'flavours/glitch/actions/timelines';
|
2018-09-06 08:47:33 -07:00
|
|
|
import { expandNotifications, notificationsSetVisibility } from 'flavours/glitch/actions/notifications';
|
2018-07-08 11:04:53 -07:00
|
|
|
import { fetchFilters } from 'flavours/glitch/actions/filters';
|
2017-12-03 23:26:40 -08:00
|
|
|
import { clearHeight } from 'flavours/glitch/actions/height_cache';
|
|
|
|
import { WrappedSwitch, WrappedRoute } from 'flavours/glitch/util/react_router_helpers';
|
2017-03-23 19:50:30 -07:00
|
|
|
import UploadArea from './components/upload_area';
|
2017-06-03 16:39:38 -07:00
|
|
|
import ColumnsAreaContainer from './containers/columns_area_container';
|
2017-09-09 08:18:21 -07:00
|
|
|
import classNames from 'classnames';
|
2018-09-06 07:09:57 -07:00
|
|
|
import Favico from 'favico.js';
|
2017-07-07 15:06:02 -07:00
|
|
|
import {
|
2019-04-19 11:14:32 -07:00
|
|
|
Compose,
|
2017-07-07 15:06:02 -07:00
|
|
|
Status,
|
|
|
|
GettingStarted,
|
2017-12-20 07:50:29 -08:00
|
|
|
KeyboardShortcuts,
|
2017-07-07 15:06:02 -07:00
|
|
|
PublicTimeline,
|
|
|
|
CommunityTimeline,
|
|
|
|
AccountTimeline,
|
|
|
|
AccountGallery,
|
|
|
|
HomeTimeline,
|
|
|
|
Followers,
|
|
|
|
Following,
|
|
|
|
Reblogs,
|
|
|
|
Favourites,
|
2017-10-15 21:02:39 -07:00
|
|
|
DirectTimeline,
|
2017-07-07 15:06:02 -07:00
|
|
|
HashtagTimeline,
|
2017-07-08 08:22:24 -07:00
|
|
|
Notifications,
|
2017-07-07 15:06:02 -07:00
|
|
|
FollowRequests,
|
|
|
|
GenericNotFound,
|
|
|
|
FavouritedStatuses,
|
2018-04-11 10:42:25 -07:00
|
|
|
BookmarkedStatuses,
|
2017-12-08 17:40:49 -08:00
|
|
|
ListTimeline,
|
2017-07-07 15:06:02 -07:00
|
|
|
Blocks,
|
2018-03-04 12:46:27 -08:00
|
|
|
DomainBlocks,
|
2017-07-07 15:06:02 -07:00
|
|
|
Mutes,
|
2017-09-07 00:58:11 -07:00
|
|
|
PinnedStatuses,
|
2017-12-08 18:13:08 -08:00
|
|
|
Lists,
|
2019-05-25 12:27:00 -07:00
|
|
|
Search,
|
2017-12-11 22:01:17 -08:00
|
|
|
GettingStartedMisc,
|
2017-12-03 23:26:40 -08:00
|
|
|
} from 'flavours/glitch/util/async-components';
|
2017-10-05 16:07:59 -07:00
|
|
|
import { HotKeys } from 'react-hotkeys';
|
2019-06-12 08:18:45 -07:00
|
|
|
import { me } from 'flavours/glitch/util/initial_state';
|
2017-11-09 05:34:41 -08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-07-07 15:06:02 -07:00
|
|
|
|
|
|
|
// Dummy import, to make sure that <Status /> ends up in the application bundle.
|
|
|
|
// Without this it ends up in ~8 very commonly used bundles.
|
2017-07-12 02:03:17 -07:00
|
|
|
import '../../../glitch/components/status';
|
2017-06-20 11:40:03 -07:00
|
|
|
|
2017-11-09 05:34:41 -08:00
|
|
|
const messages = defineMessages({
|
|
|
|
beforeUnload: { id: 'ui.beforeunload', defaultMessage: 'Your draft will be lost if you leave Mastodon.' },
|
|
|
|
});
|
|
|
|
|
2017-07-06 13:39:56 -07:00
|
|
|
const mapStateToProps = state => ({
|
2018-09-22 14:08:03 -07:00
|
|
|
hasComposingText: state.getIn(['compose', 'text']).trim().length !== 0,
|
|
|
|
hasMediaAttachments: state.getIn(['compose', 'media_attachments']).size > 0,
|
2017-11-16 22:11:01 -08:00
|
|
|
layout: state.getIn(['local_settings', 'layout']),
|
|
|
|
isWide: state.getIn(['local_settings', 'stretch']),
|
2017-11-16 22:24:22 -08:00
|
|
|
navbarUnder: state.getIn(['local_settings', 'navbar_under']),
|
2018-03-30 03:45:23 -07:00
|
|
|
dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null,
|
2018-09-06 07:09:57 -07:00
|
|
|
unreadNotifications: state.getIn(['notifications', 'unread']),
|
2018-09-06 11:55:11 -07:00
|
|
|
showFaviconBadge: state.getIn(['local_settings', 'notifications', 'favicon_badge']),
|
2019-04-27 08:41:49 -07:00
|
|
|
hicolorPrivacyIcons: state.getIn(['local_settings', 'hicolor_privacy_icons']),
|
2017-07-06 13:39:56 -07:00
|
|
|
});
|
|
|
|
|
2017-10-05 16:07:59 -07:00
|
|
|
const keyMap = {
|
2017-12-20 07:50:29 -08:00
|
|
|
help: '?',
|
2017-10-05 16:07:59 -07:00
|
|
|
new: 'n',
|
|
|
|
search: 's',
|
|
|
|
forceNew: 'option+n',
|
|
|
|
focusColumn: ['1', '2', '3', '4', '5', '6', '7', '8', '9'],
|
|
|
|
reply: 'r',
|
|
|
|
favourite: 'f',
|
|
|
|
boost: 'b',
|
|
|
|
mention: 'm',
|
|
|
|
open: ['enter', 'o'],
|
|
|
|
openProfile: 'p',
|
|
|
|
moveDown: ['down', 'j'],
|
|
|
|
moveUp: ['up', 'k'],
|
|
|
|
back: 'backspace',
|
|
|
|
goToHome: 'g h',
|
|
|
|
goToNotifications: 'g n',
|
|
|
|
goToLocal: 'g l',
|
|
|
|
goToFederated: 'g t',
|
2017-10-22 18:45:35 -07:00
|
|
|
goToDirect: 'g d',
|
2017-10-05 16:07:59 -07:00
|
|
|
goToStart: 'g s',
|
|
|
|
goToFavourites: 'g f',
|
|
|
|
goToPinned: 'g p',
|
|
|
|
goToProfile: 'g u',
|
|
|
|
goToBlocked: 'g b',
|
|
|
|
goToMuted: 'g m',
|
2018-08-20 02:12:19 -07:00
|
|
|
goToRequests: 'g r',
|
2017-11-27 13:17:12 -08:00
|
|
|
toggleSpoiler: 'x',
|
2019-04-27 10:08:38 -07:00
|
|
|
bookmark: 'd',
|
2019-04-27 10:17:42 -07:00
|
|
|
toggleCollapse: 'shift+x',
|
2019-05-26 09:58:14 -07:00
|
|
|
toggleSensitive: 'h',
|
2017-10-05 16:07:59 -07:00
|
|
|
};
|
|
|
|
|
2017-07-06 13:39:56 -07:00
|
|
|
@connect(mapStateToProps)
|
2017-11-09 05:34:41 -08:00
|
|
|
@injectIntl
|
2017-08-29 05:16:21 -07:00
|
|
|
@withRouter
|
2017-09-29 19:29:56 -07:00
|
|
|
export default class UI extends React.Component {
|
2016-09-19 14:25:59 -07:00
|
|
|
|
2017-05-12 05:44:10 -07:00
|
|
|
static propTypes = {
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
2017-05-20 08:31:47 -07:00
|
|
|
children: PropTypes.node,
|
2017-06-24 17:07:25 -07:00
|
|
|
layout: PropTypes.string,
|
2017-06-28 22:00:54 -07:00
|
|
|
isWide: PropTypes.bool,
|
2017-07-06 13:39:56 -07:00
|
|
|
systemFontUi: PropTypes.bool,
|
2017-07-22 10:51:34 -07:00
|
|
|
navbarUnder: PropTypes.bool,
|
2017-07-20 16:38:24 -07:00
|
|
|
isComposing: PropTypes.bool,
|
2017-11-09 05:34:41 -08:00
|
|
|
hasComposingText: PropTypes.bool,
|
2018-09-22 14:08:03 -07:00
|
|
|
hasMediaAttachments: PropTypes.bool,
|
2018-07-24 11:33:17 -07:00
|
|
|
match: PropTypes.object.isRequired,
|
|
|
|
location: PropTypes.object.isRequired,
|
|
|
|
history: PropTypes.object.isRequired,
|
2017-11-09 05:34:41 -08:00
|
|
|
intl: PropTypes.object.isRequired,
|
2018-03-30 03:45:23 -07:00
|
|
|
dropdownMenuIsOpen: PropTypes.bool,
|
2018-09-06 07:09:57 -07:00
|
|
|
unreadNotifications: PropTypes.number,
|
2018-09-06 11:55:11 -07:00
|
|
|
showFaviconBadge: PropTypes.bool,
|
2017-05-12 05:44:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
width: window.innerWidth,
|
2017-05-20 08:31:47 -07:00
|
|
|
draggingOver: false,
|
2017-05-12 05:44:10 -07:00
|
|
|
};
|
2016-09-19 14:25:59 -07:00
|
|
|
|
2017-11-09 05:34:41 -08:00
|
|
|
handleBeforeUnload = (e) => {
|
2018-09-22 14:08:03 -07:00
|
|
|
const { intl, hasComposingText, hasMediaAttachments } = this.props;
|
2017-11-09 05:34:41 -08:00
|
|
|
|
2018-09-22 14:08:03 -07:00
|
|
|
if (hasComposingText || hasMediaAttachments) {
|
2017-11-09 05:34:41 -08:00
|
|
|
// Setting returnValue to any string causes confirmation dialog.
|
|
|
|
// Many browsers no longer display this text to users,
|
|
|
|
// but we set user-friendly message for other browsers, e.g. Edge.
|
|
|
|
e.returnValue = intl.formatMessage(messages.beforeUnload);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-17 17:57:41 -07:00
|
|
|
handleResize = debounce(() => {
|
2017-08-07 11:32:03 -07:00
|
|
|
// The cached heights are no longer accurate, invalidate
|
2017-09-13 01:24:33 -07:00
|
|
|
this.props.dispatch(clearHeight());
|
2017-08-07 11:32:03 -07:00
|
|
|
|
2016-12-06 10:18:37 -08:00
|
|
|
this.setState({ width: window.innerWidth });
|
2017-06-17 17:57:41 -07:00
|
|
|
}, 500, {
|
|
|
|
trailing: true,
|
|
|
|
});
|
2016-12-06 10:18:37 -08:00
|
|
|
|
2017-05-12 05:44:10 -07:00
|
|
|
handleDragEnter = (e) => {
|
2017-03-31 02:48:25 -07:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if (!this.dragTargets) {
|
|
|
|
this.dragTargets = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.dragTargets.indexOf(e.target) === -1) {
|
|
|
|
this.dragTargets.push(e.target);
|
|
|
|
}
|
|
|
|
|
2017-04-24 11:19:33 -07:00
|
|
|
if (e.dataTransfer && e.dataTransfer.types.includes('Files')) {
|
2017-04-01 13:11:28 -07:00
|
|
|
this.setState({ draggingOver: true });
|
|
|
|
}
|
2017-04-21 11:05:35 -07:00
|
|
|
}
|
2017-03-31 02:48:25 -07:00
|
|
|
|
2017-05-12 05:44:10 -07:00
|
|
|
handleDragOver = (e) => {
|
2019-01-17 14:27:51 -08:00
|
|
|
if (this.dataTransferIsText(e.dataTransfer)) return false;
|
2016-12-11 14:35:06 -08:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2017-03-31 02:48:25 -07:00
|
|
|
try {
|
|
|
|
e.dataTransfer.dropEffect = 'copy';
|
|
|
|
} catch (err) {
|
2016-12-11 14:35:06 -08:00
|
|
|
|
|
|
|
}
|
2017-03-31 02:48:25 -07:00
|
|
|
|
|
|
|
return false;
|
2017-04-21 11:05:35 -07:00
|
|
|
}
|
2016-12-11 14:35:06 -08:00
|
|
|
|
2017-05-12 05:44:10 -07:00
|
|
|
handleDrop = (e) => {
|
2019-01-17 14:27:51 -08:00
|
|
|
if (this.dataTransferIsText(e.dataTransfer)) return;
|
2016-12-11 14:35:06 -08:00
|
|
|
e.preventDefault();
|
|
|
|
|
2017-03-28 05:17:24 -07:00
|
|
|
this.setState({ draggingOver: false });
|
2019-01-16 05:50:17 -08:00
|
|
|
this.dragTargets = [];
|
2017-03-28 05:17:24 -07:00
|
|
|
|
2019-02-10 12:35:04 -08:00
|
|
|
if (e.dataTransfer && e.dataTransfer.files.length >= 1) {
|
2016-12-11 14:35:06 -08:00
|
|
|
this.props.dispatch(uploadCompose(e.dataTransfer.files));
|
|
|
|
}
|
2017-04-21 11:05:35 -07:00
|
|
|
}
|
2016-12-11 14:35:06 -08:00
|
|
|
|
2017-05-12 05:44:10 -07:00
|
|
|
handleDragLeave = (e) => {
|
2017-03-31 02:48:25 -07:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
this.dragTargets = this.dragTargets.filter(el => el !== e.target && this.node.contains(el));
|
|
|
|
|
|
|
|
if (this.dragTargets.length > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-23 19:50:30 -07:00
|
|
|
this.setState({ draggingOver: false });
|
2017-04-21 11:05:35 -07:00
|
|
|
}
|
2017-03-23 19:50:30 -07:00
|
|
|
|
2019-01-17 14:27:51 -08:00
|
|
|
dataTransferIsText = (dataTransfer) => {
|
|
|
|
return (dataTransfer && Array.from(dataTransfer.types).includes('text/plain') && dataTransfer.items.length === 1);
|
|
|
|
}
|
|
|
|
|
2017-05-12 05:44:10 -07:00
|
|
|
closeUploadModal = () => {
|
2017-04-24 11:19:33 -07:00
|
|
|
this.setState({ draggingOver: false });
|
|
|
|
}
|
|
|
|
|
2017-07-27 20:06:01 -07:00
|
|
|
handleServiceWorkerPostMessage = ({ data }) => {
|
|
|
|
if (data.type === 'navigate') {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push(data.path);
|
2017-07-27 20:06:01 -07:00
|
|
|
} else {
|
2017-08-24 03:15:36 -07:00
|
|
|
console.warn('Unknown message type:', data.type);
|
2017-07-27 20:06:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-06 08:47:33 -07:00
|
|
|
handleVisibilityChange = () => {
|
|
|
|
const visibility = !document[this.visibilityHiddenProp];
|
|
|
|
this.props.dispatch(notificationsSetVisibility(visibility));
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:18:37 -08:00
|
|
|
componentWillMount () {
|
2018-09-06 08:47:33 -07:00
|
|
|
if (typeof document.hidden !== 'undefined') { // Opera 12.10 and Firefox 18 and later support
|
|
|
|
this.visibilityHiddenProp = 'hidden';
|
|
|
|
this.visibilityChange = 'visibilitychange';
|
|
|
|
} else if (typeof document.msHidden !== 'undefined') {
|
|
|
|
this.visibilityHiddenProp = 'msHidden';
|
|
|
|
this.visibilityChange = 'msvisibilitychange';
|
|
|
|
} else if (typeof document.webkitHidden !== 'undefined') {
|
|
|
|
this.visibilityHiddenProp = 'webkitHidden';
|
|
|
|
this.visibilityChange = 'webkitvisibilitychange';
|
|
|
|
}
|
|
|
|
if (this.visibilityChange !== undefined) {
|
|
|
|
document.addEventListener(this.visibilityChange, this.handleVisibilityChange, false);
|
|
|
|
this.handleVisibilityChange();
|
|
|
|
}
|
|
|
|
|
2017-11-09 05:34:41 -08:00
|
|
|
window.addEventListener('beforeunload', this.handleBeforeUnload, false);
|
2016-12-06 10:18:37 -08:00
|
|
|
window.addEventListener('resize', this.handleResize, { passive: true });
|
2017-03-31 02:48:25 -07:00
|
|
|
document.addEventListener('dragenter', this.handleDragEnter, false);
|
|
|
|
document.addEventListener('dragover', this.handleDragOver, false);
|
|
|
|
document.addEventListener('drop', this.handleDrop, false);
|
|
|
|
document.addEventListener('dragleave', this.handleDragLeave, false);
|
2017-04-24 11:19:33 -07:00
|
|
|
document.addEventListener('dragend', this.handleDragEnd, false);
|
2017-01-19 01:54:18 -08:00
|
|
|
|
2017-07-27 20:06:01 -07:00
|
|
|
if ('serviceWorker' in navigator) {
|
|
|
|
navigator.serviceWorker.addEventListener('message', this.handleServiceWorkerPostMessage);
|
|
|
|
}
|
|
|
|
|
2018-09-06 07:09:57 -07:00
|
|
|
this.favicon = new Favico({ animation:"none" });
|
|
|
|
|
2018-05-27 10:10:37 -07:00
|
|
|
this.props.dispatch(expandHomeTimeline());
|
2018-05-27 10:30:52 -07:00
|
|
|
this.props.dispatch(expandNotifications());
|
2018-07-08 11:04:53 -07:00
|
|
|
setTimeout(() => this.props.dispatch(fetchFilters()), 500);
|
2017-04-21 11:05:35 -07:00
|
|
|
}
|
2016-12-06 10:18:37 -08:00
|
|
|
|
2017-10-05 16:07:59 -07:00
|
|
|
componentDidMount () {
|
|
|
|
this.hotkeys.__mousetrap__.stopCallback = (e, element) => {
|
2017-10-11 07:31:07 -07:00
|
|
|
return ['TEXTAREA', 'SELECT', 'INPUT'].includes(element.tagName);
|
2017-10-05 16:07:59 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-29 05:16:21 -07:00
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
if (![this.props.location.pathname, '/'].includes(prevProps.location.pathname)) {
|
|
|
|
this.columnsAreaNode.handleChildrenContentChange();
|
|
|
|
}
|
2018-09-06 11:55:11 -07:00
|
|
|
if (this.props.unreadNotifications != prevProps.unreadNotifications ||
|
|
|
|
this.props.showFaviconBadge != prevProps.showFaviconBadge) {
|
2018-09-06 07:09:57 -07:00
|
|
|
if (this.favicon) {
|
2018-09-06 11:55:11 -07:00
|
|
|
this.favicon.badge(this.props.showFaviconBadge ? this.props.unreadNotifications : 0);
|
2018-09-06 07:09:57 -07:00
|
|
|
}
|
|
|
|
}
|
2017-08-29 05:16:21 -07:00
|
|
|
}
|
|
|
|
|
2016-12-06 10:18:37 -08:00
|
|
|
componentWillUnmount () {
|
2018-09-06 08:47:33 -07:00
|
|
|
if (this.visibilityChange !== undefined) {
|
|
|
|
document.removeEventListener(this.visibilityChange, this.handleVisibilityChange);
|
|
|
|
}
|
|
|
|
|
2017-11-09 05:34:41 -08:00
|
|
|
window.removeEventListener('beforeunload', this.handleBeforeUnload);
|
2016-12-06 10:18:37 -08:00
|
|
|
window.removeEventListener('resize', this.handleResize);
|
2017-03-31 02:48:25 -07:00
|
|
|
document.removeEventListener('dragenter', this.handleDragEnter);
|
|
|
|
document.removeEventListener('dragover', this.handleDragOver);
|
|
|
|
document.removeEventListener('drop', this.handleDrop);
|
|
|
|
document.removeEventListener('dragleave', this.handleDragLeave);
|
2017-04-24 11:19:33 -07:00
|
|
|
document.removeEventListener('dragend', this.handleDragEnd);
|
2017-04-21 11:05:35 -07:00
|
|
|
}
|
2017-03-31 02:48:25 -07:00
|
|
|
|
2017-09-21 19:59:17 -07:00
|
|
|
setRef = c => {
|
2017-03-31 02:48:25 -07:00
|
|
|
this.node = c;
|
2017-04-21 11:05:35 -07:00
|
|
|
}
|
2016-12-06 10:18:37 -08:00
|
|
|
|
2017-09-21 19:59:17 -07:00
|
|
|
setColumnsAreaRef = c => {
|
2019-01-02 07:07:33 -08:00
|
|
|
this.columnsAreaNode = c.getWrappedInstance();
|
2017-08-29 05:16:21 -07:00
|
|
|
}
|
|
|
|
|
2017-10-05 16:07:59 -07:00
|
|
|
handleHotkeyNew = e => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2019-06-02 01:05:54 -07:00
|
|
|
const element = this.node.querySelector('.compose-form__autosuggest-wrapper textarea');
|
2017-10-05 16:07:59 -07:00
|
|
|
|
|
|
|
if (element) {
|
|
|
|
element.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeySearch = e => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2019-06-27 13:30:55 -07:00
|
|
|
const element = this.node.querySelector('.search__input');
|
2017-10-05 16:07:59 -07:00
|
|
|
|
|
|
|
if (element) {
|
|
|
|
element.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyForceNew = e => {
|
|
|
|
this.handleHotkeyNew(e);
|
|
|
|
this.props.dispatch(resetCompose());
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyFocusColumn = e => {
|
|
|
|
const index = (e.key * 1) + 1; // First child is drawer, skip that
|
|
|
|
const column = this.node.querySelector(`.column:nth-child(${index})`);
|
2019-04-15 11:40:05 -07:00
|
|
|
if (!column) return;
|
|
|
|
const container = column.querySelector('.scrollable');
|
2017-10-05 16:07:59 -07:00
|
|
|
|
2019-04-15 11:40:05 -07:00
|
|
|
if (container) {
|
|
|
|
const status = container.querySelector('.focusable');
|
2017-10-05 16:07:59 -07:00
|
|
|
|
|
|
|
if (status) {
|
2019-04-15 11:40:05 -07:00
|
|
|
if (container.scrollTop > status.offsetTop) {
|
|
|
|
status.scrollIntoView(true);
|
|
|
|
}
|
2017-10-05 16:07:59 -07:00
|
|
|
status.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyBack = () => {
|
2018-05-23 05:17:05 -07:00
|
|
|
// if history is exhausted, or we would leave mastodon, just go to root.
|
|
|
|
if (window.history.state) {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.goBack();
|
2017-10-05 16:07:59 -07:00
|
|
|
} else {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/');
|
2017-10-05 16:07:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setHotkeysRef = c => {
|
|
|
|
this.hotkeys = c;
|
|
|
|
}
|
|
|
|
|
2017-12-20 07:50:29 -08:00
|
|
|
handleHotkeyToggleHelp = () => {
|
|
|
|
if (this.props.location.pathname === '/keyboard-shortcuts') {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.goBack();
|
2017-12-20 07:50:29 -08:00
|
|
|
} else {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/keyboard-shortcuts');
|
2017-12-20 07:50:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-05 16:07:59 -07:00
|
|
|
handleHotkeyGoToHome = () => {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/timelines/home');
|
2017-10-05 16:07:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyGoToNotifications = () => {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/notifications');
|
2017-10-05 16:07:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyGoToLocal = () => {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/timelines/public/local');
|
2017-10-05 16:07:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyGoToFederated = () => {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/timelines/public');
|
2017-10-05 16:07:59 -07:00
|
|
|
}
|
|
|
|
|
2017-10-22 18:45:35 -07:00
|
|
|
handleHotkeyGoToDirect = () => {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/timelines/direct');
|
2017-10-22 18:45:35 -07:00
|
|
|
}
|
|
|
|
|
2017-10-05 16:07:59 -07:00
|
|
|
handleHotkeyGoToStart = () => {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/getting-started');
|
2017-10-05 16:07:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyGoToFavourites = () => {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/favourites');
|
2017-10-05 16:07:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyGoToPinned = () => {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/pinned');
|
2017-10-05 16:07:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyGoToProfile = () => {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push(`/accounts/${me}`);
|
2017-10-05 16:07:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyGoToBlocked = () => {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/blocks');
|
2017-10-05 16:07:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyGoToMuted = () => {
|
2018-07-24 11:33:17 -07:00
|
|
|
this.props.history.push('/mutes');
|
2017-09-21 19:59:17 -07:00
|
|
|
}
|
|
|
|
|
2018-08-20 02:12:19 -07:00
|
|
|
handleHotkeyGoToRequests = () => {
|
|
|
|
this.props.history.push('/follow_requests');
|
|
|
|
}
|
|
|
|
|
2016-09-19 14:25:59 -07:00
|
|
|
render () {
|
2017-03-23 19:50:30 -07:00
|
|
|
const { width, draggingOver } = this.state;
|
2019-05-25 12:27:00 -07:00
|
|
|
const { children, layout, isWide, navbarUnder, dropdownMenuIsOpen } = this.props;
|
2019-06-12 08:18:45 -07:00
|
|
|
const singleColumn = isMobile(width, layout);
|
2019-05-22 16:35:22 -07:00
|
|
|
const redirect = singleColumn ? <Redirect from='/' to='/timelines/home' exact /> : <Redirect from='/' to='/getting-started' exact />;
|
2017-03-23 19:50:30 -07:00
|
|
|
|
2017-06-24 17:07:25 -07:00
|
|
|
const columnsClass = layout => {
|
|
|
|
switch (layout) {
|
|
|
|
case 'single':
|
|
|
|
return 'single-column';
|
|
|
|
case 'multiple':
|
2017-06-24 19:12:34 -07:00
|
|
|
return 'multi-columns';
|
2017-06-24 17:07:25 -07:00
|
|
|
default:
|
|
|
|
return 'auto-columns';
|
|
|
|
}
|
2017-06-24 19:12:34 -07:00
|
|
|
};
|
2017-06-24 12:22:55 -07:00
|
|
|
|
2017-07-12 02:03:17 -07:00
|
|
|
const className = classNames('ui', columnsClass(layout), {
|
|
|
|
'wide': isWide,
|
2017-07-06 13:39:56 -07:00
|
|
|
'system-font': this.props.systemFontUi,
|
2017-07-22 11:41:21 -07:00
|
|
|
'navbar-under': navbarUnder,
|
2019-04-27 08:41:49 -07:00
|
|
|
'hicolor-privacy-icons': this.props.hicolorPrivacyIcons,
|
2017-07-06 13:39:56 -07:00
|
|
|
});
|
2017-03-23 19:50:30 -07:00
|
|
|
|
2017-10-05 16:07:59 -07:00
|
|
|
const handlers = {
|
2017-12-20 07:50:29 -08:00
|
|
|
help: this.handleHotkeyToggleHelp,
|
2017-10-05 16:07:59 -07:00
|
|
|
new: this.handleHotkeyNew,
|
|
|
|
search: this.handleHotkeySearch,
|
|
|
|
forceNew: this.handleHotkeyForceNew,
|
|
|
|
focusColumn: this.handleHotkeyFocusColumn,
|
|
|
|
back: this.handleHotkeyBack,
|
|
|
|
goToHome: this.handleHotkeyGoToHome,
|
|
|
|
goToNotifications: this.handleHotkeyGoToNotifications,
|
|
|
|
goToLocal: this.handleHotkeyGoToLocal,
|
|
|
|
goToFederated: this.handleHotkeyGoToFederated,
|
2017-10-22 18:45:35 -07:00
|
|
|
goToDirect: this.handleHotkeyGoToDirect,
|
2017-10-05 16:07:59 -07:00
|
|
|
goToStart: this.handleHotkeyGoToStart,
|
|
|
|
goToFavourites: this.handleHotkeyGoToFavourites,
|
|
|
|
goToPinned: this.handleHotkeyGoToPinned,
|
|
|
|
goToProfile: this.handleHotkeyGoToProfile,
|
|
|
|
goToBlocked: this.handleHotkeyGoToBlocked,
|
|
|
|
goToMuted: this.handleHotkeyGoToMuted,
|
2018-08-20 02:12:19 -07:00
|
|
|
goToRequests: this.handleHotkeyGoToRequests,
|
2017-10-05 16:07:59 -07:00
|
|
|
};
|
|
|
|
|
2016-09-19 14:25:59 -07:00
|
|
|
return (
|
2018-10-10 08:23:40 -07:00
|
|
|
<HotKeys keyMap={keyMap} handlers={handlers} ref={this.setHotkeysRef} attach={window} focused>
|
2018-03-30 03:45:23 -07:00
|
|
|
<div className={className} ref={this.setRef} style={{ pointerEvents: dropdownMenuIsOpen ? 'none' : null }}>
|
2019-06-12 08:30:36 -07:00
|
|
|
<ColumnsAreaContainer ref={this.setColumnsAreaRef} singleColumn={singleColumn} navbarUnder={navbarUnder}>
|
2017-10-05 16:07:59 -07:00
|
|
|
<WrappedSwitch>
|
2019-05-22 16:35:22 -07:00
|
|
|
{redirect}
|
2017-10-05 16:07:59 -07:00
|
|
|
<WrappedRoute path='/getting-started' component={GettingStarted} content={children} />
|
2017-12-20 07:50:29 -08:00
|
|
|
<WrappedRoute path='/keyboard-shortcuts' component={KeyboardShortcuts} content={children} />
|
2017-10-05 16:07:59 -07:00
|
|
|
<WrappedRoute path='/timelines/home' component={HomeTimeline} content={children} />
|
|
|
|
<WrappedRoute path='/timelines/public' exact component={PublicTimeline} content={children} />
|
2018-05-27 12:22:17 -07:00
|
|
|
<WrappedRoute path='/timelines/public/local' exact component={CommunityTimeline} content={children} />
|
2017-10-15 21:02:39 -07:00
|
|
|
<WrappedRoute path='/timelines/direct' component={DirectTimeline} content={children} />
|
2017-10-05 16:07:59 -07:00
|
|
|
<WrappedRoute path='/timelines/tag/:id' component={HashtagTimeline} content={children} />
|
2017-12-08 17:40:49 -08:00
|
|
|
<WrappedRoute path='/timelines/list/:id' component={ListTimeline} content={children} />
|
2017-10-05 16:07:59 -07:00
|
|
|
<WrappedRoute path='/notifications' component={Notifications} content={children} />
|
|
|
|
<WrappedRoute path='/favourites' component={FavouritedStatuses} content={children} />
|
2018-04-11 10:42:25 -07:00
|
|
|
<WrappedRoute path='/bookmarks' component={BookmarkedStatuses} content={children} />
|
2017-10-05 16:07:59 -07:00
|
|
|
<WrappedRoute path='/pinned' component={PinnedStatuses} content={children} />
|
|
|
|
|
2019-05-25 12:27:00 -07:00
|
|
|
<WrappedRoute path='/search' component={Search} content={children} />
|
2018-08-31 04:54:25 -07:00
|
|
|
|
2019-04-19 11:14:32 -07:00
|
|
|
<WrappedRoute path='/statuses/new' component={Compose} content={children} />
|
2017-10-05 16:07:59 -07:00
|
|
|
<WrappedRoute path='/statuses/:statusId' exact component={Status} content={children} />
|
|
|
|
<WrappedRoute path='/statuses/:statusId/reblogs' component={Reblogs} content={children} />
|
|
|
|
<WrappedRoute path='/statuses/:statusId/favourites' component={Favourites} content={children} />
|
|
|
|
|
|
|
|
<WrappedRoute path='/accounts/:accountId' exact component={AccountTimeline} content={children} />
|
2018-03-16 11:54:00 -07:00
|
|
|
<WrappedRoute path='/accounts/:accountId/with_replies' component={AccountTimeline} content={children} componentParams={{ withReplies: true }} />
|
2017-10-05 16:07:59 -07:00
|
|
|
<WrappedRoute path='/accounts/:accountId/followers' component={Followers} content={children} />
|
|
|
|
<WrappedRoute path='/accounts/:accountId/following' component={Following} content={children} />
|
|
|
|
<WrappedRoute path='/accounts/:accountId/media' component={AccountGallery} content={children} />
|
|
|
|
|
|
|
|
<WrappedRoute path='/follow_requests' component={FollowRequests} content={children} />
|
|
|
|
<WrappedRoute path='/blocks' component={Blocks} content={children} />
|
2018-03-04 12:46:27 -08:00
|
|
|
<WrappedRoute path='/domain_blocks' component={DomainBlocks} content={children} />
|
2017-10-05 16:07:59 -07:00
|
|
|
<WrappedRoute path='/mutes' component={Mutes} content={children} />
|
2017-12-08 18:13:08 -08:00
|
|
|
<WrappedRoute path='/lists' component={Lists} content={children} />
|
2017-12-11 22:01:17 -08:00
|
|
|
<WrappedRoute path='/getting-started-misc' component={GettingStartedMisc} content={children} />
|
2017-10-05 16:07:59 -07:00
|
|
|
|
|
|
|
<WrappedRoute component={GenericNotFound} content={children} />
|
|
|
|
</WrappedSwitch>
|
|
|
|
</ColumnsAreaContainer>
|
|
|
|
|
|
|
|
<NotificationsContainer />
|
|
|
|
<LoadingBarContainer className='loading-bar' />
|
|
|
|
<ModalContainer />
|
|
|
|
<UploadArea active={draggingOver} onClose={this.closeUploadModal} />
|
|
|
|
</div>
|
|
|
|
</HotKeys>
|
2016-09-19 14:25:59 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 11:05:35 -07:00
|
|
|
}
|