[IMPROVEMENT] Use reselect (#1696)

This commit is contained in:
Diego Mello 2020-02-11 11:09:14 -03:00 committed by GitHub
parent b87472f10b
commit 3683b8936a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 111 additions and 141 deletions

View File

@ -17,7 +17,7 @@ export default class EmojiKeyboard extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
const state = store.getState(); const state = store.getState();
this.baseUrl = state.settings.Site_Url || state.server ? state.server.server : ''; this.baseUrl = state.server.server;
} }
onEmojiSelected = (emoji) => { onEmojiSelected = (emoji) => {

View File

@ -92,7 +92,7 @@ ReplyPreview.propTypes = {
const mapStateToProps = state => ({ const mapStateToProps = state => ({
useMarkdown: state.markdown.useMarkdown, useMarkdown: state.markdown.useMarkdown,
Message_TimeFormat: state.settings.Message_TimeFormat, Message_TimeFormat: state.settings.Message_TimeFormat,
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '' baseUrl: state.server.server
}); });
export default connect(mapStateToProps)(ReplyPreview); export default connect(mapStateToProps)(ReplyPreview);

View File

@ -44,6 +44,7 @@ import {
} from './constants'; } from './constants';
import CommandsPreview from './CommandsPreview'; import CommandsPreview from './CommandsPreview';
import { Review } from '../../utils/review'; import { Review } from '../../utils/review';
import { getUserSelector } from '../../selectors/login';
const imagePickerConfig = { const imagePickerConfig = {
cropping: true, cropping: true,
@ -881,13 +882,9 @@ class MessageBox extends Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
threadsEnabled: state.settings.Threads_enabled, threadsEnabled: state.settings.Threads_enabled,
user: { user: getUserSelector(state),
id: state.login.user && state.login.user.id,
username: state.login.user && state.login.user.username,
token: state.login.user && state.login.user.token
},
FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList, FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList,
FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize
}); });

View File

@ -28,13 +28,9 @@ export async function cancelUpload(item) {
export function sendFileMessage(rid, fileInfo, tmid, server, user) { export function sendFileMessage(rid, fileInfo, tmid, server, user) {
return new Promise(async(resolve, reject) => { return new Promise(async(resolve, reject) => {
try { try {
const serversDB = database.servers;
const serversCollection = serversDB.collections.get('servers');
const serverInfo = await serversCollection.find(server);
const { id: Site_Url } = serverInfo;
const { id, token } = user; const { id, token } = user;
const uploadUrl = `${ Site_Url }/api/v1/rooms.upload/${ rid }`; const uploadUrl = `${ server }/api/v1/rooms.upload/${ rid }`;
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
const formData = new FormData(); const formData = new FormData();

View File

@ -16,6 +16,7 @@ import { removeNotification as removeNotificationAction } from '../../actions/no
import sharedStyles from '../../views/Styles'; import sharedStyles from '../../views/Styles';
import { ROW_HEIGHT } from '../../presentation/RoomItem'; import { ROW_HEIGHT } from '../../presentation/RoomItem';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { getUserSelector } from '../../selectors/login';
const AVATAR_SIZE = 48; const AVATAR_SIZE = 48;
const ANIMATION_DURATION = 300; const ANIMATION_DURATION = 300;
@ -72,8 +73,7 @@ class NotificationBadge extends React.Component {
static propTypes = { static propTypes = {
navigation: PropTypes.object, navigation: PropTypes.object,
baseUrl: PropTypes.string, baseUrl: PropTypes.string,
token: PropTypes.string, user: PropTypes.object,
userId: PropTypes.string,
notification: PropTypes.object, notification: PropTypes.object,
window: PropTypes.object, window: PropTypes.object,
removeNotification: PropTypes.func, removeNotification: PropTypes.func,
@ -173,7 +173,7 @@ class NotificationBadge extends React.Component {
render() { render() {
const { const {
baseUrl, token, userId, notification, window, theme baseUrl, user: { id: userId, token }, notification, window, theme
} = this.props; } = this.props;
const { message, payload } = notification; const { message, payload } = notification;
const { type } = payload; const { type } = payload;
@ -227,9 +227,8 @@ class NotificationBadge extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
userId: state.login.user && state.login.user.id, user: getUserSelector(state),
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
token: state.login.user && state.login.user.token,
notification: state.notification notification: state.notification
}); });

8
app/selectors/login.js Normal file
View File

@ -0,0 +1,8 @@
import { createSelector } from 'reselect';
const getUser = state => state.login.user || {};
export const getUserSelector = createSelector(
[getUser],
user => user
);

View File

@ -11,6 +11,7 @@ import styles from '../Styles';
import { themedHeader } from '../../utils/navigation'; import { themedHeader } from '../../utils/navigation';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import { getUserSelector } from '../../selectors/login';
class AdminPanelView extends React.Component { class AdminPanelView extends React.Component {
static navigationOptions = ({ navigation, screenProps }) => ({ static navigationOptions = ({ navigation, screenProps }) => ({
@ -21,12 +22,12 @@ class AdminPanelView extends React.Component {
static propTypes = { static propTypes = {
baseUrl: PropTypes.string, baseUrl: PropTypes.string,
authToken: PropTypes.string, token: PropTypes.string,
theme: PropTypes.string theme: PropTypes.string
} }
render() { render() {
const { baseUrl, authToken, theme } = this.props; const { baseUrl, token, theme } = this.props;
if (!baseUrl) { if (!baseUrl) {
return null; return null;
} }
@ -35,7 +36,7 @@ class AdminPanelView extends React.Component {
<StatusBar theme={theme} /> <StatusBar theme={theme} />
<WebView <WebView
source={{ uri: `${ baseUrl }/admin/info?layout=embedded` }} source={{ uri: `${ baseUrl }/admin/info?layout=embedded` }}
injectedJavaScript={`Meteor.loginWithToken('${ authToken }', function() { })`} injectedJavaScript={`Meteor.loginWithToken('${ token }', function() { })`}
/> />
</SafeAreaView> </SafeAreaView>
); );
@ -43,8 +44,8 @@ class AdminPanelView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
authToken: state.login.user && state.login.user.token token: getUserSelector(state).token
}); });
export default connect(mapStateToProps)(withTheme(AdminPanelView)); export default connect(mapStateToProps)(withTheme(AdminPanelView));

View File

@ -19,6 +19,7 @@ import { formatAttachmentUrl } from '../lib/utils';
import RCActivityIndicator from '../containers/ActivityIndicator'; import RCActivityIndicator from '../containers/ActivityIndicator';
import { SaveButton, CloseModalButton } from '../containers/HeaderButton'; import { SaveButton, CloseModalButton } from '../containers/HeaderButton';
import { isAndroid } from '../utils/deviceInfo'; import { isAndroid } from '../utils/deviceInfo';
import { getUserSelector } from '../selectors/login';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
@ -142,11 +143,8 @@ class AttachmentView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
user: { user: getUserSelector(state)
id: state.login.user && state.login.user.id,
token: state.login.user && state.login.user.token
}
}); });
export default connect(mapStateToProps)(withTheme(AttachmentView)); export default connect(mapStateToProps)(withTheme(AttachmentView));

View File

@ -23,6 +23,7 @@ import { SWITCH_TRACK_COLOR, themes } from '../constants/colors';
import { withTheme } from '../theme'; import { withTheme } from '../theme';
import { themedHeader } from '../utils/navigation'; import { themedHeader } from '../utils/navigation';
import { Review } from '../utils/review'; import { Review } from '../utils/review';
import { getUserSelector } from '../selectors/login';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
@ -365,16 +366,13 @@ class CreateChannelView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
error: state.createChannel.error, error: state.createChannel.error,
failure: state.createChannel.failure, failure: state.createChannel.failure,
isFetching: state.createChannel.isFetching, isFetching: state.createChannel.isFetching,
result: state.createChannel.result, result: state.createChannel.result,
users: state.selectedUsers.users, users: state.selectedUsers.users,
user: { user: getUserSelector(state)
id: state.login.user && state.login.user.id,
token: state.login.user && state.login.user.token
}
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({

View File

@ -23,6 +23,7 @@ import { withTheme } from '../../theme';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import styles from './styles'; import styles from './styles';
import { themedHeader } from '../../utils/navigation'; import { themedHeader } from '../../utils/navigation';
import { getUserSelector } from '../../selectors/login';
class DirectoryView extends React.Component { class DirectoryView extends React.Component {
static navigationOptions = ({ navigation, screenProps }) => { static navigationOptions = ({ navigation, screenProps }) => {
@ -253,11 +254,8 @@ class DirectoryView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
user: { user: getUserSelector(state),
id: state.login.user && state.login.user.id,
token: state.login.user && state.login.user.token
},
isFederationEnabled: state.settings.FEDERATION_Enabled isFederationEnabled: state.settings.FEDERATION_Enabled
}); });

View File

@ -18,6 +18,7 @@ import Separator from '../../containers/Separator';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { themedHeader } from '../../utils/navigation'; import { themedHeader } from '../../utils/navigation';
import { getUserSelector } from '../../selectors/login';
const LANGUAGES = [ const LANGUAGES = [
{ {
@ -185,7 +186,7 @@ class LanguageView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
userLanguage: state.login.user && state.login.user.language userLanguage: getUserSelector(state).language
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({

View File

@ -17,6 +17,7 @@ import { themes } from '../../constants/colors';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { withSplit } from '../../split'; import { withSplit } from '../../split';
import { themedHeader } from '../../utils/navigation'; import { themedHeader } from '../../utils/navigation';
import { getUserSelector } from '../../selectors/login';
const ACTION_INDEX = 0; const ACTION_INDEX = 0;
const CANCEL_INDEX = 1; const CANCEL_INDEX = 1;
@ -306,12 +307,8 @@ class MessagesView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
user: { user: getUserSelector(state),
id: state.login.user && state.login.user.id,
username: state.login.user && state.login.user.username,
token: state.login.user && state.login.user.token
},
customEmojis: state.customEmojis customEmojis: state.customEmojis
}); });

View File

@ -23,6 +23,7 @@ import StatusBar from '../containers/StatusBar';
import { themes } from '../constants/colors'; import { themes } from '../constants/colors';
import { withTheme } from '../theme'; import { withTheme } from '../theme';
import { themedHeader } from '../utils/navigation'; import { themedHeader } from '../utils/navigation';
import { getUserSelector } from '../selectors/login';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
safeAreaView: { safeAreaView: {
@ -227,11 +228,8 @@ class NewMessageView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
user: { user: getUserSelector(state)
id: state.login.user && state.login.user.id,
token: state.login.user && state.login.user.token
}
}); });
export default connect(mapStateToProps)(withTheme(NewMessageView)); export default connect(mapStateToProps)(withTheme(NewMessageView));

View File

@ -31,6 +31,7 @@ import StatusBar from '../../containers/StatusBar';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { themedHeader } from '../../utils/navigation'; import { themedHeader } from '../../utils/navigation';
import { getUserSelector } from '../../selectors/login';
class ProfileView extends React.Component { class ProfileView extends React.Component {
static navigationOptions = ({ navigation, screenProps }) => ({ static navigationOptions = ({ navigation, screenProps }) => ({
@ -497,16 +498,9 @@ class ProfileView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
user: { user: getUserSelector(state),
id: state.login.user && state.login.user.id,
name: state.login.user && state.login.user.name,
username: state.login.user && state.login.user.username,
customFields: state.login.user && state.login.user.customFields,
emails: state.login.user && state.login.user.emails,
token: state.login.user && state.login.user.token
},
Accounts_CustomFields: state.settings.Accounts_CustomFields, Accounts_CustomFields: state.settings.Accounts_CustomFields,
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '' baseUrl: state.server.server
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({

View File

@ -15,6 +15,7 @@ import StatusBar from '../../containers/StatusBar';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { themedHeader } from '../../utils/navigation'; import { themedHeader } from '../../utils/navigation';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import { getUserSelector } from '../../selectors/login';
class ReadReceiptView extends React.Component { class ReadReceiptView extends React.Component {
static navigationOptions = ({ screenProps }) => ({ static navigationOptions = ({ screenProps }) => ({
@ -26,8 +27,7 @@ class ReadReceiptView extends React.Component {
navigation: PropTypes.object, navigation: PropTypes.object,
Message_TimeFormat: PropTypes.string, Message_TimeFormat: PropTypes.string,
baseUrl: PropTypes.string, baseUrl: PropTypes.string,
userId: PropTypes.string, user: PropTypes.object,
token: PropTypes.string,
theme: PropTypes.string theme: PropTypes.string
} }
@ -92,7 +92,7 @@ class ReadReceiptView extends React.Component {
renderItem = ({ item }) => { renderItem = ({ item }) => {
const { const {
Message_TimeFormat, userId, baseUrl, token, theme Message_TimeFormat, user: { id: userId, token }, baseUrl, theme
} = this.props; } = this.props;
const time = moment(item.ts).format(Message_TimeFormat); const time = moment(item.ts).format(Message_TimeFormat);
return ( return (
@ -167,9 +167,8 @@ class ReadReceiptView extends React.Component {
const mapStateToProps = state => ({ const mapStateToProps = state => ({
Message_TimeFormat: state.settings.Message_TimeFormat, Message_TimeFormat: state.settings.Message_TimeFormat,
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
userId: state.login.user && state.login.user.id, user: getUserSelector(state)
token: state.login.user && state.login.user.token
}); });
export default connect(mapStateToProps)(withTheme(ReadReceiptView)); export default connect(mapStateToProps)(withTheme(ReadReceiptView));

View File

@ -24,6 +24,7 @@ import { themes } from '../../constants/colors';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { themedHeader } from '../../utils/navigation'; import { themedHeader } from '../../utils/navigation';
import { CloseModalButton } from '../../containers/HeaderButton'; import { CloseModalButton } from '../../containers/HeaderButton';
import { getUserSelector } from '../../selectors/login';
class RoomActionsView extends React.Component { class RoomActionsView extends React.Component {
static navigationOptions = ({ navigation, screenProps }) => { static navigationOptions = ({ navigation, screenProps }) => {
@ -523,11 +524,8 @@ class RoomActionsView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
user: { user: getUserSelector(state),
id: state.login.user && state.login.user.id, baseUrl: state.server.server,
token: state.login.user && state.login.user.token
},
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '',
jitsiEnabled: state.settings.Jitsi_Enabled || false jitsiEnabled: state.settings.Jitsi_Enabled || false
}); });

View File

@ -19,6 +19,7 @@ import log from '../../utils/log';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { themedHeader } from '../../utils/navigation'; import { themedHeader } from '../../utils/navigation';
import { getUserSelector } from '../../selectors/login';
const PERMISSION_EDIT_ROOM = 'edit-room'; const PERMISSION_EDIT_ROOM = 'edit-room';
@ -309,11 +310,8 @@ class RoomInfoView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
user: { user: getUserSelector(state),
id: state.login.user && state.login.user.id,
token: state.login.user && state.login.user.token
},
Message_TimeFormat: state.settings.Message_TimeFormat Message_TimeFormat: state.settings.Message_TimeFormat
}); });

View File

@ -24,6 +24,7 @@ import ActivityIndicator from '../../containers/ActivityIndicator';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { themedHeader } from '../../utils/navigation'; import { themedHeader } from '../../utils/navigation';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import { getUserSelector } from '../../selectors/login';
const PAGE_SIZE = 25; const PAGE_SIZE = 25;
@ -287,11 +288,8 @@ class RoomMembersView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
user: { user: getUserSelector(state)
id: state.login.user && state.login.user.id,
token: state.login.user && state.login.user.token
}
}); });
export default connect(mapStateToProps)(withTheme(RoomMembersView)); export default connect(mapStateToProps)(withTheme(RoomMembersView));

View File

@ -4,6 +4,7 @@ import { connect } from 'react-redux';
import { CustomHeaderButtons, Item } from '../../../containers/HeaderButton'; import { CustomHeaderButtons, Item } from '../../../containers/HeaderButton';
import database from '../../../lib/database'; import database from '../../../lib/database';
import { getUserSelector } from '../../../selectors/login';
class RightButtonsContainer extends React.PureComponent { class RightButtonsContainer extends React.PureComponent {
static propTypes = { static propTypes = {
@ -102,7 +103,7 @@ class RightButtonsContainer extends React.PureComponent {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
userId: state.login.user && state.login.user.id, userId: getUserSelector(state).id,
threadsEnabled: state.settings.Threads_enabled threadsEnabled: state.settings.Threads_enabled
}); });

View File

@ -8,6 +8,7 @@ import Header from './Header';
import RightButtons from './RightButtons'; import RightButtons from './RightButtons';
import { withTheme } from '../../../theme'; import { withTheme } from '../../../theme';
import RoomHeaderLeft from './RoomHeaderLeft'; import RoomHeaderLeft from './RoomHeaderLeft';
import { getUserSelector } from '../../../selectors/login';
class RoomHeaderView extends Component { class RoomHeaderView extends Component {
static propTypes = { static propTypes = {
@ -86,9 +87,9 @@ const mapStateToProps = (state, ownProps) => {
let status; let status;
const { rid, type } = ownProps; const { rid, type } = ownProps;
if (type === 'd') { if (type === 'd') {
if (state.login.user && state.login.user.id) { const user = getUserSelector(state);
const { id: loggedUserId } = state.login.user; if (user.id) {
const userId = rid.replace(loggedUserId, '').trim(); const userId = rid.replace(user.id, '').trim();
status = state.activeUsers[userId]; status = state.activeUsers[userId];
} }
} }

View File

@ -83,7 +83,7 @@ class ReactionPicker extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '' baseUrl: state.server.server
}); });
export default responsive(connect(mapStateToProps)(withSplit(ReactionPicker))); export default responsive(connect(mapStateToProps)(withSplit(ReactionPicker)));

View File

@ -49,6 +49,7 @@ import {
import ModalNavigation from '../../lib/ModalNavigation'; import ModalNavigation from '../../lib/ModalNavigation';
import { Review } from '../../utils/review'; import { Review } from '../../utils/review';
import RoomClass from '../../lib/methods/subscriptions/room'; import RoomClass from '../../lib/methods/subscriptions/room';
import { getUserSelector } from '../../selectors/login';
import { CONTAINER_TYPES } from '../../lib/methods/actions'; import { CONTAINER_TYPES } from '../../lib/methods/actions';
const stateAttrsUpdate = [ const stateAttrsUpdate = [
@ -940,11 +941,7 @@ class RoomView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
user: { user: getUserSelector(state),
id: state.login.user && state.login.user.id,
username: state.login.user && state.login.user.username,
token: state.login.user && state.login.user.token
},
appState: state.app.ready && state.app.foreground ? 'foreground' : 'background', appState: state.app.ready && state.app.foreground ? 'foreground' : 'background',
useRealName: state.settings.UI_Use_Real_Name, useRealName: state.settings.UI_Use_Real_Name,
isAuthenticated: state.login.isAuthenticated, isAuthenticated: state.login.isAuthenticated,
@ -952,7 +949,7 @@ const mapStateToProps = state => ({
Message_TimeFormat: state.settings.Message_TimeFormat, Message_TimeFormat: state.settings.Message_TimeFormat,
useMarkdown: state.markdown.useMarkdown, useMarkdown: state.markdown.useMarkdown,
customEmojis: state.customEmojis, customEmojis: state.customEmojis,
baseUrl: state.settings.baseUrl || state.server ? state.server.server : '', baseUrl: state.server.server,
Message_Read_Receipt_Enabled: state.settings.Message_Read_Receipt_Enabled Message_Read_Receipt_Enabled: state.settings.Message_Read_Receipt_Enabled
}); });

View File

@ -59,6 +59,7 @@ import {
} from '../../commands'; } from '../../commands';
import { MAX_SIDEBAR_WIDTH } from '../../constants/tablet'; import { MAX_SIDEBAR_WIDTH } from '../../constants/tablet';
import { withSplit } from '../../split'; import { withSplit } from '../../split';
import { getUserSelector } from '../../selectors/login';
const SCROLL_OFFSET = 56; const SCROLL_OFFSET = 56;
const INITIAL_NUM_TO_RENDER = isTablet ? 20 : 12; const INITIAL_NUM_TO_RENDER = isTablet ? 20 : 12;
@ -148,10 +149,11 @@ class RoomsListView extends React.Component {
static propTypes = { static propTypes = {
navigation: PropTypes.object, navigation: PropTypes.object,
userId: PropTypes.string, user: PropTypes.shape({
username: PropTypes.string, id: PropTypes.string,
token: PropTypes.string, username: PropTypes.string,
baseUrl: PropTypes.string, token: PropTypes.string
}),
server: PropTypes.string, server: PropTypes.string,
searchText: PropTypes.string, searchText: PropTypes.string,
loadingServer: PropTypes.bool, loadingServer: PropTypes.bool,
@ -700,10 +702,12 @@ class RoomsListView extends React.Component {
const { width } = this.state; const { width } = this.state;
const { const {
userId, user: {
username, id: userId,
token, username,
baseUrl, token
},
server,
StoreLastMessage, StoreLastMessage,
theme, theme,
split split
@ -730,7 +734,7 @@ class RoomsListView extends React.Component {
token={token} token={token}
rid={item.rid} rid={item.rid}
type={item.t} type={item.t}
baseUrl={baseUrl} baseUrl={server}
prid={item.prid} prid={item.prid}
showLastMessage={StoreLastMessage} showLastMessage={StoreLastMessage}
onPress={() => this._onPressItem(item)} onPress={() => this._onPressItem(item)}
@ -815,11 +819,8 @@ class RoomsListView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
userId: state.login.user && state.login.user.id, user: getUserSelector(state),
username: state.login.user && state.login.user.username,
token: state.login.user && state.login.user.token,
server: state.server.server, server: state.server.server,
baseUrl: state.settings.baseUrl || state.server ? state.server.server : '',
searchText: state.rooms.searchText, searchText: state.rooms.searchText,
loadingServer: state.server.loading, loadingServer: state.server.loading,
showServerDropdown: state.rooms.showServerDropdown, showServerDropdown: state.rooms.showServerDropdown,

View File

@ -19,6 +19,7 @@ import log from '../../utils/log';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { themedHeader } from '../../utils/navigation'; import { themedHeader } from '../../utils/navigation';
import { getUserSelector } from '../../selectors/login';
class SearchMessagesView extends React.Component { class SearchMessagesView extends React.Component {
static navigationOptions = ({ screenProps }) => ({ static navigationOptions = ({ screenProps }) => ({
@ -167,12 +168,8 @@ class SearchMessagesView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
user: { user: getUserSelector(state),
id: state.login.user && state.login.user.id,
username: state.login.user && state.login.user.username,
token: state.login.user && state.login.user.token
},
customEmojis: state.customEmojis customEmojis: state.customEmojis
}); });

View File

@ -25,6 +25,7 @@ import { themes } from '../constants/colors';
import { animateNextTransition } from '../utils/layoutAnimation'; import { animateNextTransition } from '../utils/layoutAnimation';
import { withTheme } from '../theme'; import { withTheme } from '../theme';
import { themedHeader } from '../utils/navigation'; import { themedHeader } from '../utils/navigation';
import { getUserSelector } from '../selectors/login';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
safeAreaView: { safeAreaView: {
@ -305,13 +306,10 @@ class SelectedUsersView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
users: state.selectedUsers.users, users: state.selectedUsers.users,
loading: state.selectedUsers.loading, loading: state.selectedUsers.loading,
user: { user: getUserSelector(state)
id: state.login.user && state.login.user.id,
token: state.login.user && state.login.user.token
}
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({

View File

@ -21,6 +21,7 @@ import { themedHeader } from '../utils/navigation';
import { withTheme } from '../theme'; import { withTheme } from '../theme';
import { themes } from '../constants/colors'; import { themes } from '../constants/colors';
import { isTablet } from '../utils/deviceInfo'; import { isTablet } from '../utils/deviceInfo';
import { getUserSelector } from '../selectors/login';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
loginTitle: { loginTitle: {
@ -161,7 +162,7 @@ class SetUsernameView extends React.Component {
const mapStateToProps = state => ({ const mapStateToProps = state => ({
server: state.server.server, server: state.server.server,
token: state.login.user && state.login.user.token token: getUserSelector(state).token
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({

View File

@ -36,6 +36,7 @@ import { LISTENER } from '../../containers/Toast';
import EventEmitter from '../../utils/events'; import EventEmitter from '../../utils/events';
import { appStart as appStartAction } from '../../actions'; import { appStart as appStartAction } from '../../actions';
import { onReviewPress } from '../../utils/review'; import { onReviewPress } from '../../utils/review';
import { getUserSelector } from '../../selectors/login';
const SectionSeparator = React.memo(({ theme }) => ( const SectionSeparator = React.memo(({ theme }) => (
<View <View
@ -364,7 +365,7 @@ class SettingsView extends React.Component {
const mapStateToProps = state => ({ const mapStateToProps = state => ({
server: state.server, server: state.server,
token: state.login.user && state.login.user.token, token: getUserSelector(state).token,
useMarkdown: state.markdown.useMarkdown, useMarkdown: state.markdown.useMarkdown,
allowCrashReport: state.crashReport.allowCrashReport allowCrashReport: state.crashReport.allowCrashReport
}); });

View File

@ -87,7 +87,6 @@ class ShareListView extends React.Component {
static propTypes = { static propTypes = {
navigation: PropTypes.object, navigation: PropTypes.object,
server: PropTypes.string, server: PropTypes.string,
baseUrl: PropTypes.string,
token: PropTypes.string, token: PropTypes.string,
userId: PropTypes.string, userId: PropTypes.string,
theme: PropTypes.string theme: PropTypes.string
@ -301,7 +300,7 @@ class ShareListView extends React.Component {
renderItem = ({ item }) => { renderItem = ({ item }) => {
const { const {
userId, token, baseUrl, theme userId, token, server, theme
} = this.props; } = this.props;
return ( return (
<DirectoryItem <DirectoryItem
@ -310,7 +309,7 @@ class ShareListView extends React.Component {
token token
}} }}
title={this.getRoomTitle(item)} title={this.getRoomTitle(item)}
baseUrl={baseUrl} baseUrl={server}
avatar={this.getRoomTitle(item)} avatar={this.getRoomTitle(item)}
description={ description={
item.t === 'c' item.t === 'c'
@ -464,8 +463,7 @@ class ShareListView extends React.Component {
const mapStateToProps = (({ share }) => ({ const mapStateToProps = (({ share }) => ({
userId: share.user && share.user.id, userId: share.user && share.user.id,
token: share.user && share.user.token, token: share.user && share.user.token,
server: share.server, server: share.server
baseUrl: share ? share.server : ''
})); }));
export default connect(mapStateToProps)(withTheme(ShareListView)); export default connect(mapStateToProps)(withTheme(ShareListView));

View File

@ -48,7 +48,7 @@ class ShareView extends React.Component {
username: PropTypes.string.isRequired, username: PropTypes.string.isRequired,
token: PropTypes.string.isRequired token: PropTypes.string.isRequired
}), }),
baseUrl: PropTypes.string.isRequired server: PropTypes.string
}; };
constructor(props) { constructor(props) {
@ -104,7 +104,7 @@ class ShareView extends React.Component {
sendMediaMessage = async() => { sendMediaMessage = async() => {
const { rid, fileInfo, file } = this.state; const { rid, fileInfo, file } = this.state;
const { baseUrl: server, user } = this.props; const { server, user } = this.props;
const { name, description } = file; const { name, description } = file;
const fileMessage = { const fileMessage = {
name, name,
@ -293,7 +293,7 @@ const mapStateToProps = (({ share }) => ({
username: share.user && share.user.username, username: share.user && share.user.username,
token: share.user && share.user.token token: share.user && share.user.token
}, },
baseUrl: share ? share.server : '' server: share.server
})); }));
export default connect(mapStateToProps)(withTheme(ShareView)); export default connect(mapStateToProps)(withTheme(ShareView));

View File

@ -22,6 +22,7 @@ import database from '../../lib/database';
import { animateNextTransition } from '../../utils/layoutAnimation'; import { animateNextTransition } from '../../utils/layoutAnimation';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { withSplit } from '../../split'; import { withSplit } from '../../split';
import { getUserSelector } from '../../selectors/login';
const keyExtractor = item => item.id; const keyExtractor = item => item.id;
@ -297,15 +298,8 @@ class Sidebar extends Component {
const mapStateToProps = state => ({ const mapStateToProps = state => ({
Site_Name: state.settings.Site_Name, Site_Name: state.settings.Site_Name,
user: { user: getUserSelector(state),
id: state.login.user && state.login.user.id, baseUrl: state.server.server,
language: state.login.user && state.login.user.language,
status: state.login.user && state.login.user.status,
username: state.login.user && state.login.user.username,
token: state.login.user && state.login.user.token,
roles: state.login.user && state.login.user.roles
},
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '',
loadingServer: state.server.loading loadingServer: state.server.loading
}); });

View File

@ -25,6 +25,7 @@ import { themes } from '../../constants/colors';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { themedHeader } from '../../utils/navigation'; import { themedHeader } from '../../utils/navigation';
import ModalNavigation from '../../lib/ModalNavigation'; import ModalNavigation from '../../lib/ModalNavigation';
import { getUserSelector } from '../../selectors/login';
const Separator = React.memo(({ theme }) => <View style={[styles.separator, { backgroundColor: themes[theme].separatorColor }]} />); const Separator = React.memo(({ theme }) => <View style={[styles.separator, { backgroundColor: themes[theme].separatorColor }]} />);
Separator.propTypes = { Separator.propTypes = {
@ -348,12 +349,8 @@ class ThreadMessagesView extends React.Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.server.server,
user: { user: getUserSelector(state),
id: state.login.user && state.login.user.id,
username: state.login.user && state.login.user.username,
token: state.login.user && state.login.user.token
},
useRealName: state.settings.UI_Use_Real_Name, useRealName: state.settings.UI_Use_Real_Name,
customEmojis: state.customEmojis customEmojis: state.customEmojis
}); });

View File

@ -100,6 +100,7 @@
"redux-immutable-state-invariant": "^2.1.0", "redux-immutable-state-invariant": "^2.1.0",
"redux-saga": "1.1.3", "redux-saga": "1.1.3",
"remove-markdown": "^0.3.0", "remove-markdown": "^0.3.0",
"reselect": "^4.0.0",
"rn-extensions-share": "^2.3.10", "rn-extensions-share": "^2.3.10",
"rn-fetch-blob": "0.11.2", "rn-fetch-blob": "0.11.2",
"rn-root-view": "^1.0.3", "rn-root-view": "^1.0.3",

View File

@ -10147,6 +10147,11 @@ requires-port@^1.0.0:
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8= integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
reselect@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.0.0.tgz#f2529830e5d3d0e021408b246a206ef4ea4437f7"
integrity sha512-qUgANli03jjAyGlnbYVAV5vvnOmJnODyABz51RdBN7M4WaVu8mecZWgyQNkG8Yqe3KRGRt0l4K4B3XVEULC4CA==
resize-observer-polyfill@^1.5.1: resize-observer-polyfill@^1.5.1:
version "1.5.1" version "1.5.1"
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464" resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"