FEATURE: Add dark mode option for category backgrounds (#24003)

Adds a new upload field for a dark mode category background that will be used as an alternative when Discourse is using a dark mode theme.
This commit is contained in:
Sérgio Saquetim
2023-10-20 09:48:06 -03:00
committed by GitHub
parent e7afd18155
commit 0cfc42e0e6
21 changed files with 228 additions and 20 deletions

View File

@ -29,6 +29,7 @@ class Category < ActiveRecord::Base
belongs_to :uploaded_logo, class_name: "Upload"
belongs_to :uploaded_logo_dark, class_name: "Upload"
belongs_to :uploaded_background, class_name: "Upload"
belongs_to :uploaded_background_dark, class_name: "Upload"
has_many :topics
has_many :category_users
@ -115,8 +116,13 @@ class Category < ActiveRecord::Base
after_save do
if saved_change_to_uploaded_logo_id? || saved_change_to_uploaded_logo_dark_id? ||
saved_change_to_uploaded_background_id?
upload_ids = [self.uploaded_logo_id, self.uploaded_logo_dark_id, self.uploaded_background_id]
saved_change_to_uploaded_background_id? || saved_change_to_uploaded_background_dark_id?
upload_ids = [
self.uploaded_logo_id,
self.uploaded_logo_dark_id,
self.uploaded_background_id,
self.uploaded_background_dark_id,
]
UploadReference.ensure_exist!(upload_ids: upload_ids, target: self)
end
end
@ -1185,6 +1191,7 @@ end
# allow_unlimited_owner_edits_on_first_post :boolean default(FALSE), not null
# default_slow_mode_seconds :integer
# uploaded_logo_dark_id :integer
# uploaded_background_dark_id :integer
#
# Indexes
#

View File

@ -16,6 +16,7 @@ class CategoryList
def self.included_associations
[
:uploaded_background,
:uploaded_background_dark,
:uploaded_logo,
:uploaded_logo_dark,
:topic_only_relative_url,

View File

@ -81,6 +81,7 @@ class Site
:uploaded_logo,
:uploaded_logo_dark,
:uploaded_background,
:uploaded_background_dark,
:tags,
:tag_groups,
:form_templates,