Skip to content

Commit e3d07cb

Browse files
authored
feat: make it easier to add content after the first post (#4050)
1 parent 9bc8c7d commit e3d07cb

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

framework/core/js/src/forum/components/PostStream.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,24 @@ export default class PostStream extends Component {
7878
content = <PostLoading />;
7979
}
8080

81-
return (
81+
const postStreamElement = (
8282
<div className="PostStream-item" {...attrs}>
8383
{content}
8484
</div>
8585
);
86+
87+
// If we're on the first post, call the afterFirstPostItems method and add any additional elements.
88+
if (i === 0 && this.afterFirstPostItems().toArray().length > 0) {
89+
// Using m.fragment to return multiple elements without an enclosing container
90+
return m.fragment({ ...attrs }, [
91+
postStreamElement,
92+
<div className="PostStream-item PostStream-afterFirstPost" key="afterFirstPost">
93+
{this.afterFirstPostItems().toArray()}
94+
</div>,
95+
]);
96+
}
97+
98+
return postStreamElement;
8699
});
87100

88101
if (!viewingEnd && posts[this.stream.visibleEnd - this.stream.visibleStart - 1]) {
@@ -117,6 +130,15 @@ export default class PostStream extends Component {
117130
);
118131
}
119132

133+
/**
134+
* @returns {ItemList<import('mithril').Children>}
135+
*/
136+
afterFirstPostItems() {
137+
const items = new ItemList();
138+
139+
return items;
140+
}
141+
120142
/**
121143
* @returns {ItemList<import('mithril').Children>}
122144
*/

0 commit comments

Comments
 (0)