mirror of
https://github.com/discourse/discourse.git
synced 2025-02-28 21:22:10 +08:00
FIX: Preload user sidebar attrs when ?enable_sidebar=1
(#19843)
This allows users to preview the sidebar even when `SiteSetting.naviation_menu` is set to `false`.
This commit is contained in:
parent
07a1211183
commit
ef57771b08
@ -252,6 +252,11 @@ async function buildFromBootstrap(proxy, baseURL, req, response, preload) {
|
|||||||
url.searchParams.append("safe_mode", reqUrlSafeMode);
|
url.searchParams.append("safe_mode", reqUrlSafeMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const enableSidebar = forUrlSearchParams.get("enable_sidebar");
|
||||||
|
if (enableSidebar) {
|
||||||
|
url.searchParams.append("enable_sidebar", enableSidebar);
|
||||||
|
}
|
||||||
|
|
||||||
const reqUrlPreviewThemeId = forUrlSearchParams.get("preview_theme_id");
|
const reqUrlPreviewThemeId = forUrlSearchParams.get("preview_theme_id");
|
||||||
if (reqUrlPreviewThemeId) {
|
if (reqUrlPreviewThemeId) {
|
||||||
url.searchParams.append("preview_theme_id", reqUrlPreviewThemeId);
|
url.searchParams.append("preview_theme_id", reqUrlPreviewThemeId);
|
||||||
|
@ -640,15 +640,25 @@ class ApplicationController < ActionController::Base
|
|||||||
def preload_current_user_data
|
def preload_current_user_data
|
||||||
store_preloaded(
|
store_preloaded(
|
||||||
"currentUser",
|
"currentUser",
|
||||||
MultiJson.dump(CurrentUserSerializer.new(current_user, scope: guardian, root: false)),
|
MultiJson.dump(
|
||||||
|
CurrentUserSerializer.new(
|
||||||
|
current_user,
|
||||||
|
scope: guardian,
|
||||||
|
root: false,
|
||||||
|
enable_sidebar_param: params[:enable_sidebar],
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
report = TopicTrackingState.report(current_user)
|
report = TopicTrackingState.report(current_user)
|
||||||
|
|
||||||
serializer =
|
serializer =
|
||||||
ActiveModel::ArraySerializer.new(
|
ActiveModel::ArraySerializer.new(
|
||||||
report,
|
report,
|
||||||
each_serializer: TopicTrackingStateSerializer,
|
each_serializer: TopicTrackingStateSerializer,
|
||||||
scope: guardian,
|
scope: guardian,
|
||||||
)
|
)
|
||||||
|
|
||||||
store_preloaded("topicTrackingStates", MultiJson.dump(serializer))
|
store_preloaded("topicTrackingStates", MultiJson.dump(serializer))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,6 +47,6 @@ module UserSidebarMixin
|
|||||||
private
|
private
|
||||||
|
|
||||||
def sidebar_navigation_menu?
|
def sidebar_navigation_menu?
|
||||||
!SiteSetting.legacy_navigation_menu?
|
!SiteSetting.legacy_navigation_menu? || options[:enable_sidebar_param] == "1"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
15
spec/system/page_objects/components/sidebar.rb
Normal file
15
spec/system/page_objects/components/sidebar.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module PageObjects
|
||||||
|
module Components
|
||||||
|
class Sidebar < PageObjects::Components::Base
|
||||||
|
def visible?
|
||||||
|
page.has_css?("#d-sidebar")
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_category_section_link?(category)
|
||||||
|
page.has_link?(category.name, class: "sidebar-section-link")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
22
spec/system/viewing_sidebar_spec.rb
Normal file
22
spec/system/viewing_sidebar_spec.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe "Viewing sidebar", type: :system, js: true do
|
||||||
|
fab!(:admin) { Fabricate(:admin) }
|
||||||
|
fab!(:user) { Fabricate(:user) }
|
||||||
|
fab!(:category_sidebar_section_link) { Fabricate(:category_sidebar_section_link, user: user) }
|
||||||
|
|
||||||
|
describe "when using the legacy navigation menu" do
|
||||||
|
before { SiteSetting.navigation_menu = "legacy" }
|
||||||
|
|
||||||
|
it "should display the sidebar when `enable_sidebar` query param is '1'" do
|
||||||
|
sign_in(user)
|
||||||
|
|
||||||
|
visit("/latest?enable_sidebar=1")
|
||||||
|
|
||||||
|
sidebar = PageObjects::Components::Sidebar.new
|
||||||
|
|
||||||
|
expect(sidebar).to be_visible
|
||||||
|
expect(sidebar).to have_category_section_link(category_sidebar_section_link.linkable)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user