Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
borys_krutskykh committed Feb 26, 2024
1 parent 96861ae commit f2e6843
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/engine/lib/services/LocalStorageService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export class MRILocalStorageService {
RECENT_FILES_KEY: string = 'recentFiles';
VIEW_MODE_KEY: string = 'viewMode';

constructor() {
this.saveRecentFiles = this.saveRecentFiles.bind(this);
Expand All @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion src/ui/LeftToolbar/ModeSwitcherToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
* 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';
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();
Expand All @@ -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);
};
Expand Down

0 comments on commit f2e6843

Please sign in to comment.