fix(app): improve UX for nested sidebars (#50)
This commit is contained in:
@@ -24,6 +24,7 @@ class SettingsSidebarStore {
|
||||
ownerId: string | null = null;
|
||||
overrideContent: React.ReactNode | null = null;
|
||||
useOverride = false;
|
||||
dismissedOwnerId: string | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this, {overrideContent: observable.ref}, {autoBind: true});
|
||||
@@ -36,7 +37,8 @@ class SettingsSidebarStore {
|
||||
setOverride(ownerId: string, content: React.ReactNode, options?: {defaultOn?: boolean}): void {
|
||||
this.ownerId = ownerId;
|
||||
this.overrideContent = content;
|
||||
if (options?.defaultOn) this.useOverride = true;
|
||||
this.dismissedOwnerId = null;
|
||||
this.useOverride = options?.defaultOn ?? false;
|
||||
}
|
||||
|
||||
updateOverride(ownerId: string, content: React.ReactNode): void {
|
||||
@@ -48,16 +50,40 @@ class SettingsSidebarStore {
|
||||
if (ownerId && this.ownerId && this.ownerId !== ownerId) return;
|
||||
this.ownerId = null;
|
||||
this.overrideContent = null;
|
||||
this.dismissedOwnerId = null;
|
||||
this.useOverride = false;
|
||||
}
|
||||
|
||||
dismissOverride(ownerId?: string): void {
|
||||
if (ownerId && this.ownerId && this.ownerId !== ownerId) return;
|
||||
const targetOwnerId = ownerId ?? this.ownerId;
|
||||
this.useOverride = false;
|
||||
this.dismissedOwnerId = targetOwnerId;
|
||||
}
|
||||
|
||||
setUseOverride(value: boolean): void {
|
||||
if (!this.hasOverride) {
|
||||
this.useOverride = false;
|
||||
return;
|
||||
}
|
||||
if (value) {
|
||||
this.dismissedOwnerId = null;
|
||||
}
|
||||
this.useOverride = value;
|
||||
}
|
||||
|
||||
activateOverride(ownerId?: string): void {
|
||||
if (!this.hasOverride) return;
|
||||
if (ownerId && this.ownerId && this.ownerId !== ownerId) return;
|
||||
this.useOverride = true;
|
||||
this.dismissedOwnerId = null;
|
||||
}
|
||||
|
||||
isDismissed(ownerId?: string): boolean {
|
||||
if (!this.dismissedOwnerId) return false;
|
||||
if (!ownerId) return this.ownerId === this.dismissedOwnerId;
|
||||
return ownerId === this.dismissedOwnerId;
|
||||
}
|
||||
}
|
||||
|
||||
export default new SettingsSidebarStore();
|
||||
|
||||
Reference in New Issue
Block a user