Skip to content

Commit 849e74c

Browse files
committed
DEV: Check mobileView in dynamic context
Resolves `static-viewport-initialization` deprecation
1 parent bff6d88 commit 849e74c

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

javascripts/discourse/initializers/initialize-for-header-icon-links.gjs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@ export default {
2323
try {
2424
const site = api.container.lookup("service:site");
2525
let links = settings.header_links;
26-
if (site.mobileView) {
27-
links = links.filter(
28-
(link) => link.view === "vmo" || link.view === "vdm"
29-
);
30-
} else {
31-
links = links.filter(
32-
(link) => link.view === "vdo" || link.view === "vdm"
33-
);
34-
}
3526

3627
links.forEach((link, index) => {
28+
const shouldRender = () => {
29+
if (site.mobileView) {
30+
return link.view === "vmo" || link.view === "vdm";
31+
} else {
32+
return link.view === "vdo" || link.view === "vdm";
33+
}
34+
};
35+
3736
const iconTemplate = buildIcon(link.icon, link.title);
3837
const className = `header-icon-${dasherize(link.title)}`;
3938
const target = link.target === "blank" ? "_blank" : "";
@@ -47,25 +46,27 @@ export default {
4746
}
4847

4948
const iconComponent = <template>
50-
<li
51-
class={{concatClass
52-
"custom-header-icon-link"
53-
className
54-
link.view
55-
isLastLink
56-
}}
57-
>
58-
<a
59-
class="btn no-text icon btn-flat"
60-
href={{link.url}}
61-
title={{link.title}}
62-
target={{target}}
63-
rel={{rel}}
64-
style={{style}}
49+
{{#if (shouldRender)}}
50+
<li
51+
class={{concatClass
52+
"custom-header-icon-link"
53+
className
54+
link.view
55+
isLastLink
56+
}}
6557
>
66-
{{iconTemplate}}
67-
</a>
68-
</li>
58+
<a
59+
class="btn no-text icon btn-flat"
60+
href={{link.url}}
61+
title={{link.title}}
62+
target={{target}}
63+
rel={{rel}}
64+
style={{style}}
65+
>
66+
{{iconTemplate}}
67+
</a>
68+
</li>
69+
{{/if}}
6970
</template>;
7071

7172
const beforeIcon = ["chat", "search", "hamburger", "user-menu"];

0 commit comments

Comments
 (0)