Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVEMENT] Add toggle markdown to settings #907

Merged
merged 2 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/actions/actionsTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ function createRequestTypes(base, types = defaultTypes) {
export const LOGIN = createRequestTypes('LOGIN', [
...defaultTypes,
'SET_SERVICES',
'SET_PREFERENCE',
'SET_SORT_PREFERENCE'
'SET_PREFERENCE'
]);
export const USER = createRequestTypes('USER', ['SET']);
export const ROOMS = createRequestTypes('ROOMS', [
Expand Down Expand Up @@ -67,3 +66,4 @@ export const LOGOUT = 'LOGOUT'; // logout is always success
export const SNIPPETED_MESSAGES = createRequestTypes('SNIPPETED_MESSAGES', ['OPEN', 'READY', 'CLOSE', 'MESSAGES_RECEIVED']);
export const DEEP_LINKING = createRequestTypes('DEEP_LINKING', ['OPEN']);
export const SORT_PREFERENCES = createRequestTypes('SORT_PREFERENCES', ['SET_ALL', 'SET']);
export const TOGGLE_MARKDOWN = 'TOGGLE_MARKDOWN';
8 changes: 8 additions & 0 deletions app/actions/markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as types from './actionsTypes';

export function toggleMarkdown(value) {
return {
type: types.TOGGLE_MARKDOWN,
payload: value
};
}
2 changes: 1 addition & 1 deletion app/containers/message/Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Markdown = React.memo(({
}

if (!useMarkdown) {
return <Text style={styles.text}>{m}</Text>;
return <Text style={styles.text} numberOfLines={numberOfLines}>{m}</Text>;
}

return (
Expand Down
1 change: 0 additions & 1 deletion app/i18n/locales/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ export default {
This_room_is_blocked: 'Dieser Raum ist gesperrt',
This_room_is_read_only: 'Dieser Raum kann nur gelesen werden',
Timezone: 'Zeitzone',
Toggle_Drawer: 'Toggle_Drawer',
topic: 'Thema',
Topic: 'Thema',
Try_again: 'Versuchen Sie es nochmal',
Expand Down
2 changes: 1 addition & 1 deletion app/i18n/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export default {
Email_or_password_field_is_empty: 'Email or password field is empty',
Email: 'Email',
email: 'e-mail',
Enable_markdown: 'Enable markdown',
Enable_notifications: 'Enable notifications',
Everyone_can_access_this_channel: 'Everyone can access this channel',
erasing_room: 'erasing room',
Expand Down Expand Up @@ -328,7 +329,6 @@ export default {
Thread: 'Thread',
Threads: 'Threads',
Timezone: 'Timezone',
Toggle_Drawer: 'Toggle_Drawer',
diegolmello marked this conversation as resolved.
Show resolved Hide resolved
topic: 'topic',
Topic: 'Topic',
Try_again: 'Try again',
Expand Down
1 change: 0 additions & 1 deletion app/i18n/locales/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ export default {
This_room_is_blocked: 'Cette canal est bloquée',
This_room_is_read_only: 'Cette canal est en lecture seule',
Timezone: 'Fuseau horaire',
Toggle_Drawer: 'Toggle_Drawer',
topic: 'sujet',
Topic: 'Sujet',
Try_again: 'Réessayer',
Expand Down
1 change: 1 addition & 0 deletions app/i18n/locales/pt-BR.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default {
Email_or_password_field_is_empty: 'Email ou senha estão vazios',
Email: 'Email',
email: 'e-mail',
Enable_markdown: 'Habilitar markdown',
Enable_notifications: 'Habilitar notificações',
Everyone_can_access_this_channel: 'Todos podem acessar este canal',
Error_uploading: 'Erro subindo',
Expand Down
1 change: 0 additions & 1 deletion app/i18n/locales/pt-PT.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ export default {
This_room_is_blocked: 'Esta sala está bloqueada',
This_room_is_read_only: 'Esta sala é apenas de leitura',
Timezone: 'Fuso Horário',
Toggle_Drawer: 'Toggle_Drawer',
topic: 'tópico',
Topic: 'Tópico',
Try_again: 'Tente novamente',
Expand Down
1 change: 0 additions & 1 deletion app/i18n/locales/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ export default {
This_room_is_blocked: 'Этот канал заблокирован',
This_room_is_read_only: 'Этот канал доступен только для чтения',
Timezone: 'Часовой пояс',
Toggle_Drawer: 'Toggle_Drawer',
topic: 'топик',
Topic: 'Топик',
Try_again: 'Попробуйте еще раз',
Expand Down
1 change: 0 additions & 1 deletion app/i18n/locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ export default {
This_room_is_blocked: '这个房间被锁了',
This_room_is_read_only: '这个房间是只读的',
Timezone: '时区',
Toggle_Drawer: 'Toggle_Drawer',
topic: '主题',
Topic: '主题',
Try_again: '再试一次',
Expand Down
8 changes: 8 additions & 0 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { roomsRequest } from '../actions/rooms';

const TOKEN_KEY = 'reactnativemeteor_usertoken';
const SORT_PREFS_KEY = 'RC_SORT_PREFS_KEY';
export const MARKDOWN_KEY = 'RC_MARKDOWN_KEY';
const returnAnArray = obj => obj || [];
const MIN_ROCKETCHAT_VERSION = '0.70.0';

Expand Down Expand Up @@ -685,6 +686,13 @@ const RocketChat = {
// RC 0.51.0
return this.sdk.methodCall('setAvatarFromService', data, contentType, service);
},
async getUseMarkdown() {
const useMarkdown = await AsyncStorage.getItem(MARKDOWN_KEY);
if (useMarkdown === null) {
return true;
}
return JSON.parse(useMarkdown);
},
async getSortPreferences() {
const prefs = await AsyncStorage.getItem(SORT_PREFS_KEY);
return JSON.parse(prefs);
Expand Down
4 changes: 3 additions & 1 deletion app/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import selectedUsers from './selectedUsers';
import createChannel from './createChannel';
import app from './app';
import sortPreferences from './sortPreferences';
import markdown from './markdown';

export default combineReducers({
settings,
Expand All @@ -20,5 +21,6 @@ export default combineReducers({
createChannel,
app,
rooms,
sortPreferences
sortPreferences,
markdown
});
17 changes: 17 additions & 0 deletions app/reducers/markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { TOGGLE_MARKDOWN } from '../actions/actionsTypes';

const initialState = {
useMarkdown: true
};


export default (state = initialState, action) => {
switch (action.type) {
case TOGGLE_MARKDOWN:
return {
useMarkdown: action.payload
};
default:
return state;
}
};
4 changes: 4 additions & 0 deletions app/sagas/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SplashScreen from 'react-native-splash-screen';
import * as actions from '../actions';
import { selectServerRequest } from '../actions/server';
import { setAllPreferences } from '../actions/sortPreferences';
import { toggleMarkdown } from '../actions/markdown';
import { APP } from '../actions/actionsTypes';
import RocketChat from '../lib/rocketchat';
import log from '../utils/log';
Expand All @@ -21,6 +22,9 @@ const restore = function* restore() {
const sortPreferences = yield RocketChat.getSortPreferences();
yield put(setAllPreferences(sortPreferences));

const useMarkdown = yield RocketChat.getUseMarkdown();
yield put(toggleMarkdown(useMarkdown));

if (!token || !server) {
yield all([
AsyncStorage.removeItem(RocketChat.TOKEN_KEY),
Expand Down
7 changes: 4 additions & 3 deletions app/views/RoomView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { Toast } from '../../utils/info';
isAuthenticated: state.login.isAuthenticated,
Message_GroupingPeriod: state.settings.Message_GroupingPeriod,
Message_TimeFormat: state.settings.Message_TimeFormat,
useMarkdown: state.markdown.useMarkdown,
baseUrl: state.settings.baseUrl || state.server ? state.server.server : ''
}), dispatch => ({
editCancel: () => dispatch(editCancelAction()),
Expand Down Expand Up @@ -120,6 +121,7 @@ export default class RoomView extends LoggedView {
editing: PropTypes.bool,
replying: PropTypes.bool,
baseUrl: PropTypes.string,
useMarkdown: PropTypes.bool,
toggleReactionPicker: PropTypes.func,
actionsShow: PropTypes.func,
editCancel: PropTypes.func,
Expand All @@ -135,7 +137,6 @@ export default class RoomView extends LoggedView {
this.rid = props.navigation.getParam('rid');
this.t = props.navigation.getParam('t');
this.tmid = props.navigation.getParam('tmid');
this.useMarkdown = props.navigation.getParam('useMarkdown', true);
this.rooms = database.objects('subscriptions').filtered('rid = $0', this.rid);
this.state = {
joined: this.rooms.length > 0,
Expand Down Expand Up @@ -504,7 +505,7 @@ export default class RoomView extends LoggedView {
renderItem = (item, previousItem) => {
const { room, lastOpen } = this.state;
const {
user, Message_GroupingPeriod, Message_TimeFormat, useRealName, baseUrl
user, Message_GroupingPeriod, Message_TimeFormat, useRealName, baseUrl, useMarkdown
} = this.props;
let dateSeparator = null;
let showUnreadSeparator = false;
Expand Down Expand Up @@ -545,7 +546,7 @@ export default class RoomView extends LoggedView {
Message_GroupingPeriod={Message_GroupingPeriod}
timeFormat={Message_TimeFormat}
useRealName={useRealName}
useMarkdown={this.useMarkdown}
useMarkdown={useMarkdown}
/>
);

Expand Down
19 changes: 3 additions & 16 deletions app/views/RoomsListView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export default class RoomsListView extends LoggedView {
const cancelSearchingAndroid = navigation.getParam('cancelSearchingAndroid');
const onPressItem = navigation.getParam('onPressItem', () => {});
const initSearchingAndroid = navigation.getParam('initSearchingAndroid', () => {});
const toggleUseMarkdown = navigation.getParam('toggleUseMarkdown', () => {});

return {
headerLeft: (
Expand All @@ -76,7 +75,7 @@ export default class RoomsListView extends LoggedView {
<Item title='cancel' iconName='cross' onPress={cancelSearchingAndroid} />
</CustomHeaderButtons>
)
: <DrawerButton navigation={navigation} testID='rooms-list-view-sidebar' onLongPress={toggleUseMarkdown} />
: <DrawerButton navigation={navigation} testID='rooms-list-view-sidebar' />
),
headerTitle: <RoomsListHeaderView />,
headerRight: (
Expand Down Expand Up @@ -125,7 +124,6 @@ export default class RoomsListView extends LoggedView {
searching: false,
search: [],
loading: true,
useMarkdown: true,
chats: [],
unread: [],
favorites: [],
Expand All @@ -146,8 +144,7 @@ export default class RoomsListView extends LoggedView {
navigation.setParams({
onPressItem: this._onPressItem,
initSearchingAndroid: this.initSearchingAndroid,
cancelSearchingAndroid: this.cancelSearchingAndroid,
toggleUseMarkdown: this.toggleUseMarkdown
cancelSearchingAndroid: this.cancelSearchingAndroid
});
console.timeEnd(`${ this.constructor.name } mount`);
}
Expand Down Expand Up @@ -316,15 +313,6 @@ export default class RoomsListView extends LoggedView {
}
}

// Just for tests purposes
toggleUseMarkdown = () => {
this.setState(({ useMarkdown }) => ({ useMarkdown: !useMarkdown }),
() => {
const { useMarkdown } = this.state;
alert(`Markdown ${ useMarkdown ? 'enabled' : 'disabled' }`);
});
}

// this is necessary during development (enables Cmd + r)
hasActiveDB = () => database && database.databases && database.databases.activeDB;

Expand Down Expand Up @@ -355,10 +343,9 @@ export default class RoomsListView extends LoggedView {

goRoom = (item) => {
this.cancelSearchingAndroid();
const { useMarkdown } = this.state;
const { navigation } = this.props;
navigation.navigate('RoomView', {
rid: item.rid, name: this.getRoomTitle(item), t: item.t, prid: item.prid, useMarkdown
rid: item.rid, name: this.getRoomTitle(item), t: item.t, prid: item.prid
});
}

Expand Down
Loading