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

chore: ちょいリファクタリング #199

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/functional/useOrderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { OrderEntity } from "~/models/order";
type BaseAction<TypeName extends string> = { type: TypeName };
type Action<
TypeName extends string,
U = Record<never, never>,
U extends Record<string, unknown> = Record<never, never>,
> = BaseAction<TypeName> & U;

type Clear = Action<"clear", { effectFn?: () => void }>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { type ComponentPropsWithRef, useEffect } from "react";
import { AttractiveTextBox } from "./AttractiveTextBox";

type props = ComponentPropsWithRef<typeof AttractiveTextBox>;
import { useEffect } from "react";

/**
* 上下キーで数値を増減させない数値専用のテキストボックス
* 上下キーで数値を増減させないEffect
*/
const InputNumber = ({ ...props }: props) => {
const usePreventNumberKeyUpDown = () => {
useEffect(() => {
const handler = (event: KeyboardEvent) => {
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
Expand All @@ -21,8 +18,6 @@ const InputNumber = ({ ...props }: props) => {
window.removeEventListener("keyup", handler);
};
}, []);

return <AttractiveTextBox type="number" {...props} />;
};

export { InputNumber };
export { usePreventNumberKeyUpDown };
6 changes: 4 additions & 2 deletions app/components/pages/CashierV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { OrderEntity } from "~/models/order";
import { useInputStatus } from "../functional/useInputStatus";
import { useLatestOrderId } from "../functional/useLatestOrderId";
import { useOrderState } from "../functional/useOrderState";
import { usePreventNumberKeyUpDown } from "../functional/usePreventNumberKeyUpDown";
import { useUISession } from "../functional/useUISession";
import { AttractiveTextBox } from "../molecules/AttractiveTextBox";
import { InputNumber } from "../molecules/InputNumber";
import { ChargeView } from "../organisms/ChargeView";
import { DiscountInput } from "../organisms/DiscountInput";
import { OrderAlertDialog } from "../organisms/OrderAlertDialog";
Expand All @@ -31,6 +31,7 @@ const CashierV2 = ({ items, orders, submitPayload }: props) => {
useInputStatus();
const [UISession, renewUISession] = useUISession();
const { nextOrderId } = useLatestOrderId(orders);
usePreventNumberKeyUpDown();

useEffect(() => {
newOrderDispatch({ type: "updateOrderId", orderId: nextOrderId });
Expand Down Expand Up @@ -117,7 +118,8 @@ const CashierV2 = ({ items, orders, submitPayload }: props) => {
[newOrderDispatch],
)}
/>
<InputNumber
<AttractiveTextBox
type="number"
key={`Received-${UISession.key}`}
onTextSet={useCallback(
(text) =>
Expand Down
3 changes: 3 additions & 0 deletions app/routes/items/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "@remix-run/react";
import { useMemo } from "react";
import useSWRSubscription from "swr/subscription";
import { usePreventNumberKeyUpDown } from "~/components/functional/usePreventNumberKeyUpDown";
import { Button } from "~/components/ui/button";
import { Input } from "~/components/ui/input";
import { Label } from "~/components/ui/label";
Expand Down Expand Up @@ -59,6 +60,8 @@ export default function Item() {
}, base);
}, [items]);

usePreventNumberKeyUpDown();

return (
<div className="bg-white p-4 font-sans">
<h1 className="mb-6 font-bold text-3xl text-gray-800">アイテム管理</h1>
Expand Down