모바일에서 카테고리 및 '최신'을 어떻게 볼 수 있나요?

모바일에서 카테고리와 "최신"을 어떻게 볼 수 있나요?

이렇게요?

확인해 보니, “카테고리와 최신 주제” 뷰를 강제하기 위해 커스텀 JS 코드를 사용했습니다.

더 나은 방법이 있는지 확인하지는 않았지만, 그들이 사용하는 방법은 다음과 같습니다 (코드를 현대화하고 몇 가지 주석을 추가했습니다):

import { apiInitializer } from "discourse/lib/api";
import CategoriesAndLatestTopics from "discourse/components/categories-and-latest-topics";
import CategoryList from "discourse/models/category-list";
import { MAX_UNOPTIMIZED_CATEGORIES } from "discourse/lib/constants";

export default apiInitializer((api) => {
  // "카테고리와 최신 주제" 뷰를 강제합니다.
  api.modifyClass(
    "component:discovery/categories-display",
    (Superclass) =>
      class extends Superclass {
        get categoriesComponent() {
          if (this.args.parentCategory) {
            return super.categoriesComponent;
          } else {
            return CategoriesAndLatestTopics;
          }
        }
      }
  );

  // 원본과 동일하지만 "this.site.desktopView" 체크를 약간 수정하여,
  // 모바일에서도 최신 주제를 찾을 수 있도록 했습니다.
  api.modifyClass(
    "route:discovery-categories",
    (Superclass) =>
      class extends Superclass {
        async findCategories(parentCategory) {
          let model;

          let style = this.siteSettings.desktop_category_page_style;
          if (this.site.categories.length > MAX_UNOPTIMIZED_CATEGORIES) {
            style = "categories_only";
          }

          if (
            style === "categories_and_latest_topics" ||
            style === "categories_and_latest_topics_created_date"
          ) {
            model = await this._findCategoriesAndTopics(
              "latest",
              parentCategory
            );
          } else if (style === "categories_and_top_topics") {
            model = await this._findCategoriesAndTopics(
              "top",
              parentCategory
            );
          } else {
            PreloadStore.remove("topic_list");
            model = await CategoryList.list(this.store, parentCategory);
          }

          return model;
        }
      }
  );
})

새로운 컴포넌트 → 코드 편집 → JS 탭에 이 코드를 붙여넣어 보세요.
도움이 되는지 알려주세요.

매우 감사합니다. 시도해 봤지만 아무 변화가 없었습니다. :thinking:

다음 사항들을 확인해 주세요:

  • 코드가 JS 탭에 있는지 (다른 곳에 있지 않은지)
  • 코드가 활성화되어 있는지 (TC를 생성했다면 테마에 연결되어 있는지 확인)
  • desktop_category_page_style 사이트 설정이 categories_and_latest_topics로 되어 있는지
  • 브라우저 콘솔에 오류가 있는지

왜 아무 반응이 없는지 함께 찾아보겠습니다.

저는 이렇게 모두 수행했습니다. 복사한 것이 정확한가요?

중복된 항목을 제거할 수 있습니다. 작동하지 않는 이유가 바로 이것일 가능성이 높습니다(이 5줄):

이제 뭔가 나올 것 같은데! 근데 “모던 카테고리 및 그룹” 기능을 쓰면 안 돼요.

:sweat_smile: