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

Rupato/358/rerender-previous-active-tab-on-reload #8992

23 changes: 23 additions & 0 deletions packages/bot-web-ui/src/components/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import classNames from 'classnames';
import { initTrashCan } from '@deriv/bot-skeleton/src/scratch/hooks/trashcan';
import { DesktopWrapper, Dialog, MobileWrapper, Tabs } from '@deriv/components';
import { isMobile } from '@deriv/shared';
import { useStore } from '@deriv/stores';
import { localize } from '@deriv/translations';
import Chart from 'Components/chart';
import { DBOT_TABS, TAB_IDS } from 'Constants/bot-contents';
Expand Down Expand Up @@ -88,6 +89,28 @@ const Dashboard = ({
let storage = '';
let tour_status: { [key: string]: string };
const is_mobile = isMobile();
const init_render = React.useRef(true);
const { ui } = useStore();
const { url_hashed_values } = ui;

let tab_value = active_tab;
const GetHashedValue = (tab: number) => {
tab_value = Number(url_hashed_values?.split('#')[1]);
if (isNaN(tab_value) || isNaN(tab)) return active_tab;
if (tab_value > 4 || tab > 4) return active_tab;
return tab_value;
};
const active_hash_tab = GetHashedValue(active_tab);

React.useEffect(() => {
if (init_render.current) {
setActiveTab(Number(active_hash_tab));
if (is_mobile) handleTabChange(Number(active_hash_tab));
init_render.current = false;
} else {
window.location.hash = active_tab;
}
}, [active_tab]);

const setTourStatus = (status: { [key: string]: string }) => {
if (status) {
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/Stores/ui-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import BaseStore from './base-store';
const store_name = 'ui_store';

export default class UIStore extends BaseStore {
url_hashed_values = '';
rupato-deriv marked this conversation as resolved.
Show resolved Hide resolved
is_account_settings_visible = false;
is_positions_drawer_on = false;
is_reports_visible = false;
Expand Down Expand Up @@ -317,6 +318,7 @@ export default class UIStore extends BaseStore {
is_mobile: computed,
is_tablet: computed,
is_warning_scam_message_modal_visible: computed,
url_hashed_values: observable,
notifyAppInstall: action.bound,
onChangeUiStore: action.bound,
openAccountNeededModal: action.bound,
Expand All @@ -341,6 +343,7 @@ export default class UIStore extends BaseStore {
setCurrentFocus: action.bound,
setDarkMode: action.bound,
setHasOnlyForwardingContracts: action.bound,
setHashedValue: action.bound,
setIsAcuityModalOpen: action.bound,
setIsClosingCreateRealAccountModal: action.bound,
setIsNativepickerVisible: action.bound,
Expand Down Expand Up @@ -439,7 +442,12 @@ export default class UIStore extends BaseStore {
this.is_new_account = localStorage.getItem('isNewAccount') || false;
}

setHashedValue(url_hashed_values) {
this.url_hashed_values = url_hashed_values;
}

init(notification_messages) {
this.setHashedValue(window.location.hash);
this.notification_messages_ui = notification_messages;
}

Expand Down