mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
fix(editor): use persisted state for presentation mode background config (#12293)
Fixed this issue (black background is on but the toggle state is not synced):  Issue source: https://linear.app/affine-design/issue/BS-3448 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - The background color now defaults to non-black for new users or when no previous setting exists. - Improved reliability when restoring user settings. - **New Features** - Changes to the background color setting are now saved and persist between sessions. - **Style** - Enhanced toggle switch responsiveness for background and toolbar settings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -77,18 +77,16 @@ export class EdgelessNavigatorSettingButton extends WithDisposable(LitElement) {
|
|||||||
slots.navigatorSettingUpdated.next({
|
slots.navigatorSettingUpdated.next({
|
||||||
blackBackground: this.blackBackground,
|
blackBackground: this.blackBackground,
|
||||||
});
|
});
|
||||||
|
this.edgeless.std
|
||||||
|
.get(EditPropsStore)
|
||||||
|
.setStorage('presentBlackBackground', checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
private _tryRestoreSettings() {
|
private _tryRestoreSettings() {
|
||||||
const blackBackground = this.edgeless.std
|
const blackBackground = this.edgeless.std
|
||||||
.get(EditPropsStore)
|
.get(EditPropsStore)
|
||||||
.getStorage('presentBlackBackground');
|
.getStorage('presentBlackBackground');
|
||||||
this.blackBackground = blackBackground ?? true;
|
this.blackBackground = blackBackground ?? false;
|
||||||
}
|
|
||||||
|
|
||||||
override connectedCallback() {
|
|
||||||
super.connectedCallback();
|
|
||||||
this._tryRestoreSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override disconnectedCallback(): void {
|
override disconnectedCallback(): void {
|
||||||
@@ -97,6 +95,7 @@ export class EdgelessNavigatorSettingButton extends WithDisposable(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override firstUpdated() {
|
override firstUpdated() {
|
||||||
|
if (this.edgeless) this._tryRestoreSettings();
|
||||||
this._navigatorSettingPopper = createButtonPopper({
|
this._navigatorSettingPopper = createButtonPopper({
|
||||||
reference: this._navigatorSettingButton,
|
reference: this._navigatorSettingButton,
|
||||||
popperElement: this._navigatorSettingMenu,
|
popperElement: this._navigatorSettingMenu,
|
||||||
@@ -133,7 +132,7 @@ export class EdgelessNavigatorSettingButton extends WithDisposable(LitElement) {
|
|||||||
<div class="text">Black background</div>
|
<div class="text">Black background</div>
|
||||||
|
|
||||||
<toggle-switch
|
<toggle-switch
|
||||||
.subscribe=${this.blackBackground}
|
.on=${this.blackBackground}
|
||||||
.onChange=${this._onBlackBackgroundChange}
|
.onChange=${this._onBlackBackgroundChange}
|
||||||
>
|
>
|
||||||
</toggle-switch>
|
</toggle-switch>
|
||||||
@@ -143,7 +142,7 @@ export class EdgelessNavigatorSettingButton extends WithDisposable(LitElement) {
|
|||||||
<div class="text">Hide toolbar</div>
|
<div class="text">Hide toolbar</div>
|
||||||
|
|
||||||
<toggle-switch
|
<toggle-switch
|
||||||
.subscribe=${this.hideToolbar}
|
.on=${this.hideToolbar}
|
||||||
.onChange=${(checked: boolean) => {
|
.onChange=${(checked: boolean) => {
|
||||||
this.onHideToolbarChange && this.onHideToolbarChange(checked);
|
this.onHideToolbarChange && this.onHideToolbarChange(checked);
|
||||||
}}
|
}}
|
||||||
@@ -173,7 +172,7 @@ export class EdgelessNavigatorSettingButton extends WithDisposable(LitElement) {
|
|||||||
private accessor _navigatorSettingMenu!: HTMLElement;
|
private accessor _navigatorSettingMenu!: HTMLElement;
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
accessor blackBackground = true;
|
accessor blackBackground = false;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor edgeless!: BlockComponent;
|
accessor edgeless!: BlockComponent;
|
||||||
|
|||||||
Reference in New Issue
Block a user