DEV: Adds hasNoPreferredMode to chat state manager (#33213)

This commit introduces a new property `hasNoPreferredMode` to the
chat state manager, which represents a user who has not purposely
set chat mode to drawer or full page, meaning they have no LocalStorage
value set.

This can be useful for themes to change the chat mode but only
if the user has no preference already.

c.f.
https://meta.discourse.org/t/full-screen-chat-as-default-for-collaboration-setup/369849
This commit is contained in:
Martin Brennan 2025-06-17 13:22:42 +10:00 committed by GitHub
parent 6ea31d32f0
commit c00c522530
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -148,11 +148,15 @@ export default class ChatStateManager extends Service {
return !!(
!this.isFullPagePreferred ||
(this.site.desktopView &&
(!this._store.getObject(PREFERRED_MODE_KEY) ||
(this.hasNoPreferredMode ||
this._store.getObject(PREFERRED_MODE_KEY) === DRAWER_CHAT))
);
}
get hasNoPreferredMode() {
return !this._store.getObject(PREFERRED_MODE_KEY);
}
get isFullPageActive() {
return this.router.currentRouteName?.startsWith("chat");
}

View File

@ -50,6 +50,18 @@ module(
assert.true(this.subject.isDrawerPreferred);
});
test("hasNoPreferredMode", async function (assert) {
assert.true(this.subject.hasNoPreferredMode);
this.subject.prefersFullPage();
assert.false(this.subject.hasNoPreferredMode);
this.subject.prefersDrawer();
assert.false(this.subject.hasNoPreferredMode);
});
test("lastKnownChatURL", function (assert) {
assert.strictEqual(this.subject.lastKnownChatURL, "/chat");