Hello I'm trying to store UI preference based on User, irrespective of browser or device, it should store the preference of user globally, I tried with Javascript's localstorage function but it is browser specific, so it didn't fulfill the requirement
I read about custom settings also but not sure how it can be implemented in my scenario as I'm using lightning-combobox and want to store last selected option and use on relogin/login on other browser. If someone can guide on this, It will be really helpful.
here's my Component -
import { LightningElement, track } from 'lwc';
export default class TreatmentPlan extends LightningElement {
@track showTBTTreatment = false;
@track showTreatment = false;
@track selectedOption;
//selectedOption = 'Treatment';
connectedCallback(){
const lastUsedOption = localStorage.getItem('lastUsedOption');
if (lastUsedOption == 'Treatment') {
this.showTBTTreatment = false;
this.showTreatment = true;
}
else{
this.showTBTTreatment = true;
this.showTreatment = false;
}
this.selectedOption = lastUsedOption;
}
get options() {
return [
{ label: 'Treatment', value: 'Treatment' },
{ label: 'TBT Treatment', value: 'TBT Treatment' },
];
}
saveLastUsedOption(selectedOption) {
localStorage.setItem('lastUsedOption', selectedOption);
}
handleTreatmentChange(event){
console.log('event value', event.target.value);
this.selectedOption = event.target.value;
this.saveLastUsedOption(this.selectedOption);
// this.selectedOption = event.target.value;
// this.saveLastUsedOption(this.selectedOption);
if(event.target.value == 'Treatment'){
this.showTBTTreatment = false;
this.showTreatment = true;
}
else if(event.target.value == 'TBT Treatment'){
this.showTBTTreatment = true;
this.showTreatment = false;
}
// this.setTreatmentFlag();
}
saveLastUsedOption(selectedOption) {
localStorage.setItem('lastUsedOption', selectedOption);
}
}
<template>
<div style="width:15%;">
<lightning-combobox
name="Treatment"
value={selectedOption}
placeholder="Select Treatment Plan"
options={options}
onchange={handleTreatmentChange} >
</lightning-combobox>
</div>
<template if:true={showTBTTreatment}>
<c-tbt-Client-Session-Container-V3 ></c-tbt-Client-Session-Container-V3>
</template>
<template if:true={showTreatment}>
<c-TBT-Client-Treatment-Container-V3></c-TBT-Client-Treatment-Container-V3>
</template>
</template>