merge: avoid empty blocks when hiding ads (!828)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/828

Approved-by: Charlotte <timo.herngreen@gmail.com>
Approved-by: Amber Null <puppygirlhornyposting@gmail.com>
This commit is contained in:
dakkar 2024-12-18 17:06:57 +00:00
commit 12ef2b13c4

View file

@ -12,6 +12,7 @@ import * as os from '@/os.js';
import { instance } from '@/instance.js';
import { defaultStore } from '@/store.js';
import { MisskeyEntity } from '@/types/date-separated-list.js';
import { $i } from '@/account.js';
export default defineComponent({
props: {
@ -55,7 +56,7 @@ export default defineComponent({
if (props.items.length === 0) return;
const renderChildrenImpl = () => props.items.map((item, i) => {
const renderChildrenImpl = (shouldHideAds: boolean) => props.items.map((item, i) => {
if (!slots || !slots.default) return;
const el = slots.default({
@ -100,7 +101,7 @@ export default defineComponent({
return [el, separator];
} else {
if (props.ad && instance.ads.length > 0 && item._shouldInsertAd_) {
if (props.ad && instance.ads.length > 0 && item._shouldInsertAd_ && !shouldHideAds) {
return [h('div', {
key: item.id + ':ad',
class: $style['ad-wrapper'],
@ -114,7 +115,9 @@ export default defineComponent({
});
const renderChildren = () => {
const children = renderChildrenImpl();
const shouldHideAds = !defaultStore.state.forceShowAds && $i && $i.policies.canHideAds;
const children = renderChildrenImpl(shouldHideAds);
if (isDebuggerEnabled(6864)) {
const nodes = children.flatMap((node) => node ?? []);
const keys = new Set(nodes.map((node) => node.key));