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

race resultを消すAPIを実装 #305

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
112 changes: 112 additions & 0 deletions client/src/components/RegisterField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FC, useEffect, useState } from "react";
import { Timestamp } from "@bufbuild/protobuf";
import {
DeleteRaceResultRequest_HorseAndEffect,
HorseDetail_Image,
JWT,
RaceDetail_Member,
Expand Down Expand Up @@ -428,10 +429,121 @@ const RegisterRaceResultField: FC<{ jwt: JWT | null }> = ({ jwt }) => {
);
};

const DeleteRaceResultField: FC<{ jwt: JWT | null }> = ({ jwt }) => {
const [id, setId] = useState<number>(1);
const [horses, setHorses] = useState<
DeleteRaceResultRequest_HorseAndEffect[]
>([]);
useEffect(() => {
raceClient
.raceData({ id })
.then((res) =>
setHorses(
res.race!.members!.map(
(h) =>
new DeleteRaceResultRequest_HorseAndEffect({
member: h,
match: false,
win: false,
})
)
)
);
}, [id]);
return (
<fieldset>
<legend>競争結果削除</legend>
<div>
<label>
id:{" "}
<input
type="number"
value={id}
onChange={(e) => setId(+e.target.value)}
/>
</label>
</div>
{horses.map((e) => (
<div key={`h-${e.member!.horse!.id}`}>
{e.member!.horse!.name}:{" "}
<label>
<input
type="checkbox"
value={e.win ? "on" : ""}
onChange={(ev) =>
setHorses(
horses.map((h) =>
e.member!.horse!.id ===
h.member!.horse!.id
? new DeleteRaceResultRequest_HorseAndEffect(
{
member: h.member,
match: h.match,
win:
ev.target.value ===
"on",
}
)
: h
)
)
}
/>
win
</label>
<label>
<input
type="checkbox"
value={e.match ? "on" : ""}
onChange={(ev) =>
setHorses(
horses.map((h) =>
e.member!.horse!.id ===
h.member!.horse!.id
? new DeleteRaceResultRequest_HorseAndEffect(
{
member: h.member,
win: h.win,
match:
ev.target.value ===
"on",
}
)
: h
)
)
}
/>
match
</label>
</div>
))}
<button
onClick={() => {
raceClient
.deleteRaceResult({
adminJwt: jwt!,
horseAndEffects: horses,
id,
})
.then(() => alert("削除完了!"))
.catch((err) => {
console.error(err);
alert("削除失敗......");
});
}}
>
決定
</button>
</fieldset>
);
};

export {
RegisterRaceField,
EditRaceField,
RegisterHorseField,
EditHorseField,
RegisterRaceResultField,
DeleteRaceResultField,
};
3 changes: 3 additions & 0 deletions client/src/pages/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
RegisterRaceField,
EditHorseField,
RegisterRaceResultField,
DeleteRaceResultField,
} from "../components/RegisterField";

const AdminPage: FC<{}> = () => {
Expand Down Expand Up @@ -52,6 +53,8 @@ const AdminPage: FC<{}> = () => {
<EditHorseField jwt={jwt} />

<RegisterRaceResultField jwt={jwt} />

<DeleteRaceResultField jwt={jwt} />
</>
);
};
Expand Down
Loading