Skip to content

Commit

Permalink
Fix error when viewing post number 1 from user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkwinkelmann committed Feb 16, 2021
1 parent 709928b commit bd26ba8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion js/dist/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/admin.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion js/src/forum/addFieldsOnDiscussionPost.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import {extend} from 'flarum/extend';
import app from 'flarum/app';
import CommentPost from 'flarum/components/CommentPost';
import DiscussionPage from 'flarum/components/DiscussionPage';
import FieldsViewer from './components/FieldsViewer';

function showFieldsOnPost(post) {
// The CommentPost component is also visible on the user profile, but we don't want to render the fields there
if (!app.current.matches(DiscussionPage)) {
return false;
}

// We only add fields to the first post, and only if fields are not displayed in the hero
// TODO: what if the first post is deleted ?
return post.number() === 1 && !app.forum.attribute('fof-mason.fields-in-hero');
Expand All @@ -18,7 +24,7 @@ export default function () {
this.subtree.check(() => {
// Create a string with all answer ids
// If answers change this string will be different
return this.attrs.post.discussion().masonAnswers().map(answer => {
return (this.attrs.post.discussion().masonAnswers() || []).map(answer => {
// Sometimes answer will be undefined while the data is being saved in FieldsEditorModal
if (!answer) {
return '';
Expand Down
2 changes: 1 addition & 1 deletion js/src/forum/components/FieldsViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class FieldsViewer extends Component {

this.fields.forEach(field => {
// Discussion answers to this field
const answers = sortByAttribute(this.discussion.masonAnswers().filter(answer => {
const answers = sortByAttribute((this.discussion.masonAnswers() || []).filter(answer => {
// It's necessary to compare the field() relationship
// Because field.suggested_answers() won't contain new and user answers
return answer.field() && answer.field().id() === field.id();
Expand Down

0 comments on commit bd26ba8

Please sign in to comment.