mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Clean up mobileView/desktopView uses (#26229)
Inspired by a piece of "do not do x if it's not a mobile view" code 🙃
This commit is contained in:
@@ -2,12 +2,13 @@ import Component from "@glimmer/component";
|
||||
import { service } from "@ember/service";
|
||||
import { isPresent } from "@ember/utils";
|
||||
import DButton from "discourse/components/d-button";
|
||||
|
||||
export default class ChatChannelLeaveBtn extends Component {
|
||||
@service chat;
|
||||
@service site;
|
||||
|
||||
get shouldRender() {
|
||||
return !this.site.mobileView && isPresent(this.args.channel);
|
||||
return this.site.desktopView && isPresent(this.args.channel);
|
||||
}
|
||||
|
||||
get leaveChatTitleKey() {
|
||||
|
||||
@@ -40,7 +40,7 @@ export default class ChatHeaderIcon extends Component {
|
||||
if (
|
||||
this.chatStateManager.isFullPageActive &&
|
||||
!this.chatSeparateSidebarMode.never &&
|
||||
!this.site.mobileView
|
||||
this.site.desktopView
|
||||
) {
|
||||
return I18n.t("sidebar.panels.forum.label");
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export default class ChatHeaderIcon extends Component {
|
||||
if (
|
||||
this.chatStateManager.isFullPageActive &&
|
||||
!this.chatSeparateSidebarMode.never &&
|
||||
!this.site.mobileView
|
||||
this.site.desktopView
|
||||
) {
|
||||
return "random";
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ export default class ChatThreadHeader extends Component {
|
||||
route = "chat.channel.threads";
|
||||
title = I18n.t("chat.return_to_threads_list");
|
||||
models = this.channel?.routeModels;
|
||||
} else if (prevPage === "chat.channel.index" && !this.site.mobileView) {
|
||||
} else if (prevPage === "chat.channel.index" && this.site.desktopView) {
|
||||
route = "chat.channel.threads";
|
||||
title = I18n.t("chat.return_to_threads_list");
|
||||
models = this.channel?.routeModels;
|
||||
|
||||
@@ -4,7 +4,6 @@ import KeyValueStore from "discourse/lib/key-value-store";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import { MAIN_PANEL } from "discourse/lib/sidebar/panels";
|
||||
import { defaultHomepage } from "discourse/lib/utilities";
|
||||
import Site from "discourse/models/site";
|
||||
import getURL from "discourse-common/lib/get-url";
|
||||
import { getUserChatSeparateSidebarMode } from "discourse/plugins/chat/discourse/lib/get-user-chat-separate-sidebar-mode";
|
||||
|
||||
@@ -22,10 +21,12 @@ export function addChatDrawerStateCallback(callback) {
|
||||
export function resetChatDrawerStateCallbacks() {
|
||||
chatDrawerStateCallbacks = [];
|
||||
}
|
||||
|
||||
export default class ChatStateManager extends Service {
|
||||
@service chat;
|
||||
@service chatHistory;
|
||||
@service router;
|
||||
@service site;
|
||||
|
||||
@tracked isSidePanelExpanded = false;
|
||||
@tracked isDrawerExpanded = false;
|
||||
@@ -126,7 +127,7 @@ export default class ChatStateManager extends Service {
|
||||
|
||||
get isFullPagePreferred() {
|
||||
return !!(
|
||||
Site.currentProp("mobileView") ||
|
||||
this.site.mobileView ||
|
||||
this._store.getObject(PREFERRED_MODE_KEY) === FULL_PAGE_CHAT
|
||||
);
|
||||
}
|
||||
@@ -134,7 +135,7 @@ export default class ChatStateManager extends Service {
|
||||
get isDrawerPreferred() {
|
||||
return !!(
|
||||
!this.isFullPagePreferred ||
|
||||
(!Site.currentProp("mobileView") &&
|
||||
(this.site.desktopView &&
|
||||
(!this._store.getObject(PREFERRED_MODE_KEY) ||
|
||||
this._store.getObject(PREFERRED_MODE_KEY) === DRAWER_CHAT))
|
||||
);
|
||||
|
||||
@@ -3,7 +3,7 @@ import hbs from "htmlbars-inline-precompile";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import I18n from "discourse-i18n";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
@@ -47,11 +47,11 @@ module("Discourse Chat | Component | chat-channel-leave-btn", function (hooks) {
|
||||
});
|
||||
|
||||
test("is not visible on mobile", async function (assert) {
|
||||
this.site.mobileView = true;
|
||||
this.site.desktopView = false;
|
||||
this.channel = fabricators.channel();
|
||||
|
||||
await render(hbs`<ChatChannelLeaveBtn @channel={{this.channel}} />`);
|
||||
|
||||
assert.false(exists(".chat-channel-leave-btn"));
|
||||
assert.dom(".chat-channel-leave-btn").doesNotExist();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,13 +57,13 @@
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
{{#unless this.site.mobileView}}
|
||||
{{#if this.site.desktopView}}
|
||||
<TimezoneInput
|
||||
@options={{hash icon="globe"}}
|
||||
@value={{this.timezone}}
|
||||
@onChange={{fn (mut this.timezone)}}
|
||||
/>
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<div class="picker-panel">
|
||||
|
||||
Reference in New Issue
Block a user