Proof of concept: viewport-based mobile mode

This commit is contained in:
David Taylor
2025-01-08 15:12:55 +00:00
parent 61450b0947
commit 75e9cbaa0f
4 changed files with 37 additions and 2 deletions

View File

@@ -79,6 +79,7 @@ export default class Site extends RestModel {
}
@service siteSettings;
@service capabilities;
@tracked categories;
@@ -95,6 +96,22 @@ export default class Site extends RestModel {
this.categories = this.categories || [];
}
get desktopView() {
return !this.mobileView;
}
set desktopView(value) {
// Ignore server value
}
get mobileView() {
return this.capabilities.viewportWidth <= 450;
}
set mobileView(value) {
// Ignore server value
}
get useGlimmerTopicList() {
if (this.#glimmerTopicDecision !== undefined) {
// Caches the decision after the first call, and avoids re-printing the same message

View File

@@ -1,9 +1,13 @@
import { tracked } from "@glimmer/tracking";
const APPLE_NAVIGATOR_PLATFORMS = /iPhone|iPod|iPad|Macintosh|MacIntel/;
const APPLE_USER_AGENT_DATA_PLATFORM = /macOS/;
const ua = navigator.userAgent;
class Capabilities {
@tracked viewportWidth;
touch = navigator.maxTouchPoints > 1 || "ontouchstart" in window;
isAndroid = ua.includes("Android");
@@ -46,6 +50,15 @@ class Capabilities {
window.location.search.includes("discourse_app=1");
isAppWebview = window.ReactNativeWebView !== undefined;
constructor() {
this.viewportWidth = window.innerWidth;
window.addEventListener("resize", () => {
if (window.innerWidth !== this.viewportWidth) {
this.viewportWidth = window.innerWidth;
}
});
}
get userHasBeenActive() {
return (
!("userActivation" in navigator) || navigator.userActivation.hasBeenActive

View File

@@ -627,7 +627,11 @@ module ApplicationHelper
stylesheet_manager
end
manager.stylesheet_link_tag(name, "all", self.method(:add_resource_preload_list))
manager.stylesheet_link_tag(
name,
opts[:media] || "all",
self.method(:add_resource_preload_list),
)
end
def discourse_preload_color_scheme_stylesheets

View File

@@ -3,7 +3,8 @@
<%- if rtl? %>
<%= discourse_stylesheet_link_tag(mobile_view? ? :mobile_rtl : :desktop_rtl) %>
<%- else %>
<%= discourse_stylesheet_link_tag(mobile_view? ? :mobile : :desktop) %>
<%= discourse_stylesheet_link_tag(:mobile, { media: "all and (max-width: 450px)" }) %>
<%= discourse_stylesheet_link_tag(:desktop, { media: "all and (min-width: 450px)" }) %>
<%- end %>
<%- if staff? %>