사용자 정의 상태를 더 눈에 띄게 만들기

이것의 변형 버전을 만들어서, 게시자 이름 아래에 사용자 정의 필드를 표시하도록 했습니다. 테마 컴포넌트를 생성하고, JS에는 다음을 사용했습니다:

import Component from "@glimmer/component";
import { withPluginApi } from "discourse/lib/plugin-api";
import { get } from "@ember/object"; // We still need this

// here, add the id of the custom field, prefixed with "user_field_"

// to get the user field id:
// 1. go to admin/config/user-fields
// 2. click on the user field's name
// 3. the user field id is shown in the url after admin/config/user-fields/

const FIELDS_TO_SHOW = [
  { fieldKey: "user_field_2", display: "inline" }, 
  { fieldKey: "user_field_1", display: "block" }   
];
// ----------------------------------------


function addCustomFields(api) {
  
  FIELDS_TO_SHOW.forEach(config => {
    
    api.renderAfterWrapperOutlet(
      "post-meta-data-poster-name",
      class extends Component {
        
        // getter to pass the key to the template
        get currentFieldKey() {
          return config.fieldKey;
        }

        // getter to pass the display type to the template
        get currentDisplayType() {
          return config.display;
        }

        static shouldRender(args) {
          // use config.fieldKey to find the data
          const value = get(args.post.user.custom_fields, config.fieldKey);
          return !!value;
        }

        <template>
          <div class="
            poster-custom-field
            poster-custom-field-{{this.currentDisplayType}}
            field-{{this.currentFieldKey}}
          ">
            {{get @post.user.custom_fields this.currentFieldKey}}
          </div>
        </template>
      }
    );
  });
}


export default {
  name: "show-poster-custom-fields",
  initialize() {
    withPluginApi("1.0.0", (api) => {
      addCustomFields(api);
    });
  }
};

그리고 CSS에는 다음을 사용했습니다:

.topic-meta-data .names {
  flex-wrap: wrap;
  align-items: baseline;
}


// base styles for all custom field display
.poster-custom-field {
  font-size: 0.9em;
  color: var(--primary-high-or-secondary-low);
  flex-shrink: 0;
}

// style for inline display
.poster-custom-field-inline {
  display: inline-block; 
  margin-left: 8px;
  order: 5;
}

.topic-meta-data .names .user-title {
    order: 10;
    flex-basis: 100%;
    width: 100%;
    display: block;
    margin-left: 0;
    margin-top: 2px;
    font-size: 0.9em;
    color: var(--primary-high-or-secondary-low);
}

// style for below the name display
.poster-custom-field-block {
  flex-basis: 100%;
  margin-top: 4px;
  order: 20;
}

실제로 적용하면 아래 이미지와 같습니다. "more stuff"와 "some information"은 두 사용자 정의 필드에 있는 내용입니다.

@NateDhaliwal 님이 말씀하신 대로, this.user.status를 사용하여 사용자 상태가 있는 곳에 제가 사용한 사용자 정의 필드를 대신 표시할 수 있다고 생각합니다.