From f2e68438d4ca49a363faee11f12f6e5638d2855d Mon Sep 17 00:00:00 2001 From: borys_krutskykh Date: Mon, 26 Feb 2024 21:29:14 +0200 Subject: [PATCH] https://jira.epam.com/jira/browse/EPMUII-8315 - in progress --- src/engine/lib/services/LocalStorageService.ts | 9 +++++++++ src/ui/LeftToolbar/ModeSwitcherToolbar.jsx | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/engine/lib/services/LocalStorageService.ts b/src/engine/lib/services/LocalStorageService.ts index 167521c5..0d324df4 100644 --- a/src/engine/lib/services/LocalStorageService.ts +++ b/src/engine/lib/services/LocalStorageService.ts @@ -1,5 +1,6 @@ export class MRILocalStorageService { RECENT_FILES_KEY: string = 'recentFiles'; + VIEW_MODE_KEY: string = 'viewMode'; constructor() { this.saveRecentFiles = this.saveRecentFiles.bind(this); @@ -22,6 +23,14 @@ export class MRILocalStorageService { this.localStorage.setItem(key, JSON.stringify(data)); } + saveViewMode(viewMode: string): void { + this.setData(this.VIEW_MODE_KEY, viewMode); + } + + getViewMode(): string { + return this.getData(this.VIEW_MODE_KEY) || ''; + } + saveRecentFiles(fileName: string): void { const recentFiles = this.getData(this.RECENT_FILES_KEY); const limitedRecentFiles = recentFiles.slice(0, 2); diff --git a/src/ui/LeftToolbar/ModeSwitcherToolbar.jsx b/src/ui/LeftToolbar/ModeSwitcherToolbar.jsx index e1cb92bb..6b200a31 100644 --- a/src/ui/LeftToolbar/ModeSwitcherToolbar.jsx +++ b/src/ui/LeftToolbar/ModeSwitcherToolbar.jsx @@ -2,7 +2,7 @@ * Copyright 2022 EPAM Systems, Inc. (https://www.epam.com/) * SPDX-License-Identifier: Apache-2.0 */ -import React from 'react'; +import React, { useEffect } from 'react'; import { Tooltip } from '../Tooltip/Tooltip'; import { UIButton } from '../Button/Button'; import { Container } from '../Layout/Container'; @@ -10,6 +10,7 @@ import { useDispatch, useSelector } from 'react-redux'; import StoreActionType from '../../store/ActionTypes'; import ViewMode from '../../store/ViewMode'; import { useNeedShow3d } from '../../utils/useNeedShow3d'; +import { mriLocalStorageService } from '../../engine/lib/services'; export function ModeSwitcherToolbar() { const dispatch = useDispatch(); @@ -19,8 +20,16 @@ export function ModeSwitcherToolbar() { const setMode = (indexMode) => { dispatch({ type: StoreActionType.SET_MODE_VIEW, viewMode: indexMode }); + mriLocalStorageService.saveViewMode(indexMode); }; + useEffect(() => { + const savedMode = mriLocalStorageService.getViewMode(); + if (savedMode) { + setMode(savedMode); + } + }, []); + const set2dMode = () => { setMode(ViewMode.VIEW_2D); };