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

[EPMUII-8315]. Make it possible to set default rendering mode #204

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading