Skip to content

Commit

Permalink
Store user preferences in local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
otabek-memphis committed Dec 18, 2023
1 parent 1e26db9 commit 31196a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
26 changes: 25 additions & 1 deletion ui_src/src/components/sdkExample/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import {
LOCAL_STORAGE_ENV,
LOCAL_STORAGE_REST_GW_HOST,
LOCAL_STORAGE_REST_GW_PORT,
LOCAL_STORAGE_USER_PASS_BASED_AUTH
LOCAL_STORAGE_USER_PASS_BASED_AUTH,
LOCAL_STORAGE_PRODUCER_COMMUNICATION_TYPE,
LOCAL_STORAGE_PRODUCER_PROGRAMMING_LANGUAGE,
LOCAL_STORAGE_CONSUMER_COMMUNICATION_TYPE,
LOCAL_STORAGE_CONSUMER_PROGRAMMING_LANGUAGE,
} from '../../const/localStorageConsts';
import GenerateTokenModal from '../../domain/stationOverview/components/generateTokenModal';
import { ReactComponent as NoCodeExampleIcon } from '../../assets/images/noCodeExample.svg';
Expand Down Expand Up @@ -105,6 +109,26 @@ const SdkExample = ({ consumer, showTabs = true, stationName, username, connecti
protocolSelected === 'SDK' ? changeSDKDynamicCode(langSelected) : changeRestDynamicCode(langSelected);
}, [formFields, tabValue]);

useEffect(() => {
const communicationTypeStorage = !consumer ? LOCAL_STORAGE_PRODUCER_COMMUNICATION_TYPE : LOCAL_STORAGE_CONSUMER_COMMUNICATION_TYPE;
const communicationType = localStorage.getItem(communicationTypeStorage);
if (communicationType) setProtocolSelected(communicationType);

const programmingLanguageStorage = !consumer ? LOCAL_STORAGE_PRODUCER_PROGRAMMING_LANGUAGE : LOCAL_STORAGE_CONSUMER_PROGRAMMING_LANGUAGE;
const programmingLanguage = localStorage.getItem(programmingLanguageStorage);
if (programmingLanguage) setLangSelected(programmingLanguage);
}, []);

useEffect(() => {
const communicationType = !consumer ? LOCAL_STORAGE_PRODUCER_COMMUNICATION_TYPE : LOCAL_STORAGE_CONSUMER_COMMUNICATION_TYPE;
localStorage.setItem(communicationType, protocolSelected);
}, [protocolSelected]);

useEffect(() => {
const programmingLanguage = !consumer ? LOCAL_STORAGE_PRODUCER_PROGRAMMING_LANGUAGE : LOCAL_STORAGE_CONSUMER_PROGRAMMING_LANGUAGE;
localStorage.setItem(programmingLanguage, langSelected);
}, [langSelected]);

const updateFormFields = (field, value) => {
setFormFields({ ...formFields, [field]: value });
};
Expand Down
4 changes: 4 additions & 0 deletions ui_src/src/const/localStorageConsts.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ export const LOGS_RETENTION_IN_DAYS = 'logs_retention';
export const TIERED_STORAGE_UPLOAD_INTERVAL = 'tiered_storage_time_sec';
export const USER_IMAGE = 'user_image';
export const LOCAL_STORAGE_FUNCTION_PAGE_VIEW = 'function_page_view';
export const LOCAL_STORAGE_PRODUCER_COMMUNICATION_TYPE = 'producer_communication_type';
export const LOCAL_STORAGE_PRODUCER_PROGRAMMING_LANGUAGE = 'producer_programming_language';
export const LOCAL_STORAGE_CONSUMER_COMMUNICATION_TYPE = 'consumer_communication_type';
export const LOCAL_STORAGE_CONSUMER_PROGRAMMING_LANGUAGE = 'consumer_programming_language';

0 comments on commit 31196a5

Please sign in to comment.