fix: show TerminalPost in search results when field sort is active or mostRelevantPost is unavailable
When params.q is set, Flarum core suppresses TerminalPost and only shows an excerpt from mostRelevantPost. This leaves the info section empty when the post is null (e.g. hidden/deleted first post in production) or when results are ordered by a field sort where an excerpt is meaningless. Extend DiscussionListItem.infoItems to: - Replace excerpt with TerminalPost when a field sort (latest, oldest, top) is active — relevance excerpts are not meaningful when sorted by date/count. - Fall back to TerminalPost when no excerpt was added (mostRelevantPost null).
This commit is contained in:
parent
c5643bed31
commit
c55db0abd6
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { extend } from 'flarum/common/extend';
|
||||||
|
import DiscussionListItem from 'flarum/forum/components/DiscussionListItem';
|
||||||
|
import TerminalPost from 'flarum/forum/components/TerminalPost';
|
||||||
|
|
||||||
|
export default function extendDiscussionListItem() {
|
||||||
|
extend(DiscussionListItem.prototype, 'infoItems', function (items) {
|
||||||
|
const params = this.attrs.params;
|
||||||
|
|
||||||
|
if (!params.q) return;
|
||||||
|
|
||||||
|
const hasFieldSort = params.sort && params.sort !== 'relevance';
|
||||||
|
|
||||||
|
if (hasFieldSort) {
|
||||||
|
// Field sort active (latest, oldest, top, …): replace excerpt with TerminalPost.
|
||||||
|
// An excerpt is meaningless when results are ordered by date/count rather than relevance.
|
||||||
|
items.remove('excerpt');
|
||||||
|
if (!items.has('terminalPost')) {
|
||||||
|
items.add('terminalPost', <TerminalPost discussion={this.attrs.discussion} lastPost={!this.showFirstPost()} />);
|
||||||
|
}
|
||||||
|
} else if (!items.has('excerpt')) {
|
||||||
|
// Relevance mode but no excerpt (mostRelevantPost was null or non-comment type).
|
||||||
|
// Fall back to TerminalPost so the info section is never silently empty.
|
||||||
|
items.add('terminalPost', <TerminalPost discussion={this.attrs.discussion} lastPost={true} />);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import ItemList from 'flarum/common/utils/ItemList';
|
||||||
|
|
||||||
import DiscussionsSearchSource from './SearchSources/DiscussionsSearchSource';
|
import DiscussionsSearchSource from './SearchSources/DiscussionsSearchSource';
|
||||||
import extendDiscussionState from './PaginatedListStates/extendDiscussionState';
|
import extendDiscussionState from './PaginatedListStates/extendDiscussionState';
|
||||||
|
import extendDiscussionListItem from './extendDiscussionListItem';
|
||||||
|
|
||||||
app.initializers.add('blomstra-search', () => {
|
app.initializers.add('blomstra-search', () => {
|
||||||
extend(Search.prototype, 'sourceItems', function (this: Search<SearchAttrs>, items: ItemList<SearchSource>) {
|
extend(Search.prototype, 'sourceItems', function (this: Search<SearchAttrs>, items: ItemList<SearchSource>) {
|
||||||
|
|
@ -25,6 +26,7 @@ app.initializers.add(
|
||||||
'blomstra-search-early',
|
'blomstra-search-early',
|
||||||
() => {
|
() => {
|
||||||
extendDiscussionState();
|
extendDiscussionState();
|
||||||
|
extendDiscussionListItem();
|
||||||
},
|
},
|
||||||
999999
|
999999
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue