Skip to content

Commit

Permalink
reverted back the draft click navigation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat-Dabade committed Dec 11, 2024
1 parent cd93248 commit 8965394
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 144 deletions.
42 changes: 2 additions & 40 deletions app/actions/local/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ import {queryDisplayNamePreferences} from '@queries/servers/preference';
import {prepareCommonSystemValues, type PrepareCommonSystemValuesArgs, getCommonSystemValues, getCurrentTeamId, setCurrentChannelId, getCurrentUserId, getConfig, getLicense} from '@queries/servers/system';
import {addChannelToTeamHistory, addTeamToTeamHistory, getTeamById, removeChannelFromTeamHistory} from '@queries/servers/team';
import {getCurrentUser, queryUsersById} from '@queries/servers/user';
import {dismissAllModals, dismissAllModalsAndPopToRoot, dismissAllModalsAndPopToScreen, getThemeFromState, resetToRootAndAddScreenOnTop} from '@screens/navigation';
import {dismissAllModalsAndPopToRoot, dismissAllModalsAndPopToScreen} from '@screens/navigation';
import EphemeralStore from '@store/ephemeral_store';
import {isTablet} from '@utils/helpers';
import {logError, logInfo} from '@utils/log';
import {changeOpacity} from '@utils/theme';
import {displayGroupMessageName, displayUsername, getUserIdFromChannelName} from '@utils/user';

import type {Model} from '@nozbe/watermelondb';
import type ChannelModel from '@typings/database/models/servers/channel';
import type UserModel from '@typings/database/models/servers/user';

export async function switchToChannel(serverUrl: string, channelId: string, teamId?: string, skipLastUnread = false, prepareRecordsOnly = false, isNavigatedFromDraft = false) {
export async function switchToChannel(serverUrl: string, channelId: string, teamId?: string, skipLastUnread = false, prepareRecordsOnly = false) {
try {
const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
let models: Model[] = [];
Expand Down Expand Up @@ -89,43 +88,6 @@ export async function switchToChannel(serverUrl: string, channelId: string, team
if (isTabletDevice) {
dismissAllModalsAndPopToRoot();
DeviceEventEmitter.emit(NavigationConstants.NAVIGATION_HOME, Screens.CHANNEL);
} else if (isNavigatedFromDraft) {
const theme = getThemeFromState();
const options = {
layout: {
componentBackgroundColor: theme.centerChannelBg,
},
popGesture: true,
sideMenu: {
left: {enabled: false},
right: {enabled: false},
},
topBar: {
animate: true,
visible: false,
backButton: {
color: theme.sidebarHeaderTextColor,
title: '',
testID: 'screen.back.button',
},
background: {
color: theme.sidebarBg,
},
title: {
color: theme.sidebarHeaderTextColor,
},
subtitle: {
color: changeOpacity(EphemeralStore.theme!.sidebarHeaderTextColor, 0.72),
},
noBorder: true,
scrollEdgeAppearance: {
noBorder: true,
active: true,
},
},
};
dismissAllModals();
resetToRootAndAddScreenOnTop(Screens.CHANNEL, {}, options);
} else {
dismissAllModalsAndPopToScreen(Screens.CHANNEL, '', undefined, {topBar: {visible: false}});
}
Expand Down
49 changes: 5 additions & 44 deletions app/actions/local/thread.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import merge from 'deepmerge';
import {DeviceEventEmitter} from 'react-native';
import tinycolor from 'tinycolor2';

import {ActionType, General, Navigation, Screens} from '@constants';
import DatabaseManager from '@database/manager';
Expand All @@ -14,15 +12,14 @@ import {getCurrentTeamId, getCurrentUserId, prepareCommonSystemValues, type Prep
import {addChannelToTeamHistory, addTeamToTeamHistory} from '@queries/servers/team';
import {getThreadById, prepareThreadsFromReceivedPosts, queryThreadsInTeam} from '@queries/servers/thread';
import {getCurrentUser} from '@queries/servers/user';
import {dismissAllModals, dismissAllModalsAndPopToRoot, dismissAllOverlays, getThemeFromState, goToScreen, resetToRootAndAddScreenOnTop} from '@screens/navigation';
import {dismissAllModals, dismissAllModalsAndPopToRoot, dismissAllOverlays, goToScreen} from '@screens/navigation';
import EphemeralStore from '@store/ephemeral_store';
import NavigationStore from '@store/navigation_store';
import {isTablet} from '@utils/helpers';
import {logError} from '@utils/log';
import {changeOpacity} from '@utils/theme';

import type Model from '@nozbe/watermelondb/Model';
import type {Options} from 'react-native-navigation';

export const switchToGlobalThreads = async (serverUrl: string, teamId?: string, prepareRecordsOnly = false) => {
try {
Expand Down Expand Up @@ -60,7 +57,7 @@ export const switchToGlobalThreads = async (serverUrl: string, teamId?: string,
}
};

export const switchToThread = async (serverUrl: string, rootId: string, isFromNotification = false, isNavigatedFromDraft = false) => {
export const switchToThread = async (serverUrl: string, rootId: string, isFromNotification = false) => {
try {
const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
const user = await getCurrentUser(database);
Expand Down Expand Up @@ -125,7 +122,8 @@ export const switchToThread = async (serverUrl: string, rootId: string, isFromNo
subtitle = translations[t('thread.header.thread_in')] || 'in {channelName}';
subtitle = subtitle.replace('{channelName}', channel.displayName);
}
const threadOptions = {

goToScreen(Screens.THREAD, '', {rootId}, {
topBar: {
title: {
text: title,
Expand All @@ -140,44 +138,7 @@ export const switchToThread = async (serverUrl: string, rootId: string, isFromNo
active: true,
},
},
};
if (isNavigatedFromDraft && !isTabletDevice) {
const theme = getThemeFromState();
const isDark = tinycolor(theme.sidebarBg).isDark();
const defaultOptions: Options = {
layout: {
componentBackgroundColor: theme.centerChannelBg,
},
popGesture: true,
sideMenu: {
left: {enabled: false},
right: {enabled: false},
},
statusBar: {
style: isDark ? 'light' : 'dark',
},
topBar: {
animate: true,
visible: true,
backButton: {
color: theme.sidebarHeaderTextColor,
title: '',
testID: 'screen.back.button',
},
background: {
color: theme.sidebarBg,
},
title: {
color: theme.sidebarHeaderTextColor,
text: title,
},
},
};
resetToRootAndAddScreenOnTop(Screens.THREAD, {rootId}, merge(defaultOptions, threadOptions));
return {};
}

goToScreen(Screens.THREAD, '', {rootId}, threadOptions);
});

return {};
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions app/actions/remote/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ export async function getChannelTimezones(serverUrl: string, channelId: string)
}
}

export async function switchToChannelById(serverUrl: string, channelId: string, teamId?: string, skipLastUnread = false, isNavigatedFromDraft = false) {
export async function switchToChannelById(serverUrl: string, channelId: string, teamId?: string, skipLastUnread = false) {
if (channelId === Screens.GLOBAL_THREADS) {
return switchToGlobalThreads(serverUrl, teamId);
}
Expand All @@ -1053,7 +1053,7 @@ export async function switchToChannelById(serverUrl: string, channelId: string,

fetchPostsForChannel(serverUrl, channelId);
fetchChannelBookmarks(serverUrl, channelId);
await switchToChannel(serverUrl, channelId, teamId, skipLastUnread, false, isNavigatedFromDraft);
await switchToChannel(serverUrl, channelId, teamId, skipLastUnread, false);
openChannelIfNeeded(serverUrl, channelId);
markChannelAsRead(serverUrl, channelId);
fetchChannelStats(serverUrl, channelId);
Expand Down
4 changes: 2 additions & 2 deletions app/components/draft/draft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ const Draft: React.FC<Props> = ({

const onPress = useCallback(() => {
if (draft.rootId) {
switchToThread(serverUrl, draft.rootId, false, true);
switchToThread(serverUrl, draft.rootId, false);
return;
}
switchToChannelById(serverUrl, channel.id, channel.teamId, false, true);
switchToChannelById(serverUrl, channel.id, channel.teamId, false);
}, [channel.id, channel.teamId, draft.rootId, serverUrl]);

return (
Expand Down
4 changes: 2 additions & 2 deletions app/screens/draft_options/edit_draft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ const EditDraft: React.FC<Props> = ({
const editHandler = async () => {
await dismissBottomSheet(bottomSheetId);
if (rootId) {
switchToThread(serverUrl, rootId, false, true);
switchToThread(serverUrl, rootId, false);
return;
}
switchToChannelById(serverUrl, channel.id, channel.teamId, false, true);
switchToChannelById(serverUrl, channel.id, channel.teamId, false);
};

return (
Expand Down
54 changes: 0 additions & 54 deletions app/screens/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,60 +313,6 @@ export function resetToHome(passProps: LaunchProps = {launchType: Launch.Normal}
});
}

export function resetToRootAndAddScreenOnTop(availableScreen: AvailableScreens, passProps = {}, options: Options = {}) {
const theme = getDefaultThemeByAppearance();
const isDark = tinyColor(theme.sidebarBg).isDark();
StatusBar.setBarStyle(isDark ? 'light-content' : 'dark-content');

const rootStack = {
stack: {
children: [{
component: {
id: Screens.HOME,
name: Screens.HOME,
options: {
layout: {
backgroundColor: theme.centerChannelBg,
componentBackgroundColor: theme.centerChannelBg,
},
statusBar: {
visible: true,
backgroundColor: theme.sidebarBg,
},
topBar: {
visible: false,
height: 0,
background: {
color: theme.sidebarBg,
},
backButton: {
visible: false,
color: theme.sidebarHeaderTextColor,
},
},
},
},
},
{
component: {
id: availableScreen,
name: availableScreen,
passProps: {
...passProps,
theme,
},
options,
},
},
],
},
};

Navigation.setRoot({
root: rootStack,
});
}

export function resetToSelectServer(passProps: LaunchProps) {
const theme = getDefaultThemeByAppearance();
const isDark = tinyColor(theme.sidebarBg).isDark();
Expand Down

0 comments on commit 8965394

Please sign in to comment.