From a33006e0b90fe22ea31bc0d5945d6ced7185e413 Mon Sep 17 00:00:00 2001 From: Enya <26k1234o3@gmail.com> Date: Thu, 3 Aug 2023 19:45:49 +0800 Subject: [PATCH 01/28] =?UTF-8?q?=E5=89=B5=E5=BB=BA=E6=88=BF=E9=96=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/js/api/index.js | 15 +++ packages/frontend/js/common/axiosInstance.js | 26 ++++ packages/frontend/js/components/App.jsx | 11 +- packages/frontend/js/components/Modal.jsx | 22 ++++ .../frontend/js/components/Pagination.jsx | 123 +++++++++++++++++ packages/frontend/js/components/RoomList.jsx | 124 ++++++++++++++++++ packages/frontend/js/redux/slice/roomSlice.js | 64 +++++++++ packages/frontend/js/redux/store/index.js | 4 +- packages/frontend/js/routers/index.js | 4 +- packages/frontend/src/scss/_Pagination.scss | 59 +++++++++ packages/frontend/src/scss/_init.scss | 90 +++++++++++++ packages/frontend/src/scss/_roomList.scss | 119 +++++++++++++++++ packages/frontend/src/scss/index.scss | 2 + 13 files changed, 658 insertions(+), 5 deletions(-) create mode 100644 packages/frontend/js/common/axiosInstance.js create mode 100644 packages/frontend/js/components/Modal.jsx create mode 100644 packages/frontend/js/components/Pagination.jsx create mode 100644 packages/frontend/js/components/RoomList.jsx create mode 100644 packages/frontend/js/redux/slice/roomSlice.js create mode 100644 packages/frontend/src/scss/_Pagination.scss create mode 100644 packages/frontend/src/scss/_roomList.scss diff --git a/packages/frontend/js/api/index.js b/packages/frontend/js/api/index.js index e69de29b..c5bd5440 100644 --- a/packages/frontend/js/api/index.js +++ b/packages/frontend/js/api/index.js @@ -0,0 +1,15 @@ +import axiosInstance from '../common/axiosInstance' + +const url = + process.env.NODE_ENV === 'development' + ? 'https://001f08b9-acb7-4c3a-a54f-a9254b7e8e55.mock.pstmn.io' + : '' +const axios = axiosInstance(url) + +export const getRoomList = (payload) => { + return axios.get('/games', payload) +} + +export const createRoom = (payload) => { + return axios.post('/createroom', payload) +} diff --git a/packages/frontend/js/common/axiosInstance.js b/packages/frontend/js/common/axiosInstance.js new file mode 100644 index 00000000..36801d1c --- /dev/null +++ b/packages/frontend/js/common/axiosInstance.js @@ -0,0 +1,26 @@ +import axios from 'axios' + +export default (baseUrl) => { + const instance = axios.create({ + baseURL: baseUrl + }) + instance.interceptors.response.use( + (res) => { + if (res && res.status === 200) { + return res.data + } + }, + (error) => { + if (error.response) { + switch (error.response.status) { + case 404: + break + default: + console.log(error.message) + } + } + return Promise.reject(error) + } + ) + return instance +} diff --git a/packages/frontend/js/components/App.jsx b/packages/frontend/js/components/App.jsx index 18b750b8..df50e29b 100644 --- a/packages/frontend/js/components/App.jsx +++ b/packages/frontend/js/components/App.jsx @@ -1,10 +1,19 @@ +import { Routes, Route, Navigate } from 'react-router-dom' +import RoomList from './RoomList' +import Game from './Game' + import getAPI from '../api/getAPI' const App = () => { const { data } = getAPI() return ( <> -