Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Refactor for readability and add tests for logo display logic #65

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 26 additions & 38 deletions javascripts/discourse/components/brand-header-contents.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,68 @@ export default class BrandHeaderContents extends Component {
@service site;

get shouldShow() {
return !this.site.mobileView || settings.show_bar_on_mobile;
return this.site.desktopView || settings.show_bar_on_mobile;
}

get brandLogo() {
const mobileView = this.site.mobileView;
const mobileLogoUrl = settings.mobile_logo_url || "";
const showMobileLogo = mobileView && mobileLogoUrl.length > 0;
const logoUrl = settings.logo_url || "";
const logoDarkUrl = settings.logo_dark_url || "";
const title = settings.brand_name;

return {
mobileUrl: showMobileLogo ? mobileLogoUrl : null,
lightImg: {
url: logoUrl,
},
darkImg: {
url: logoDarkUrl,
},
title,
};
get mobileLogoUrl() {
return this.site.mobileView ? settings.mobile_logo_url : null;
}

get hasIcons() {
return settings.icons && settings.icons.length > 0;
get lightLogo() {
return { url: settings.logo_url || "" };
}

get hasLinks() {
return settings.links && settings.links.length > 0;
get darkLogo() {
return { url: settings.logo_dark_url || "" };
}

<template>
<div class="title">
<a href={{settings.website_url}}>
{{#if this.brandLogo.mobileUrl}}
{{#if this.mobileLogoUrl}}
<img
id="brand-logo"
class="logo-big"
src={{this.brandLogo.mobileUrl}}
title={{this.brandLogo.title}}
src={{this.mobileLogoUrl}}
title={{settings.brand_name}}
/>
{{else}}
{{else if this.lightLogo.url}}
<LightDarkImg
id="brand-logo"
class="logo-big"
@lightImg={{this.brandLogo.lightImg}}
@darkImg={{this.brandLogo.darkImg}}
title={{this.brandLogo.title}}
@lightImg={{this.lightLogo}}
@darkImg={{this.darkLogo}}
title={{settings.brand_name}}
/>
{{else}}
<h2 id="brand-text-logo" class="text-logo">
{{settings.brand_name}}
</h2>
{{/if}}
</a>
</div>

{{#if this.hasLinks}}
{{#if settings.links}}
<nav class="links">
<ul class="nav {{if this.shouldShow 'nav-pills'}}">
{{#each settings.links as |tl|}}
{{#each settings.links as |link|}}
<li>
<a href={{tl.url}} target={{tl.target}}>
{{tl.text}}
<a href={{link.url}} target={{link.target}}>
{{link.text}}
</a>
</li>
{{/each}}
</ul>
</nav>
{{/if}}

{{#if this.hasIcons}}
{{#if settings.icons}}
<div class="panel">
<ul class="icons">
{{#each settings.icons as |il|}}
{{#each settings.icons as |iconLink|}}
<li>
<a href={{il.url}} target={{il.target}}>
{{dIcon il.icon_name}}
<a href={{iconLink.url}} target={{iconLink.target}}>
{{dIcon iconLink.icon_name}}
</a>
</li>
{{/each}}
Expand Down
18 changes: 18 additions & 0 deletions spec/system/viewing_brand_header_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,22 @@
'a[href="http://some.url.com/some-pencil-link"][target="_blank"] .d-icon-pencil',
)
end

it "shows the brand name when no logo is uploaded" do
theme.update_setting(:brand_name, "some name")
theme.save!

visit("/")

expect(page).to have_css("#brand-text-logo", text: "some name")
end

it "does not show the brand name when a logo is uploaded" do
theme.update_setting(:logo_url, "http://example.com/logo.png")
theme.save!

visit("/")

expect(page).to have_css('img#brand-logo[src="http://example.com/logo.png"]', visible: :all)
end
end
Loading