Skip to content

Commit

Permalink
feat(sticky): make excerpt optional in sticky (#4016)
Browse files Browse the repository at this point in the history
  • Loading branch information
lycorisor authored Oct 21, 2024
1 parent b86a4a0 commit a0311df
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
4 changes: 4 additions & 0 deletions extensions/sticky/extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@

new Extend\Locales(__DIR__.'/locale'),

(new Extend\Settings())
->serializeToForum('excerptDisplayEnabled', 'flarum-sticky.enable_display_excerpt', 'boolval')
->default('flarum-sticky.enable_display_excerpt', true),

(new Extend\Model(Discussion::class))
->cast('is_sticky', 'bool'),

Expand Down
25 changes: 18 additions & 7 deletions extensions/sticky/js/src/admin/extend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,22 @@ export default [
'moderate',
95
)
.setting(() => ({
setting: 'flarum-sticky.only_sticky_unread_discussions',
name: 'onlyStickyUnreadDiscussions',
type: 'boolean',
label: app.translator.trans('flarum-sticky.admin.settings.only_sticky_unread_discussions_label'),
help: app.translator.trans('flarum-sticky.admin.settings.only_sticky_unread_discussions_help'),
})),
.setting(
() => ({
setting: 'flarum-sticky.only_sticky_unread_discussions',
name: 'onlyStickyUnreadDiscussions',
type: 'boolean',
label: app.translator.trans('flarum-sticky.admin.settings.only_sticky_unread_discussions_label'),
help: app.translator.trans('flarum-sticky.admin.settings.only_sticky_unread_discussions_help'),
}),
90
)
.setting(
() => ({
type: 'switch',
setting: 'flarum-sticky.enable_display_excerpt',
label: app.translator.trans('flarum-sticky.admin.settings.enable_display_excerpt'),
}),
100
),
];
4 changes: 2 additions & 2 deletions extensions/sticky/js/src/forum/addStickyExcerpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { truncate } from 'flarum/common/utils/string';

export default function addStickyExcerpt() {
extend(DiscussionListState.prototype, 'requestParams', function (params) {
if (app.current.matches(IndexPage) || app.current.matches(DiscussionPage)) {
if (app.forum.attribute('excerptDisplayEnabled') && (app.current.matches(IndexPage) || app.current.matches(DiscussionPage))) {
params.include.push('firstPost');
}
});

extend(DiscussionListItem.prototype, 'infoItems', function (items) {
const discussion = this.attrs.discussion;

if (discussion.isSticky() && !this.attrs.params.q && !discussion.lastReadPostNumber()) {
if (app.forum.attribute('excerptDisplayEnabled') && discussion.isSticky() && !this.attrs.params.q && !discussion.lastReadPostNumber()) {
const firstPost = discussion.firstPost();

if (firstPost) {
Expand Down
1 change: 1 addition & 0 deletions extensions/sticky/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ flarum-sticky:
# Translations in this namespace are used by the admin interface.
admin:
settings:
enable_display_excerpt: Show an excerpt of the first post when a sticky discussion is unread
only_sticky_unread_discussions_label: Only sticky unread discussions
only_sticky_unread_discussions_help: On the All Discussions page, unread sticky discussions pin to the top, while read sticky discussions follow the regular order.

Expand Down

0 comments on commit a0311df

Please sign in to comment.