Skip to content

Commit

Permalink
Preserve profile groups collapse state.
Browse files Browse the repository at this point in the history
use local storage rather than config store
Remove config save and toggleGroupCollapse not to be async
  • Loading branch information
artu-ole committed Mar 29, 2022
1 parent a5282ea commit 6e09931
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
ng-container(*ngFor='let group of profileGroups')
ng-container(*ngIf='isGroupVisible(group)')
.list-group-item.list-group-item-action.d-flex.align-items-center(
(click)='group.collapsed = !group.collapsed'
(click)='toggleGroupCollapse(group)'
)
.fa.fa-fw.fa-chevron-right(*ngIf='group.collapsed')
.fa.fa-fw.fa-chevron-down(*ngIf='!group.collapsed')
Expand Down
16 changes: 13 additions & 3 deletions tabby-settings/src/components/profilesSettingsTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
refresh (): void {
this.profiles = this.config.store.profiles
this.profileGroups = []
const profileGroupCollapsed = JSON.parse(window.localStorage.profileGroupCollapsed ?? '{}')

for (const profile of this.profiles) {
let group = this.profileGroups.find(x => x.name === profile.group)
Expand All @@ -151,7 +152,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
name: profile.group,
profiles: [],
editable: true,
collapsed: false,
collapsed: profileGroupCollapsed[profile.group ?? ''] ?? false,
}
this.profileGroups.push(group)
}
Expand All @@ -160,12 +161,14 @@ export class ProfilesSettingsTabComponent extends BaseComponent {

this.profileGroups.sort((a, b) => a.name?.localeCompare(b.name ?? '') ?? -1)

this.profileGroups.push({
const builtIn = {
name: this.translate.instant('Built-in'),
profiles: this.builtinProfiles,
editable: false,
collapsed: false,
})
}
builtIn.collapsed = profileGroupCollapsed[builtIn.name ?? ''] ?? false
this.profileGroups.push(builtIn)
}

async editGroup (group: ProfileGroup): Promise<void> {
Expand Down Expand Up @@ -246,6 +249,13 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
}[this.profilesService.providerForProfile(profile)?.id ?? ''] ?? 'warning'
}

toggleGroupCollapse (group: ProfileGroup): void {
group.collapsed = !group.collapsed
const profileGroupCollapsed = JSON.parse(window.localStorage.profileGroupCollapsed ?? '{}')
profileGroupCollapsed[group.name ?? ''] = group.collapsed
window.localStorage.profileGroupCollapsed = JSON.stringify(profileGroupCollapsed)
}

async editDefaults (provider: ProfileProvider<Profile>): Promise<void> {
const modal = this.ngbModal.open(
EditProfileModalComponent,
Expand Down

0 comments on commit 6e09931

Please sign in to comment.