Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 173 ページング機能のエラー発生時の復帰処理を実装 #209

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

Aosanori
Copy link

@Aosanori Aosanori commented May 21, 2024

概要

レビュー観点

@akatsuki174 さんのお陰で解決しました!ありがとうございました!
common_paging_view.dartにおいて、
2ページ目以降の読み込み、表示、再読み込みの3つについての条件分岐が複雑であり、
三項演算子では可読性に乏しくなると考えました。
そこで無理矢理ですが、可読性の観点からswitch文を用いました。

こちらについてさらに良い方法がございましたら、ご教授いただけますと幸いです

switch (data.hasMore) {
  true when hasError && isLoading => const Center(
      child: Padding(
        padding: EdgeInsets.all(16),
        child: CircularProgressIndicator(),
      ),
    ),
  true when hasError && !isLoading => _EndItemWhenError(
      onPressed: () async =>
          ref.read(_provider.notifier).loadNext(),
    ),
  true when !hasError => _EndItem(
      onScrollEnd: () async =>
          ref.read(_provider.notifier).loadNext(),
    ),
  true => null,
  false => null,
},

レビューレベル

  • Lv1: ぱっとみて違和感がないかチェックして Approve する
  • Lv2: 仕様レベルまで理解して、仕様通りに動くかある程度検証して Approve する
  • Lv3: 実際に環境で動作確認したうえで Approve する

レビュー優先度

  • すぐに見てもらいたい ( hotfix など ) 🚀
  • 今日中に見てもらいたい 🚗
  • 今日〜明日中で見てもらいたい 🚶
  • 数日以内で見てもらいたい 🐢

画像 / 動画

  • 読み込み失敗時に再読み込みのためのボタンを設置いたしました。
  • ボタンをタップ時に、再読み込みが行われます。その際に読み込み中はCircularProgressIndicatorが表示されるようにしました。
Before After Design
2024-05-21.18.15.24.mov
2024-05-21.17.34.39.mov

動作確認手順

  • 初回読み込みのために最初は通常通りにアプリ起動
  • 2ページ目以降は機内モードに設定もしくはPCのWIFIを切ってから、スクロールし追加読み込みを行う。
  • 読み込みが失敗したことを確認したら、再びシミュレータをオンラインの状態に戻しrefreshボタンをタップする。
  • 正常に次のページが読み込まれたら動作確認完了。

備考

@Aosanori Aosanori self-assigned this May 21, 2024
@yumemi-team-review-requester yumemi-team-review-requester bot requested review from a team, akatsuki174 and warahiko and removed request for a team May 21, 2024 09:10
Copy link

Ready for review 🚀

Copy link

github-actions bot commented May 21, 2024

Visit the preview URL for this PR (updated for commit d09e747):

https://flutter-mobile-project-template-catalog--pr209-issue-1-j5t2jn9g.web.app

(expires Mon, 24 Jun 2024 08:14:17 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 9ea56735a63d07a7cfe62eb204b0528284c37c23

Copy link

@akatsuki174 akatsuki174 left a comment

Choose a reason for hiding this comment

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

コメントしましたが、Flutter/Dartからしばらく離れているので、他の方のレビューもいただけるといいかなという状態です 🙇

@Aosanori
Copy link
Author

Aosanori commented May 27, 2024

愚問で申し訳ござませんが、CIがcheck-format-ci.sh で失敗している原因を教えていただきたいです。

Switch式を切り出す以前のテスト(c82f97a)は成功していましたが、Switch式の切り出し等のリファクタリングを行った結果、CIからエラーが出力されるようになりました。(1a3cf4c),(bc7299b)

そこでテストが失敗している原因の究明のためにローカルで実行した結果、以下の出力が得られました。

$ bash scripts/check-format-ci.sh

Fixes might be needed for ./packages/cores/core/.dart_tool/build/entrypoint/build.dart
Fixes might be needed for ./apps/app/.dart_tool/flutter_build/dart_plugin_registrant.dart
Fixes might be needed for ./apps/app/.dart_tool/build/entrypoint/build.dart

check-format-ci.shでは、コードが警告の有無、正しく整形されているかをチェックするものと認識しております。しかしながらCIのエラーの有無に関わらず出力は変化しないため、原因の見当がつきません。

お忙しいところ恐縮ですが、回答の方お待ちしております。

@K9i-0
Copy link
Contributor

K9i-0 commented May 30, 2024

@Aosanori

[cores_core]: Changed ./lib/src/ui/util/common_paging_view.dart

このファイルのフォーマットが必要みたいですよ 🙆‍♂️

@Aosanori
Copy link
Author

@K9i-0
お忙しい中ありがとうございます!
おかげで解決することができました!

Copy link
Contributor

@warahiko warahiko left a comment

Choose a reason for hiding this comment

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

レビューが遅れて申し訳ないです
全体的な動きは問題なく、UX が向上していると感じました 👍

細かい点をいくつかコメントしているので、確認いただけるとありがたいです!

@@ -29,16 +34,17 @@ extension AsyncValueExtension<T> on AsyncValue<T> {
bool skipErrorOnHasValue = false,
}) {
if (skipErrorOnHasValue) {
logger.shout(isLoading);
Copy link
Contributor

Choose a reason for hiding this comment

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

nits
これは確認用のが残ってしまっている?

Copy link
Author

Choose a reason for hiding this comment

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

d2b6a70にて修正いたしました!

@@ -64,6 +64,40 @@ class CommonPagingView<N extends PagingAsyncNotifier<D, T>,

final void Function(AppException e) _onError;

Widget _endItem(
Copy link
Contributor

Choose a reason for hiding this comment

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

imo
ここは nullable にして、空を返すケースは null にしてもいいかもですね
「なにも表示しない」を明確化できそうです

Copy link
Author

Choose a reason for hiding this comment

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

01fc576にて修正いたしました!

);
}

if (!hasError) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nits
ここで残りのケース全て受けているので、 L.98 には入らないですかね
単純に return としてもよさそうですし、「エラーがないとき」を明示したければ L.98 で throw するようにしてもよさそうです

Copy link
Author

Choose a reason for hiding this comment

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

@warahiko
ご指摘ありがとうございます!
ちなみL.98に入らないのであれば、if(!hasError)を取り払っても問題ないですか?
そのようにすれば返り値にnullの可能性が消失するのでそちらの方が良いのかなと考えましたが意見を賜りたいです!

ちなみに上でご指摘いただいた「なにも表示しない」を明確化するにはSizedBox.shrink();等の空のWidgetを返すのではなく基本的にはnullで返したほうが良いのでしょうか?
今後の開発の参考にさせて頂きたいのでご回答いただけますと幸いです!

Copy link
Contributor

Choose a reason for hiding this comment

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

L.98に入らないのであれば、if(!hasError)を取り払っても問題ないですか?

はい、自分は問題ないと思います!

「なにも表示しない」を明確化するにはSizedBox.shrink();等の空のWidgetを返すのではなく基本的にはnullで返したほうが良いのでしょうか?

今回のケースであれば、この API 自体が null で返す仕様になっているのでそうしたほうがよさそうですね
一般的にも、たとえサイズゼロの要素でも処理が必要ですし、 min(Height|Width) があればそれが適用されたりする(しますよね......?ちゃんと調べられてはないですが......)ので、できるのであればそもそも要素として入れない、というのは優先すべきじゃないかなと思いました
一方で普通の StatelessWidget#build() などは non-null な Widget を返す必要があるので、こういうときには仕方ないかな、くらいかなと

(などと書いていますが初心者の一意見なので、もっと使い慣れている人に聞いたほうがよさそうです)

Copy link
Author

Choose a reason for hiding this comment

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

返信ありがとうございます!
確かにこの API 自体が null で返す仕様になっているので、nullとして要素を存在させない方が自然な感じはありますね!ありがとうございます!

Copy link
Author

Choose a reason for hiding this comment

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

65e8d62にて修正いたしました!

Comment on lines 78 to 83
return const Center(
child: Padding(
padding: EdgeInsets.all(16),
child: CircularProgressIndicator(),
),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

nits
他の EndItem と粒度は同じですがここだけ直書き、というのに少し違和感を感じました
_EndItem との違いを分かりやすくするためにも、名前があるとよさそうに思います

Copy link
Author

Choose a reason for hiding this comment

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

605536dにて修正いたしました!

Comment on lines 95 to 96
// Displays EndItem to detect scroll end
// if more data is available and no errors.
Copy link
Contributor

Choose a reason for hiding this comment

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

nits
ここのコメントが消えてしまっていますね
EndItem という naming だと少しここの意図は分かり辛いので残しておくほうがよさそうに思います
もしくは、もう一方の ProgressIndicator の naming との兼ね合いでいい感じに名前をつけてもよさそうです

Copy link
Author

Choose a reason for hiding this comment

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

018eb9fにて修正いたしました!

@@ -64,6 +64,40 @@ class CommonPagingView<N extends PagingAsyncNotifier<D, T>,

final void Function(AppException e) _onError;

Widget _endItem(
Copy link
Contributor

Choose a reason for hiding this comment

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

comment
切り出し 👍

@Aosanori Aosanori requested a review from blendthink June 17, 2024 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: ページング機能のエラー発生時の復帰処理を実装する
4 participants