スマホでカテゴリと「最新」を見る方法は?

モバイルでカテゴリと「最新」を表示するにはどうすればよいですか?

このように?

「カテゴリと最新トピック」ビューを強制するために、カスタム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タブにコードを貼り付けて試すことができます。
うまくいけば教えてください。

「いいね!」 2

どうもありがとうございます。試しましたが、何も変わりませんでした。:thinking:

以下を確認してください。

  • コードがJSタブ内にあること(他の場所ではないこと)
  • コードが有効になっていること(TCを作成した場合、テーマにアタッチされていることを確認してください)
  • desktop_category_page_styleサイト設定がcategories_and_latest_topicsになっていること
  • ブラウザのコンソールにエラーがないこと

何も起こらない理由を突き止めましょう。

これで全部やったと思うのですが、正しくコピーできていますか?

「いいね!」 1

重複を削除できます。それが機能しない理由である可能性が高いです(これらの5行):

「いいね!」 1

今度は何か来るぞ!しかし、「モダンカテゴリとグループ」のThingを使うときはそうではない。

:sweat_smile: