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

リアクション降下のリファクタ #319

Merged
merged 3 commits into from
Oct 21, 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
1 change: 0 additions & 1 deletion view-user/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 18 additions & 27 deletions view-user/src/pages/screen/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import type { NextPage } from "next";
import Image from "next/image";
import { useState, useEffect, useRef } from "react";
import Matter from "matter-js";
import { useSubscription } from "@apollo/client";
import {
SubscribeListNumbersDocument,
SubscribeCreatedStampTriggerDocument,
SubscribeOneLatestReachLogDocument,
} from "@/types/graphql";
import type {
SubscribeListNumbersSubscription,
SubscribeCreatedStampTriggerSubscription,
SubscribeOneLatestReachLogSubscription,
type SubscribeListNumbersSubscription,
type SubscribeCreatedStampTriggerSubscription,
type SubscribeOneLatestReachLogSubscription,
} from "@/types/graphql";
import {
NumberCardLarge,
Expand Down Expand Up @@ -69,7 +66,7 @@ const Page: NextPage = () => {
const render = useRef<Matter.Render | null>(null);
const engine = useRef<Matter.Engine | null>(null);
const [latestCreatedAt, setLatestCreatedAt] = useState<string>(
new Date().toString(),
new Date().toISOString(),
);
const [bingoNumbers, setBingoNumbers] = useState<
SubscribeListNumbersSubscription["numbers"]
Expand Down Expand Up @@ -100,21 +97,23 @@ const Page: NextPage = () => {
);

useEffect(() => {
if (triggers?.stampTriggers?.length) {
triggers.stampTriggers.forEach((stamp: Stamp) => {
const stamps = triggers?.stampTriggers;
if (stamps?.length) {
stamps.forEach((stamp: Stamp) => {
addCircleById(stamp.name);

if (
stamp.createdAt &&
new Date(stamp.createdAt) > new Date(latestCreatedAt)
) {
setLatestCreatedAt(stamp.createdAt);
}
});

setLatestCreatedAt(latestCreatedAt);
const latestStamp = stamps.reduce((latest, stamp) => {
return new Date(stamp.createdAt) > new Date(latest.createdAt)
? stamp
: latest;
}, stamps[0]);

if (new Date(latestStamp.createdAt) > new Date(latestCreatedAt)) {
setLatestCreatedAt(latestStamp.createdAt);
}
}
}, [triggers]);
}, [triggers, latestCreatedAt]);

// ビンゴ番号のuseEffect
useEffect(() => {
Expand Down Expand Up @@ -175,14 +174,6 @@ const Page: NextPage = () => {
},
});

const ground = Bodies.rectangle(
window.innerWidth / 2,
window.innerHeight,
window.innerWidth + 10,
20,
{ isStatic: true, render: { visible: false } },
);

const rightWall = Bodies.rectangle(
window.innerWidth,
window.innerHeight / 2,
Expand All @@ -199,7 +190,7 @@ const Page: NextPage = () => {
{ isStatic: true, render: { visible: false } },
);

Composite.add(engine.current.world, [ground, leftWall, rightWall]);
Composite.add(engine.current.world, [leftWall, rightWall]);
Render.run(render.current);

const runner = Runner.create();
Expand Down
Loading