Skip to content

Conversation

@Kosei805
Copy link
Contributor

やったこと

  • やったこと (コミットのハッシュ)
  • 本のアイテムのinterfaceとカートのアイテムのinterfaceを別にした c69a3fc
  • カートページの実装をした

確認した方法

  • pnpm run devで確認した

スクリーンショット

image
image

自動生成したコード

  • ファイル名

@Kosei805 Kosei805 added the frontend frontend development label Nov 13, 2024
@Kosei805 Kosei805 requested a review from kimurash November 13, 2024 10:17
@Kosei805 Kosei805 self-assigned this Nov 13, 2024
Comment on lines 21 to 22
title={book.title}
thumbnail={book.thumbnail}
Copy link
Member

@kimurash kimurash Nov 13, 2024

Choose a reason for hiding this comment

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

カートにタイトルとサムネイルを追加するのが目的だと理解した.
タイトルはモーダルで表示しないことにしたから削除してもいいのでは?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

消しました

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment on lines +17 to +19
const stockList = range(0, stock);
const dataList = stock >= volume ? stockList : [...stockList, volume];
const strList = dataList.map((data) => data.toString());
Copy link
Member

Choose a reason for hiding this comment

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

この3つは何のための変数だろう?

Copy link
Contributor Author

@Kosei805 Kosei805 Nov 13, 2024

Choose a reason for hiding this comment

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

もし、volumeをstockが超えてたら0 ~ stock, volumeの要素を持つ配列が選択肢になる。
そうでないなら0 ~ stockまでを選択肢とする

そういった選択肢の配列

setSelectedCartBook([]);
}, []);

// volumeがstockを超えていないかチェックする
Copy link
Member

Choose a reason for hiding this comment

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

volumeとstockを日本語で書いてあげた方が分かりやすいと思った

// 貸出数が蔵書数を超えていないかチェックする

Copy link
Contributor Author

Choose a reason for hiding this comment

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

変更しました

@Kosei805 Kosei805 marked this pull request as ready for review November 13, 2024 14:27
Comment on lines 24 to 41
export const addBookToCart = (
cart: CartProps[],
bookId: number,
stock: number,
) => {
const index = cart.findIndex((cartBook) => cartBook.id === bookId);
if (index !== -1) {
cart[index].volume += 1;
} else {
cart.push({
id: bookId,
stock,
thumbnail: '',
volume: 1,
});
}
return cart;
};
Copy link
Member

Choose a reason for hiding this comment

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

addBooksToCart に要素数1の配列を渡せば,同じことが実現できると思う.
そうしなかったことに何か理由がある?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

うーむ、特に意味はないかも
強いて言えば、引数に長さ1の配列を書くことに違和感を覚えただけかもしれん
addBooksToCartにまとめるわ

interface BookCardHeaderProps {
id: number;
stock: number;
title: string;
Copy link
Member

Choose a reason for hiding this comment

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

title 消してもいいのでは?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

全部消したつもりやったけど残ってたわ

};

// 選択されている本のIDと表示する本のIDを比較する関数
const selectedCheck = (element: SelectedBookProps) => element.id === id;
Copy link
Member

@kimurash kimurash Nov 13, 2024

Choose a reason for hiding this comment

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

関数名は動詞から始めた方が機能が伝わりやすいと思う.

  • checkSelected
  • isSelected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

関数の設計思想としてはfunctionよりチェックのラベルみたいなニュアンスで使ってるからisSelectedにしたわ

// 選択されている本のIDと表示する本のIDを比較する関数
const selectedCheck = (element: SelectedBookProps) => element.id === id;

const selectedBookAdd = () => {
Copy link
Member

@kimurash kimurash Nov 13, 2024

Choose a reason for hiding this comment

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

  • switchBookSelect
  • toggleBookSelect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

switchBookSelectにしたわ

'1400px': 6,
'1700px': 7,
}}
spacing={{ base: 10, '300px': 'xl' }}
Copy link
Member

Choose a reason for hiding this comment

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

画面幅が300ピクセル以上の場合に xl サイズの間隔が適用されると理解した.
一発で理解できなかったので,コメントを残しておきたい.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

コメント残しました

import { removeBooksFromCart } from '~/utils/cart';

interface CartSelectedDialogProps {
handleLoanPatch: () => void;
Copy link
Member

@kimurash kimurash Nov 13, 2024

Choose a reason for hiding this comment

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

ハンドラ名は handle<ハンドルするイベント名> という形式にした方がいいと思う
handleBorrowButtonClickとか

Copy link
Contributor Author

Choose a reason for hiding this comment

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

handleLoanPatchを書き換えたわ
他のハンドラ名は確認したけど変えてない

w="50%"
data={strList}
value={String(volume)}
error={volume > stock}
Copy link
Member

Choose a reason for hiding this comment

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

便利だね

Copy link
Contributor Author

Choose a reason for hiding this comment

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

やったあ

@Kosei805 Kosei805 merged commit 41c6fb1 into main Nov 14, 2024
3 checks passed
@Kosei805 Kosei805 deleted the 72-cart-page branch November 14, 2024 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend frontend development

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

カートページの実装

3 participants