-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
176 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { extend } from 'flarum/common/extend'; | ||
import app from 'flarum/forum/app'; | ||
import DiscussionComposer from 'flarum/forum/components/DiscussionComposer'; | ||
|
||
export default function extendDiscussionComposer() { | ||
extend(DiscussionComposer.prototype, 'headerItems', function (items) { | ||
const tags = this.composer.fields.tags; | ||
if (tags === undefined) return; | ||
|
||
const qna = tags.some((t) => t.isQnA()); | ||
|
||
if (!qna) return; | ||
|
||
this.attrs.titlePlaceholder = app.translator.trans('fof-best-answer.forum.composer.titlePlaceholder'); | ||
|
||
if (items.has('discussionTitle')) { | ||
items.setContent( | ||
'discussionTitle', | ||
<h3> | ||
<input | ||
className="FormControl" | ||
bidi={this.title} | ||
placeholder={this.attrs.titlePlaceholder} | ||
disabled={!!this.attrs.disabled} | ||
onkeydown={this.onkeydown.bind(this)} | ||
/> | ||
</h3> | ||
); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import app from 'flarum/forum/app'; | ||
import { extend } from 'flarum/common/extend'; | ||
import DiscussionListState from 'flarum/forum/states/DiscussionListState'; | ||
|
||
export default function extendDiscussionListState() { | ||
extend(DiscussionListState.prototype, 'requestParams', function (params) { | ||
if (app.discussions.bestAnswer) { | ||
const negate = app.discussions.bestAnswer === '2'; | ||
const prepend = negate ? '-' : ''; | ||
|
||
params.filter[`${prepend}solved-discussions`] = true; | ||
|
||
if (params.filter.q) { | ||
params.filter.q += ` ${prepend}is:solved`; | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import app from 'flarum/forum/app'; | ||
import { extend } from 'flarum/common/extend'; | ||
import DiscussionsSearchSource from 'flarum/forum/components/DiscussionsSearchSource'; | ||
|
||
export default function extendDiscussionsSearchSource() { | ||
extend(DiscussionsSearchSource.prototype, 'queryMutators', function (mutators: string[]) { | ||
if (app.forum.attribute<boolean>('solutionSearchEnabled')) { | ||
mutators.push('-is:solved'); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import app from 'flarum/forum/app'; | ||
import { extend } from 'flarum/common/extend'; | ||
import IndexPage from 'flarum/forum/components/IndexPage'; | ||
import Dropdown from 'flarum/common/components/Dropdown'; | ||
import Button from 'flarum/common/components/Button'; | ||
|
||
export default function extendIndexPage() { | ||
extend(IndexPage.prototype, 'sidebarItems', function (items) { | ||
/** @ts-ignore */ | ||
const tag = this.currentTag(); | ||
|
||
if (!tag?.isQnA?.()) return; | ||
|
||
const canStartDiscussion = app.forum.attribute('canStartDiscussion') || !app.session.user; | ||
const cta = items.get('newDiscussion'); | ||
cta.children = app.translator.trans( | ||
canStartDiscussion ? 'fof-best-answer.forum.index.ask_question' : 'fof-best-answer.forum.index.cannot_ask_question' | ||
); | ||
|
||
if (items.has('startDiscussion')) { | ||
items.setContent('startDiscussion', cta); | ||
} | ||
}); | ||
|
||
extend(IndexPage.prototype, 'viewItems', function (items) { | ||
if (!app.forum.attribute('showBestAnswerFilterUi')) { | ||
return; | ||
} | ||
|
||
/** @ts-ignore */ | ||
const tag = this.currentTag(); | ||
|
||
if (!tag?.isQnA?.()) { | ||
if (app.discussions.bestAnswer) { | ||
delete app.discussions.bestAnswer; | ||
app.discussions.refresh(); | ||
} | ||
|
||
return; | ||
} | ||
|
||
const options = ['all', 'solved', 'unsolved']; | ||
|
||
const selected = app.discussions.bestAnswer; | ||
|
||
items.add( | ||
'solved-filter', | ||
Dropdown.component( | ||
{ | ||
buttonClassName: 'Button', | ||
label: app.translator.trans( | ||
`fof-best-answer.forum.filter.${options[selected] || Object.keys(options).map((key) => options[key])[0]}_label` | ||
), | ||
accessibleToggleLabel: app.translator.trans('fof-best-answer.forum.filter.accessible_label'), | ||
}, | ||
Object.keys(options).map((value) => { | ||
const label = options[value]; | ||
const active = (selected || Object.keys(options)[0]) === value; | ||
|
||
return Button.component( | ||
{ | ||
icon: active ? 'fas fa-check' : true, | ||
active: active, | ||
onclick: () => { | ||
app.discussions.bestAnswer = value; | ||
if (value === '0') { | ||
delete app.discussions.bestAnswer; | ||
} | ||
app.discussions.refresh(); | ||
}, | ||
}, | ||
app.translator.trans(`fof-best-answer.forum.filter.${label}_label`) | ||
); | ||
}) | ||
) | ||
); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import app from 'flarum/forum/app'; | ||
import SelectBestAnswerNotification from './components/SelectBestAnswerNotification'; | ||
import addBestAnswerAction from './addBestAnswerAction'; | ||
import addBestAnswerView from './addBestAnswerView'; | ||
import addAnsweredBadge from './addAnsweredBadge'; | ||
import AwardedBestAnswerNotification from './components/AwardedBestAnswerNotification'; | ||
import BestAnswerInDiscussionNotification from './components/BestAnswerInDiscussionNotification'; | ||
import extendNotifications from './extenders/extendNotifications'; | ||
import addBestAnswerCountToUsers from './addBestAnswerCountToUsers'; | ||
import addBestAnswerCountSort from '../common/addBestAnswerCountSort'; | ||
import extendSearch from './extenders/extendSearch'; | ||
import extendDiscussionsSearchSource from './extenders/extendDiscussionSearchSource'; | ||
import extendIndexPage from './extenders/extendIndexPage'; | ||
import extendDiscussionListState from './extenders/extendDiscussionListState'; | ||
import extendDiscussionComposer from './extenders/extendDiscussionComposer'; | ||
|
||
export * from './components'; | ||
|
||
export { default as extend } from './extend'; | ||
|
||
app.initializers.add('fof/best-answer', () => { | ||
app.notificationComponents.selectBestAnswer = SelectBestAnswerNotification; | ||
app.notificationComponents.awardedBestAnswer = AwardedBestAnswerNotification; | ||
app.notificationComponents.bestAnswerInDiscussion = BestAnswerInDiscussionNotification; | ||
|
||
addAnsweredBadge(); | ||
addBestAnswerAction(); | ||
addBestAnswerView(); | ||
addBestAnswerCountToUsers(); | ||
addBestAnswerCountSort(); | ||
|
||
extendNotifications(); | ||
extendSearch(); | ||
extendDiscussionsSearchSource(); | ||
extendIndexPage(); | ||
extendDiscussionListState(); | ||
extendDiscussionComposer(); | ||
}); |