Skip to content

Commit

Permalink
Merge pull request #18 from su-its/feat/home-screen/buttons
Browse files Browse the repository at this point in the history
Feat/home screen/buttons
  • Loading branch information
KikyoNanakusa authored Mar 29, 2024
2 parents 239e2b0 + 75cdedd commit aa51c7b
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 5 deletions.
21 changes: 21 additions & 0 deletions typing-app/src/components/molecules/GameStartButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use client";

import React from "react";
import { Button, useDisclosure } from "@chakra-ui/react";
import LoginModal from "./LoginModal"; // LoginModalコンポーネントをインポート

const GameStartButton = () => {
const { isOpen, onOpen, onClose } = useDisclosure();

return (
<>
<Button colorScheme="green" size="lg" onClick={onOpen}>
Game Start
</Button>

<LoginModal isOpen={isOpen} onClose={onClose} />
</>
);
};

export default GameStartButton;
57 changes: 57 additions & 0 deletions typing-app/src/components/molecules/LoginModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useState } from "react";
import { useRouter } from "next/navigation";
import {
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalFooter,
ModalBody,
ModalCloseButton,
Button,
Input,
} from "@chakra-ui/react";

interface LoginModalProps {
isOpen: boolean;
onClose: () => void;
}

const LoginModal: React.FC<LoginModalProps> = ({ isOpen, onClose }) => {
const [studentId, setStudentId] = useState("");
const router = useRouter();

const handleLogin = async () => {
// TODO:ログイン済みかどうかを判別
// TODO:学籍番号を使用したログイン処理
console.log(studentId);
router.push("/game");
};

return (
<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
<ModalContent>
<ModalHeader>続けるにはログインが必要です</ModalHeader>
<ModalBody>
<Input
placeholder="学籍番号を入力してください"
value={studentId}
onChange={(e) => setStudentId(e.target.value)}
/>
</ModalBody>

<ModalFooter>
<Button colorScheme="blue" mr={3} onClick={handleLogin}>
ログインして続行
</Button>
<Button variant="ghost" onClick={onClose}>
閉じる
</Button>
</ModalFooter>
</ModalContent>
</Modal>
);
};

export default LoginModal;
28 changes: 28 additions & 0 deletions typing-app/src/components/molecules/LogoutButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use client";

import React from "react";
import { useRouter } from "next/navigation";
import { Button, useDisclosure } from "@chakra-ui/react";
import LogoutModal from "./LogoutModal"; // 正しいパスに変更してください

const LogoutButton: React.FC = () => {
const { isOpen, onOpen, onClose } = useDisclosure();
const router = useRouter();

const handleLogout = async () => {
// TODO:ログアウト処理を実装
onOpen();
};

return (
<>
<Button colorScheme="blue" size="lg" onClick={handleLogout}>
Logout
</Button>

<LogoutModal isOpen={isOpen} onClose={onClose} />
</>
);
};

export default LogoutButton;
26 changes: 26 additions & 0 deletions typing-app/src/components/molecules/LogoutModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";
import { Modal, ModalOverlay, ModalContent, ModalHeader, ModalBody, ModalFooter, Button } from "@chakra-ui/react";

interface LogoutModalProps {
isOpen: boolean;
onClose: () => void;
}

const LogoutModal: React.FC<LogoutModalProps> = ({ isOpen, onClose }) => {
return (
<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
<ModalContent>
<ModalHeader>ログアウトしました</ModalHeader>
<ModalBody>ご利用ありがとうございました。</ModalBody>
<ModalFooter>
<Button colorScheme="blue" mr={3} onClick={onClose}>
OK
</Button>
</ModalFooter>
</ModalContent>
</Modal>
);
};

export default LogoutModal;
21 changes: 21 additions & 0 deletions typing-app/src/components/molecules/RankingButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use client";

import { useRouter } from "next/navigation";
import { Button } from "@chakra-ui/react";

const RankingButton = () => {
const router = useRouter();

const handleRouteRanking = async () => {
//TODO:ログインの維持を実装
router.push("/ranking");
};

return (
<Button colorScheme="orange" size="lg" onClick={handleRouteRanking}>
Ranking
</Button>
);
};

export default RankingButton;
19 changes: 19 additions & 0 deletions typing-app/src/components/organism/HomeMenuContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Flex, VStack } from "@chakra-ui/react";
import GameStartButton from "../molecules/GameStartButton";
import RankingButton from "../molecules/RankingButton";
import LogoutButton from "../molecules/LogoutButton";

const HomeMenuContainer = () => {
return (
<Flex justify="center" align="center" h="65vh">
<VStack spacing={8} align="stretch" width="50%" maxWidth="md" mx="auto">
{/* TODO: ログイン状況に応じて表示を切り替え */}
<GameStartButton />
<RankingButton />
<LogoutButton />
</VStack>
</Flex>
);
};

export default HomeMenuContainer;
7 changes: 2 additions & 5 deletions typing-app/src/components/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import React from "react";
import { Text, VStack } from "@chakra-ui/react";
import HomeMenuContainer from "../organism/HomeMenuContainer";

const HomePage: React.FC = () => {
return (
<>
<VStack>
<Text fontSize="2xl">Hello, World!</Text>
<Text fontSize="xl">Welcome to the ITS Room</Text>
</VStack>
<HomeMenuContainer />
</>
);
};
Expand Down

0 comments on commit aa51c7b

Please sign in to comment.