Skip to content

Conversation

@riririn180904
Copy link
Collaborator

対応Issue

resolve #1941

概要

  • お知らせ欄を更新日時順が新しい順に表示されるように変更

実装詳細

画面スクリーンショット等

スクリーンショット 2025-11-10 190254

テスト項目

  • お知らせ欄が新しい順に表示されているか
  • お知らせを 管理者画面から新規作成、編集した場合も更新順に表示されるか

備考

前のPRのレビューで指摘されたconst部分消したらエラーになったのでそのままにしてあります

Copy link
Contributor

@hikahana hikahana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

できればですが、毎回PR消さなくても良いです!
どこで何のコメントしてどうなっているかの情報把握が少し面倒になりそうなので!!!
お願いします~

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちょっと差分以外のところにコメントできないからここで
下みたいにsortedNewsを消したところをnewsにしたらエラー無く動くと思っているんだけどどうですかね?
エラーの詳細についても貼ってもらえるとうれしいかもです。

const { news, error, isLoading } = useGetNews();

~略~

  const newsList = news.map((item, index) => {
    const date = formattedDates[index] ?? 'お知らせはありません。';

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { news, error, isLoading } = useGetNews();
これ全部消したときはこれが出ました↓
スクリーンショット 2025-12-02 165101

あとsortedNewsのところnewsにしてみたんですけどundefindになっちゃいましたね…
const newsList = (news ?? []).map((item, index) => { const date = formattedDates[index] ?? 'お知らせはありません。';
GPTに相談してこんな感じに変更したら動きましたがどうでしょう?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これで解決できると思われ

const NewsList: FC<NewsListProps> = () => {
  const { news, error, isLoading } = useGetNews();
  if (news === undefined) return [];

  const formattedDates = news.map((item) => {
    const date = new Date(item.createdAt);
    const formattedDate = format(date, 'yyyy/MM/dd');
    return formattedDate;
  });

  const newsList = news.map((item, index) => {
    const date = formattedDates[index] ?? 'お知らせはありません。';

    return (
      <div key={item.id} className="flex flex-col gap-2">
        <span className="w-24 text-base font-medium text-font">{date}</span>
        <span className="w-full whitespace-pre-line text-base font-medium text-font">
          {item.body}
        </span>
      </div>
    );
  });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これで解決できると思われ

const NewsList: FC<NewsListProps> = () => {
  const { news, error, isLoading } = useGetNews();
  if (news === undefined) return [];

  const formattedDates = news.map((item) => {
    const date = new Date(item.createdAt);
    const formattedDate = format(date, 'yyyy/MM/dd');
    return formattedDate;
  });

  const newsList = news.map((item, index) => {
    const date = formattedDates[index] ?? 'お知らせはありません。';

    return (
      <div key={item.id} className="flex flex-col gap-2">
        <span className="w-24 text-base font-medium text-font">{date}</span>
        <span className="w-full whitespace-pre-line text-base font-medium text-font">
          {item.body}
        </span>
      </div>
    );
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

お知らせ欄の昇順変更

3 participants