fix: delete data if top-level data is selected
All checks were successful
Build and Deploy Angular App / build (push) Successful in 2m3s
All checks were successful
Build and Deploy Angular App / build (push) Successful in 2m3s
This commit is contained in:
@ -30,6 +30,7 @@ export interface TabSelectData {
|
||||
})
|
||||
export class TabStorageService {
|
||||
private static dataName = 'tabSelectedData';
|
||||
private _enclosure: string[] = [];
|
||||
|
||||
constructor(private router: Router, private location: Location) {
|
||||
}
|
||||
@ -52,27 +53,18 @@ export class TabStorageService {
|
||||
}, 100);
|
||||
}
|
||||
|
||||
private resetIfNeed(type: TabSelectType) {
|
||||
let selectedData = TabStorageService.selected;
|
||||
|
||||
if (selectedData === null || selectedData?.type === null)
|
||||
return;
|
||||
|
||||
if (selectedData.type !== type) {
|
||||
localStorage.removeItem(TabStorageService.dataName);
|
||||
const currentUrl = this.router.url.split('?')[0];
|
||||
this.location.replaceState(currentUrl);
|
||||
}
|
||||
public set enclosure(data: string[]) {
|
||||
this._enclosure = data;
|
||||
}
|
||||
|
||||
public select(selected: TabSelect, type: TabSelectType, navigateName: string) {
|
||||
this.resetIfNeed(type);
|
||||
let selectedData = TabStorageService.selected;
|
||||
public select(type: TabSelectType, tabSelected: TabSelect[]) {
|
||||
let selectedData = {selected: {}} as TabSelectData;
|
||||
|
||||
if (selectedData === null || !selectedData.selected)
|
||||
selectedData = {selected: {}} as TabSelectData;
|
||||
for (let index = 0; index < this._enclosure.length; index++) {
|
||||
if (tabSelected[index])
|
||||
selectedData.selected[this._enclosure[index]] = tabSelected[index];
|
||||
}
|
||||
|
||||
selectedData.selected[navigateName] = selected;
|
||||
selectedData.type = type;
|
||||
|
||||
localStorage.setItem(TabStorageService.dataName, JSON.stringify(selectedData));
|
||||
|
Reference in New Issue
Block a user