You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
685 lines
23 KiB
685 lines
23 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import NotificationsContainer from './containers/notifications_container';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
8 years ago
|
import LoadingBarContainer from './containers/loading_bar_container';
|
||
|
import ModalContainer from './containers/modal_container';
|
||
8 years ago
|
import { connect } from 'react-redux';
|
||
2 years ago
|
import { Redirect, Route, withRouter } from 'react-router-dom';
|
||
2 years ago
|
import { layoutFromWindow } from 'flavours/glitch/is_mobile';
|
||
8 years ago
|
import { debounce } from 'lodash';
|
||
5 years ago
|
import { uploadCompose, resetCompose, changeComposeSpoilerness } from 'flavours/glitch/actions/compose';
|
||
7 years ago
|
import { expandHomeTimeline } from 'flavours/glitch/actions/timelines';
|
||
6 years ago
|
import { expandNotifications, notificationsSetVisibility } from 'flavours/glitch/actions/notifications';
|
||
2 years ago
|
import { fetchServer } from 'flavours/glitch/actions/server';
|
||
7 years ago
|
import { clearHeight } from 'flavours/glitch/actions/height_cache';
|
||
4 years ago
|
import { changeLayout } from 'flavours/glitch/actions/app';
|
||
4 years ago
|
import { synchronouslySubmitMarkers, submitMarkers, fetchMarkers } from 'flavours/glitch/actions/markers';
|
||
2 years ago
|
import { WrappedSwitch, WrappedRoute } from './util/react_router_helpers';
|
||
2 years ago
|
import BundleColumnError from './components/bundle_column_error';
|
||
8 years ago
|
import UploadArea from './components/upload_area';
|
||
5 years ago
|
import PermaLink from 'flavours/glitch/components/permalink';
|
||
8 years ago
|
import ColumnsAreaContainer from './containers/columns_area_container';
|
||
7 years ago
|
import classNames from 'classnames';
|
||
6 years ago
|
import Favico from 'favico.js';
|
||
4 years ago
|
import PictureInPicture from 'flavours/glitch/features/picture_in_picture';
|
||
7 years ago
|
import {
|
||
6 years ago
|
Compose,
|
||
7 years ago
|
Status,
|
||
|
GettingStarted,
|
||
7 years ago
|
KeyboardShortcuts,
|
||
7 years ago
|
PublicTimeline,
|
||
|
CommunityTimeline,
|
||
|
AccountTimeline,
|
||
|
AccountGallery,
|
||
|
HomeTimeline,
|
||
|
Followers,
|
||
|
Following,
|
||
|
Reblogs,
|
||
|
Favourites,
|
||
7 years ago
|
DirectTimeline,
|
||
7 years ago
|
HashtagTimeline,
|
||
7 years ago
|
Notifications,
|
||
7 years ago
|
FollowRequests,
|
||
|
FavouritedStatuses,
|
||
7 years ago
|
BookmarkedStatuses,
|
||
2 years ago
|
FollowedTags,
|
||
7 years ago
|
ListTimeline,
|
||
7 years ago
|
Blocks,
|
||
7 years ago
|
DomainBlocks,
|
||
7 years ago
|
Mutes,
|
||
7 years ago
|
PinnedStatuses,
|
||
7 years ago
|
Lists,
|
||
7 years ago
|
GettingStartedMisc,
|
||
5 years ago
|
Directory,
|
||
3 years ago
|
Explore,
|
||
4 years ago
|
FollowRecommendations,
|
||
2 years ago
|
About,
|
||
2 years ago
|
PrivacyPolicy,
|
||
2 years ago
|
} from './util/async-components';
|
||
7 years ago
|
import { HotKeys } from 'react-hotkeys';
|
||
2 years ago
|
import initialState, { me, owner, singleUserMode, showTrends, trendsAsLanding } from '../../initial_state';
|
||
4 years ago
|
import { closeOnboarding, INTRODUCTION_VERSION } from 'flavours/glitch/actions/onboarding';
|
||
5 years ago
|
import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
|
||
2 years ago
|
import { Helmet } from 'react-helmet';
|
||
2 years ago
|
import Header from './components/header';
|
||
7 years ago
|
|
||
|
// Dummy import, to make sure that <Status /> ends up in the application bundle.
|
||
|
// Without this it ends up in ~8 very commonly used bundles.
|
||
7 years ago
|
import '../../../glitch/components/status';
|
||
8 years ago
|
|
||
7 years ago
|
const messages = defineMessages({
|
||
|
beforeUnload: { id: 'ui.beforeunload', defaultMessage: 'Your draft will be lost if you leave Mastodon.' },
|
||
|
});
|
||
|
|
||
7 years ago
|
const mapStateToProps = state => ({
|
||
4 years ago
|
layout: state.getIn(['meta', 'layout']),
|
||
6 years ago
|
hasComposingText: state.getIn(['compose', 'text']).trim().length !== 0,
|
||
|
hasMediaAttachments: state.getIn(['compose', 'media_attachments']).size > 0,
|
||
5 years ago
|
canUploadMore: !state.getIn(['compose', 'media_attachments']).some(x => ['audio', 'video'].includes(x.get('type'))) && state.getIn(['compose', 'media_attachments']).size < 4,
|
||
4 years ago
|
layout: state.getIn(['meta', 'layout']),
|
||
|
layout_local_setting: state.getIn(['local_settings', 'layout']),
|
||
7 years ago
|
isWide: state.getIn(['local_settings', 'stretch']),
|
||
7 years ago
|
navbarUnder: state.getIn(['local_settings', 'navbar_under']),
|
||
7 years ago
|
dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null,
|
||
6 years ago
|
unreadNotifications: state.getIn(['notifications', 'unread']),
|
||
6 years ago
|
showFaviconBadge: state.getIn(['local_settings', 'notifications', 'favicon_badge']),
|
||
6 years ago
|
hicolorPrivacyIcons: state.getIn(['local_settings', 'hicolor_privacy_icons']),
|
||
5 years ago
|
moved: state.getIn(['accounts', me, 'moved']) && state.getIn(['accounts', state.getIn(['accounts', me, 'moved'])]),
|
||
4 years ago
|
firstLaunch: state.getIn(['settings', 'introductionVersion'], 0) < INTRODUCTION_VERSION,
|
||
3 years ago
|
username: state.getIn(['accounts', me, 'username']),
|
||
7 years ago
|
});
|
||
|
|
||
7 years ago
|
const keyMap = {
|
||
7 years ago
|
help: '?',
|
||
7 years ago
|
new: 'n',
|
||
|
search: 's',
|
||
|
forceNew: 'option+n',
|
||
5 years ago
|
toggleComposeSpoilers: 'option+x',
|
||
7 years ago
|
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',
|
||
7 years ago
|
goToDirect: 'g d',
|
||
7 years ago
|
goToStart: 'g s',
|
||
|
goToFavourites: 'g f',
|
||
|
goToPinned: 'g p',
|
||
|
goToProfile: 'g u',
|
||
|
goToBlocked: 'g b',
|
||
|
goToMuted: 'g m',
|
||
6 years ago
|
goToRequests: 'g r',
|
||
7 years ago
|
toggleSpoiler: 'x',
|
||
6 years ago
|
bookmark: 'd',
|
||
6 years ago
|
toggleCollapse: 'shift+x',
|
||
6 years ago
|
toggleSensitive: 'h',
|
||
5 years ago
|
openMedia: 'e',
|
||
7 years ago
|
};
|
||
|
|
||
5 years ago
|
class SwitchingColumnsArea extends React.PureComponent {
|
||
|
|
||
2 years ago
|
static contextTypes = {
|
||
|
identity: PropTypes.object,
|
||
|
};
|
||
|
|
||
5 years ago
|
static propTypes = {
|
||
|
children: PropTypes.node,
|
||
|
location: PropTypes.object,
|
||
|
navbarUnder: PropTypes.bool,
|
||
4 years ago
|
mobile: PropTypes.bool,
|
||
5 years ago
|
};
|
||
|
|
||
|
componentWillMount () {
|
||
4 years ago
|
if (this.props.mobile) {
|
||
5 years ago
|
document.body.classList.toggle('layout-single-column', true);
|
||
|
document.body.classList.toggle('layout-multiple-columns', false);
|
||
|
} else {
|
||
|
document.body.classList.toggle('layout-single-column', false);
|
||
|
document.body.classList.toggle('layout-multiple-columns', true);
|
||
|
}
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
componentDidUpdate (prevProps) {
|
||
5 years ago
|
if (![this.props.location.pathname, '/'].includes(prevProps.location.pathname)) {
|
||
|
this.node.handleChildrenContentChange();
|
||
|
}
|
||
5 years ago
|
|
||
4 years ago
|
if (prevProps.mobile !== this.props.mobile) {
|
||
|
document.body.classList.toggle('layout-single-column', this.props.mobile);
|
||
|
document.body.classList.toggle('layout-multiple-columns', !this.props.mobile);
|
||
5 years ago
|
}
|
||
|
}
|
||
5 years ago
|
|
||
|
setRef = c => {
|
||
5 years ago
|
if (c) {
|
||
2 years ago
|
this.node = c;
|
||
5 years ago
|
}
|
||
2 years ago
|
};
|
||
5 years ago
|
|
||
|
render () {
|
||
4 years ago
|
const { children, mobile, navbarUnder } = this.props;
|
||
2 years ago
|
const { signedIn } = this.context.identity;
|
||
|
|
||
|
let redirect;
|
||
|
|
||
|
if (signedIn) {
|
||
|
if (mobile) {
|
||
|
redirect = <Redirect from='/' to='/home' exact />;
|
||
|
} else {
|
||
|
redirect = <Redirect from='/' to='/getting-started' exact />;
|
||
|
}
|
||
2 years ago
|
} else if (singleUserMode && owner && initialState?.accounts[owner]) {
|
||
|
redirect = <Redirect from='/' to={`/@${initialState.accounts[owner].username}`} exact />;
|
||
2 years ago
|
} else if (showTrends && trendsAsLanding) {
|
||
2 years ago
|
redirect = <Redirect from='/' to='/explore' exact />;
|
||
2 years ago
|
} else {
|
||
|
redirect = <Redirect from='/' to='/about' exact />;
|
||
2 years ago
|
}
|
||
5 years ago
|
|
||
|
return (
|
||
4 years ago
|
<ColumnsAreaContainer ref={this.setRef} singleColumn={mobile} navbarUnder={navbarUnder}>
|
||
5 years ago
|
<WrappedSwitch>
|
||
|
{redirect}
|
||
2 years ago
|
|
||
5 years ago
|
<WrappedRoute path='/getting-started' component={GettingStarted} content={children} />
|
||
|
<WrappedRoute path='/keyboard-shortcuts' component={KeyboardShortcuts} content={children} />
|
||
2 years ago
|
<WrappedRoute path='/about' component={About} content={children} />
|
||
2 years ago
|
<WrappedRoute path='/privacy-policy' component={PrivacyPolicy} content={children} />
|
||
5 years ago
|
|
||
3 years ago
|
<WrappedRoute path={['/home', '/timelines/home']} component={HomeTimeline} content={children} />
|
||
|
<WrappedRoute path={['/public', '/timelines/public']} exact component={PublicTimeline} content={children} />
|
||
|
<WrappedRoute path={['/public/local', '/timelines/public/local']} exact component={CommunityTimeline} content={children} />
|
||
|
<WrappedRoute path={['/conversations', '/timelines/direct']} component={DirectTimeline} content={children} />
|
||
3 years ago
|
<WrappedRoute path='/tags/:id' component={HashtagTimeline} content={children} />
|
||
|
<WrappedRoute path='/lists/:id' component={ListTimeline} content={children} />
|
||
5 years ago
|
<WrappedRoute path='/notifications' component={Notifications} content={children} />
|
||
|
<WrappedRoute path='/favourites' component={FavouritedStatuses} content={children} />
|
||
3 years ago
|
|
||
5 years ago
|
<WrappedRoute path='/bookmarks' component={BookmarkedStatuses} content={children} />
|
||
|
<WrappedRoute path='/pinned' component={PinnedStatuses} content={children} />
|
||
|
|
||
4 years ago
|
<WrappedRoute path='/start' component={FollowRecommendations} content={children} />
|
||
3 years ago
|
<WrappedRoute path='/directory' component={Directory} content={children} />
|
||
3 years ago
|
<WrappedRoute path={['/explore', '/search']} component={Explore} content={children} />
|
||
3 years ago
|
<WrappedRoute path={['/publish', '/statuses/new']} component={Compose} content={children} />
|
||
5 years ago
|
|
||
3 years ago
|
<WrappedRoute path={['/@:acct', '/accounts/:id']} exact component={AccountTimeline} content={children} />
|
||
2 years ago
|
<WrappedRoute path='/@:acct/tagged/:tagged?' exact component={AccountTimeline} content={children} />
|
||
3 years ago
|
<WrappedRoute path={['/@:acct/with_replies', '/accounts/:id/with_replies']} component={AccountTimeline} content={children} componentParams={{ withReplies: true }} />
|
||
2 years ago
|
<WrappedRoute path={['/accounts/:id/followers', '/users/:acct/followers', '/@:acct/followers']} component={Followers} content={children} />
|
||
|
<WrappedRoute path={['/accounts/:id/following', '/users/:acct/following', '/@:acct/following']} component={Following} content={children} />
|
||
3 years ago
|
<WrappedRoute path={['/@:acct/media', '/accounts/:id/media']} component={AccountGallery} content={children} />
|
||
3 years ago
|
<WrappedRoute path='/@:acct/:statusId' exact component={Status} content={children} />
|
||
|
<WrappedRoute path='/@:acct/:statusId/reblogs' component={Reblogs} content={children} />
|
||
|
<WrappedRoute path='/@:acct/:statusId/favourites' component={Favourites} content={children} />
|
||
5 years ago
|
|
||
3 years ago
|
{/* Legacy routes, cannot be easily factored with other routes because they share a param name */}
|
||
|
<WrappedRoute path='/timelines/tag/:id' component={HashtagTimeline} content={children} />
|
||
|
<WrappedRoute path='/timelines/list/:id' component={ListTimeline} content={children} />
|
||
|
<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} />
|
||
|
|
||
5 years ago
|
<WrappedRoute path='/follow_requests' component={FollowRequests} content={children} />
|
||
|
<WrappedRoute path='/blocks' component={Blocks} content={children} />
|
||
|
<WrappedRoute path='/domain_blocks' component={DomainBlocks} content={children} />
|
||
2 years ago
|
<WrappedRoute path='/followed_tags' component={FollowedTags} content={children} />
|
||
5 years ago
|
<WrappedRoute path='/mutes' component={Mutes} content={children} />
|
||
|
<WrappedRoute path='/lists' component={Lists} content={children} />
|
||
|
<WrappedRoute path='/getting-started-misc' component={GettingStartedMisc} content={children} />
|
||
|
|
||
2 years ago
|
<Route component={BundleColumnError} />
|
||
5 years ago
|
</WrappedSwitch>
|
||
|
</ColumnsAreaContainer>
|
||
|
);
|
||
2 years ago
|
}
|
||
5 years ago
|
|
||
|
}
|
||
|
|
||
|
export default @connect(mapStateToProps)
|
||
7 years ago
|
@injectIntl
|
||
7 years ago
|
@withRouter
|
||
5 years ago
|
class UI extends React.Component {
|
||
8 years ago
|
|
||
2 years ago
|
static contextTypes = {
|
||
|
identity: PropTypes.object.isRequired,
|
||
|
};
|
||
|
|
||
8 years ago
|
static propTypes = {
|
||
|
dispatch: PropTypes.func.isRequired,
|
||
8 years ago
|
children: PropTypes.node,
|
||
4 years ago
|
layout_local_setting: PropTypes.string,
|
||
7 years ago
|
isWide: PropTypes.bool,
|
||
7 years ago
|
systemFontUi: PropTypes.bool,
|
||
7 years ago
|
navbarUnder: PropTypes.bool,
|
||
7 years ago
|
isComposing: PropTypes.bool,
|
||
7 years ago
|
hasComposingText: PropTypes.bool,
|
||
6 years ago
|
hasMediaAttachments: PropTypes.bool,
|
||
5 years ago
|
canUploadMore: PropTypes.bool,
|
||
6 years ago
|
match: PropTypes.object.isRequired,
|
||
|
location: PropTypes.object.isRequired,
|
||
|
history: PropTypes.object.isRequired,
|
||
7 years ago
|
intl: PropTypes.object.isRequired,
|
||
7 years ago
|
dropdownMenuIsOpen: PropTypes.bool,
|
||
6 years ago
|
unreadNotifications: PropTypes.number,
|
||
6 years ago
|
showFaviconBadge: PropTypes.bool,
|
||
5 years ago
|
moved: PropTypes.map,
|
||
4 years ago
|
layout: PropTypes.string.isRequired,
|
||
4 years ago
|
firstLaunch: PropTypes.bool,
|
||
3 years ago
|
username: PropTypes.string,
|
||
8 years ago
|
};
|
||
|
|
||
|
state = {
|
||
8 years ago
|
draggingOver: false,
|
||
8 years ago
|
};
|
||
8 years ago
|
|
||
7 years ago
|
handleBeforeUnload = (e) => {
|
||
5 years ago
|
const { intl, dispatch, hasComposingText, hasMediaAttachments } = this.props;
|
||
|
|
||
5 years ago
|
dispatch(synchronouslySubmitMarkers());
|
||
7 years ago
|
|
||
6 years ago
|
if (hasComposingText || hasMediaAttachments) {
|
||
7 years ago
|
// 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);
|
||
|
}
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
8 years ago
|
handleDragEnter = (e) => {
|
||
8 years ago
|
e.preventDefault();
|
||
|
|
||
|
if (!this.dragTargets) {
|
||
|
this.dragTargets = [];
|
||
|
}
|
||
|
|
||
|
if (this.dragTargets.indexOf(e.target) === -1) {
|
||
|
this.dragTargets.push(e.target);
|
||
|
}
|
||
|
|
||
2 years ago
|
if (e.dataTransfer && e.dataTransfer.types.includes('Files') && this.props.canUploadMore && this.context.identity.signedIn) {
|
||
8 years ago
|
this.setState({ draggingOver: true });
|
||
|
}
|
||
2 years ago
|
};
|
||
8 years ago
|
|
||
8 years ago
|
handleDragOver = (e) => {
|
||
6 years ago
|
if (this.dataTransferIsText(e.dataTransfer)) return false;
|
||
8 years ago
|
e.preventDefault();
|
||
|
e.stopPropagation();
|
||
|
|
||
8 years ago
|
try {
|
||
|
e.dataTransfer.dropEffect = 'copy';
|
||
|
} catch (err) {
|
||
8 years ago
|
|
||
|
}
|
||
8 years ago
|
|
||
|
return false;
|
||
2 years ago
|
};
|
||
8 years ago
|
|
||
8 years ago
|
handleDrop = (e) => {
|
||
6 years ago
|
if (this.dataTransferIsText(e.dataTransfer)) return;
|
||
5 years ago
|
|
||
8 years ago
|
e.preventDefault();
|
||
|
|
||
8 years ago
|
this.setState({ draggingOver: false });
|
||
6 years ago
|
this.dragTargets = [];
|
||
8 years ago
|
|
||
2 years ago
|
if (e.dataTransfer && e.dataTransfer.files.length >= 1 && this.props.canUploadMore && this.context.identity.signedIn) {
|
||
8 years ago
|
this.props.dispatch(uploadCompose(e.dataTransfer.files));
|
||
|
}
|
||
2 years ago
|
};
|
||
8 years ago
|
|
||
8 years ago
|
handleDragLeave = (e) => {
|
||
8 years ago
|
e.preventDefault();
|
||
|
e.stopPropagation();
|
||
|
|
||
|
this.dragTargets = this.dragTargets.filter(el => el !== e.target && this.node.contains(el));
|
||
|
|
||
|
if (this.dragTargets.length > 0) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
8 years ago
|
this.setState({ draggingOver: false });
|
||
2 years ago
|
};
|
||
8 years ago
|
|
||
6 years ago
|
dataTransferIsText = (dataTransfer) => {
|
||
5 years ago
|
return (dataTransfer && Array.from(dataTransfer.types).filter((type) => type === 'text/plain').length === 1);
|
||
2 years ago
|
};
|
||
6 years ago
|
|
||
8 years ago
|
closeUploadModal = () => {
|
||
8 years ago
|
this.setState({ draggingOver: false });
|
||
2 years ago
|
};
|
||
8 years ago
|
|
||
7 years ago
|
handleServiceWorkerPostMessage = ({ data }) => {
|
||
|
if (data.type === 'navigate') {
|
||
6 years ago
|
this.props.history.push(data.path);
|
||
7 years ago
|
} else {
|
||
7 years ago
|
console.warn('Unknown message type:', data.type);
|
||
7 years ago
|
}
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
6 years ago
|
handleVisibilityChange = () => {
|
||
|
const visibility = !document[this.visibilityHiddenProp];
|
||
|
this.props.dispatch(notificationsSetVisibility(visibility));
|
||
4 years ago
|
if (visibility) {
|
||
4 years ago
|
this.props.dispatch(submitMarkers({ immediate: true }));
|
||
4 years ago
|
}
|
||
2 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
handleLayoutChange = debounce(() => {
|
||
|
this.props.dispatch(clearHeight()); // The cached heights are no longer accurate, invalidate
|
||
|
}, 500, {
|
||
|
trailing: true,
|
||
|
});
|
||
|
|
||
|
handleResize = () => {
|
||
|
const layout = layoutFromWindow(this.props.layout_local_setting);
|
||
|
|
||
|
if (layout !== this.props.layout) {
|
||
|
this.handleLayoutChange.cancel();
|
||
|
this.props.dispatch(changeLayout(layout));
|
||
|
} else {
|
||
|
this.handleLayoutChange();
|
||
|
}
|
||
2 years ago
|
};
|
||
4 years ago
|
|
||
|
componentDidMount () {
|
||
2 years ago
|
const { signedIn } = this.context.identity;
|
||
|
|
||
7 years ago
|
window.addEventListener('beforeunload', this.handleBeforeUnload, false);
|
||
4 years ago
|
window.addEventListener('resize', this.handleResize, { passive: true });
|
||
|
|
||
8 years ago
|
document.addEventListener('dragenter', this.handleDragEnter, false);
|
||
|
document.addEventListener('dragover', this.handleDragOver, false);
|
||
|
document.addEventListener('drop', this.handleDrop, false);
|
||
|
document.addEventListener('dragleave', this.handleDragLeave, false);
|
||
8 years ago
|
document.addEventListener('dragend', this.handleDragEnd, false);
|
||
8 years ago
|
|
||
7 years ago
|
if ('serviceWorker' in navigator) {
|
||
|
navigator.serviceWorker.addEventListener('message', this.handleServiceWorkerPostMessage);
|
||
|
}
|
||
|
|
||
2 years ago
|
this.favicon = new Favico({ animation:'none' });
|
||
6 years ago
|
|
||
4 years ago
|
// On first launch, redirect to the follow recommendations page
|
||
2 years ago
|
if (signedIn && this.props.firstLaunch) {
|
||
4 years ago
|
this.context.router.history.replace('/start');
|
||
|
this.props.dispatch(closeOnboarding());
|
||
|
}
|
||
|
|
||
2 years ago
|
if (signedIn) {
|
||
|
this.props.dispatch(fetchMarkers());
|
||
|
this.props.dispatch(expandHomeTimeline());
|
||
|
this.props.dispatch(expandNotifications());
|
||
2 years ago
|
|
||
2 years ago
|
setTimeout(() => this.props.dispatch(fetchServer()), 3000);
|
||
2 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
this.hotkeys.__mousetrap__.stopCallback = (e, element) => {
|
||
4 years ago
|
return ['TEXTAREA', 'SELECT', 'INPUT'].includes(element.tagName);
|
||
7 years ago
|
};
|
||
4 years ago
|
|
||
|
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();
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
componentWillReceiveProps (nextProps) {
|
||
|
if (nextProps.layout_local_setting !== this.props.layout_local_setting) {
|
||
|
const layout = layoutFromWindow(nextProps.layout_local_setting);
|
||
|
|
||
|
if (layout !== this.props.layout) {
|
||
|
this.handleLayoutChange.cancel();
|
||
|
this.props.dispatch(changeLayout(layout));
|
||
|
} else {
|
||
|
this.handleLayoutChange();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
componentDidUpdate (prevProps) {
|
||
6 years ago
|
if (this.props.unreadNotifications != prevProps.unreadNotifications ||
|
||
|
this.props.showFaviconBadge != prevProps.showFaviconBadge) {
|
||
6 years ago
|
if (this.favicon) {
|
||
5 years ago
|
try {
|
||
|
this.favicon.badge(this.props.showFaviconBadge ? this.props.unreadNotifications : 0);
|
||
|
} catch (err) {
|
||
|
console.error(err);
|
||
|
}
|
||
6 years ago
|
}
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
8 years ago
|
componentWillUnmount () {
|
||
6 years ago
|
if (this.visibilityChange !== undefined) {
|
||
|
document.removeEventListener(this.visibilityChange, this.handleVisibilityChange);
|
||
|
}
|
||
|
|
||
7 years ago
|
window.removeEventListener('beforeunload', this.handleBeforeUnload);
|
||
4 years ago
|
window.removeEventListener('resize', this.handleResize);
|
||
|
|
||
8 years ago
|
document.removeEventListener('dragenter', this.handleDragEnter);
|
||
|
document.removeEventListener('dragover', this.handleDragOver);
|
||
|
document.removeEventListener('drop', this.handleDrop);
|
||
|
document.removeEventListener('dragleave', this.handleDragLeave);
|
||
8 years ago
|
document.removeEventListener('dragend', this.handleDragEnd);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
setRef = c => {
|
||
8 years ago
|
this.node = c;
|
||
2 years ago
|
};
|
||
8 years ago
|
|
||
7 years ago
|
handleHotkeyNew = e => {
|
||
|
e.preventDefault();
|
||
|
|
||
6 years ago
|
const element = this.node.querySelector('.compose-form__autosuggest-wrapper textarea');
|
||
7 years ago
|
|
||
|
if (element) {
|
||
|
element.focus();
|
||
|
}
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHotkeySearch = e => {
|
||
|
e.preventDefault();
|
||
|
|
||
5 years ago
|
const element = this.node.querySelector('.search__input');
|
||
7 years ago
|
|
||
|
if (element) {
|
||
|
element.focus();
|
||
|
}
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHotkeyForceNew = e => {
|
||
|
this.handleHotkeyNew(e);
|
||
|
this.props.dispatch(resetCompose());
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
5 years ago
|
handleHotkeyToggleComposeSpoilers = e => {
|
||
|
e.preventDefault();
|
||
|
this.props.dispatch(changeComposeSpoilerness());
|
||
2 years ago
|
};
|
||
5 years ago
|
|
||
7 years ago
|
handleHotkeyFocusColumn = e => {
|
||
|
const index = (e.key * 1) + 1; // First child is drawer, skip that
|
||
|
const column = this.node.querySelector(`.column:nth-child(${index})`);
|
||
6 years ago
|
if (!column) return;
|
||
|
const container = column.querySelector('.scrollable');
|
||
7 years ago
|
|
||
6 years ago
|
if (container) {
|
||
|
const status = container.querySelector('.focusable');
|
||
7 years ago
|
|
||
|
if (status) {
|
||
6 years ago
|
if (container.scrollTop > status.offsetTop) {
|
||
|
status.scrollIntoView(true);
|
||
|
}
|
||
7 years ago
|
status.focus();
|
||
|
}
|
||
|
}
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHotkeyBack = () => {
|
||
7 years ago
|
// if history is exhausted, or we would leave mastodon, just go to root.
|
||
|
if (window.history.state) {
|
||
6 years ago
|
this.props.history.goBack();
|
||
7 years ago
|
} else {
|
||
6 years ago
|
this.props.history.push('/');
|
||
7 years ago
|
}
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
setHotkeysRef = c => {
|
||
|
this.hotkeys = c;
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
7 years ago
|
handleHotkeyToggleHelp = () => {
|
||
|
if (this.props.location.pathname === '/keyboard-shortcuts') {
|
||
6 years ago
|
this.props.history.goBack();
|
||
7 years ago
|
} else {
|
||
6 years ago
|
this.props.history.push('/keyboard-shortcuts');
|
||
7 years ago
|
}
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
7 years ago
|
handleHotkeyGoToHome = () => {
|
||
3 years ago
|
this.props.history.push('/home');
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHotkeyGoToNotifications = () => {
|
||
6 years ago
|
this.props.history.push('/notifications');
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHotkeyGoToLocal = () => {
|
||
3 years ago
|
this.props.history.push('/public/local');
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHotkeyGoToFederated = () => {
|
||
3 years ago
|
this.props.history.push('/public');
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
7 years ago
|
handleHotkeyGoToDirect = () => {
|
||
3 years ago
|
this.props.history.push('/conversations');
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
7 years ago
|
handleHotkeyGoToStart = () => {
|
||
6 years ago
|
this.props.history.push('/getting-started');
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHotkeyGoToFavourites = () => {
|
||
6 years ago
|
this.props.history.push('/favourites');
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHotkeyGoToPinned = () => {
|
||
6 years ago
|
this.props.history.push('/pinned');
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHotkeyGoToProfile = () => {
|
||
3 years ago
|
this.props.history.push(`/@${this.props.username}`);
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHotkeyGoToBlocked = () => {
|
||
6 years ago
|
this.props.history.push('/blocks');
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHotkeyGoToMuted = () => {
|
||
6 years ago
|
this.props.history.push('/mutes');
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
6 years ago
|
handleHotkeyGoToRequests = () => {
|
||
|
this.props.history.push('/follow_requests');
|
||
2 years ago
|
};
|
||
6 years ago
|
|
||
8 years ago
|
render () {
|
||
5 years ago
|
const { draggingOver } = this.state;
|
||
4 years ago
|
const { children, isWide, navbarUnder, location, dropdownMenuIsOpen, layout, moved } = this.props;
|
||
8 years ago
|
|
||
8 years ago
|
const columnsClass = layout => {
|
||
|
switch (layout) {
|
||
|
case 'single':
|
||
|
return 'single-column';
|
||
|
case 'multiple':
|
||
8 years ago
|
return 'multi-columns';
|
||
8 years ago
|
default:
|
||
|
return 'auto-columns';
|
||
|
}
|
||
8 years ago
|
};
|
||
8 years ago
|
|
||
7 years ago
|
const className = classNames('ui', columnsClass(layout), {
|
||
|
'wide': isWide,
|
||
7 years ago
|
'system-font': this.props.systemFontUi,
|
||
7 years ago
|
'navbar-under': navbarUnder,
|
||
6 years ago
|
'hicolor-privacy-icons': this.props.hicolorPrivacyIcons,
|
||
7 years ago
|
});
|
||
8 years ago
|
|
||
7 years ago
|
const handlers = {
|
||
7 years ago
|
help: this.handleHotkeyToggleHelp,
|
||
7 years ago
|
new: this.handleHotkeyNew,
|
||
|
search: this.handleHotkeySearch,
|
||
|
forceNew: this.handleHotkeyForceNew,
|
||
5 years ago
|
toggleComposeSpoilers: this.handleHotkeyToggleComposeSpoilers,
|
||
7 years ago
|
focusColumn: this.handleHotkeyFocusColumn,
|
||
|
back: this.handleHotkeyBack,
|
||
|
goToHome: this.handleHotkeyGoToHome,
|
||
|
goToNotifications: this.handleHotkeyGoToNotifications,
|
||
|
goToLocal: this.handleHotkeyGoToLocal,
|
||
|
goToFederated: this.handleHotkeyGoToFederated,
|
||
7 years ago
|
goToDirect: this.handleHotkeyGoToDirect,
|
||
7 years ago
|
goToStart: this.handleHotkeyGoToStart,
|
||
|
goToFavourites: this.handleHotkeyGoToFavourites,
|
||
|
goToPinned: this.handleHotkeyGoToPinned,
|
||
|
goToProfile: this.handleHotkeyGoToProfile,
|
||
|
goToBlocked: this.handleHotkeyGoToBlocked,
|
||
|
goToMuted: this.handleHotkeyGoToMuted,
|
||
6 years ago
|
goToRequests: this.handleHotkeyGoToRequests,
|
||
7 years ago
|
};
|
||
|
|
||
8 years ago
|
return (
|
||
6 years ago
|
<HotKeys keyMap={keyMap} handlers={handlers} ref={this.setHotkeysRef} attach={window} focused>
|
||
7 years ago
|
<div className={className} ref={this.setRef} style={{ pointerEvents: dropdownMenuIsOpen ? 'none' : null }}>
|
||
5 years ago
|
{moved && (<div className='flash-message alert'>
|
||
5 years ago
|
<FormattedMessage
|
||
|
id='moved_to_warning'
|
||
|
defaultMessage='This account is marked as moved to {moved_to_link}, and may thus not accept new follows.'
|
||
|
values={{ moved_to_link: (
|
||
3 years ago
|
<PermaLink href={moved.get('url')} to={`/@${moved.get('acct')}`}>
|
||
5 years ago
|
@{moved.get('acct')}
|
||
|
</PermaLink>
|
||
2 years ago
|
) }}
|
||
5 years ago
|
/>
|
||
5 years ago
|
</div>)}
|
||
2 years ago
|
|
||
|
<Header />
|
||
|
|
||
4 years ago
|
<SwitchingColumnsArea location={location} mobile={layout === 'mobile' || layout === 'single-column'} navbarUnder={navbarUnder}>
|
||
5 years ago
|
{children}
|
||
|
</SwitchingColumnsArea>
|
||
7 years ago
|
|
||
4 years ago
|
{layout !== 'mobile' && <PictureInPicture />}
|
||
7 years ago
|
<NotificationsContainer />
|
||
|
<LoadingBarContainer className='loading-bar' />
|
||
|
<ModalContainer />
|
||
|
<UploadArea active={draggingOver} onClose={this.closeUploadModal} />
|
||
|
</div>
|
||
|
</HotKeys>
|
||
8 years ago
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|