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

Frontend/create room #127

Merged
merged 33 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6a74edd
新增遊戲大廳&串接mock API
dawnglede Jul 25, 2023
44558b5
.eslintignore & .prettierignore 新增cypress
dawnglede Jul 25, 2023
830e517
修改API domain設定
dawnglede Jul 27, 2023
576af68
修改呼叫API方式及新增分頁功能
dawnglede Aug 3, 2023
d9f042c
新增顯示房間名稱&調整房主名稱位置
dawnglede Aug 14, 2023
b704fab
add onPageClick feature in both Pagination and RoomList component
dawnglede Aug 22, 2023
c5ff728
add cypress test and replace api call with static json file
dawnglede Aug 23, 2023
0d19be4
update get rooms API and json file
dawnglede Sep 12, 2023
072d3c5
turn js file into ts file
dawnglede Oct 12, 2023
bf82ab1
svg setting
Oct 17, 2023
77f3ee2
outdir
Oct 17, 2023
803dcd6
api ts
Oct 17, 2023
f028112
game router
Oct 17, 2023
0dc1988
Modal and css
Oct 17, 2023
fba0cf5
createRoom
Oct 17, 2023
b7eac2e
Game to ts
Oct 17, 2023
14d2c69
房間切版
Oct 22, 2023
390181c
user資訊context
Oct 22, 2023
9f968ed
user Context
Oct 22, 2023
6f49339
leave room
Oct 22, 2023
47890b1
no use svg
Oct 22, 2023
53a55ca
更新createRoomName
Nov 30, 2023
a69a6f1
add Crown and userInfoModal
Dec 7, 2023
ffc1157
rename TS type
Dec 9, 2023
c5bb058
Merge branch 'frontend/CreateRoom'
Dec 9, 2023
72b02f3
delete duplicated module
Dec 9, 2023
02e6051
rename the type of specific_room and change useNavigate to useHistory
Dec 9, 2023
a4ccb29
change useNavigate to useHistory
Dec 9, 2023
edef902
Merge branch 'frontend/CreateRoom'
Dec 20, 2023
10d598e
編排調整
Dec 20, 2023
a447af8
Merge branch 'main' of https://github.com/Game-as-a-Service/citadels-…
Dec 20, 2023
1fbd589
刪除預設帳號
Dec 20, 2023
a07123b
刪除預設帳號
Dec 20, 2023
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
12 changes: 6 additions & 6 deletions packages/frontend/cypress/e2e/login.cy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
describe('Login Page Test', () => {
it('save user name', () => {
cy.visit('http://localhost:3001/login');
cy.get('#name').type('Snowman');
cy.get('.login_button').click();
cy.url().should('include', '/rooms');
cy.visit('http://localhost:3001/login')
cy.get('#name').type('Snowman')
cy.get('.login_button').click()
cy.url().should('include', '/rooms')
cy.window().then((win) => {
// 使用 win.localStorage.getItem() 來獲取 localStorage 的值
expect(win.localStorage.getItem('userName')).to.equal('Snowman');
});
expect(win.localStorage.getItem('userName')).to.equal('Snowman')
})
})
})
14 changes: 13 additions & 1 deletion packages/frontend/js/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axiosInstance from '../common/axiosInstance'

import { CreateRoom, SpecificRoom } from '../common/types'
type Domain = {
development: string
production: string
Expand Down Expand Up @@ -39,3 +39,15 @@ type player = {
export const getRoomList = () => {
return axios.get<RoomList>('/rooms')
}

export const createRoom = (payload: Object) => {
return axios.post<CreateRoom>('/api/citadels/room', payload)
}

export const getSpecificRoom = (payload: String) => {
return axios.get<SpecificRoom>(`/api/citadels/rooms/${payload}`)
}

export const leaveRoom = (payload: Object, roomId: string) => {
return axios.post(`/rooms/${roomId}:leave`, payload)
}
26 changes: 26 additions & 0 deletions packages/frontend/js/common/axiosInstance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import axios from 'axios'

export default (baseUrl: string) => {
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
}
42 changes: 42 additions & 0 deletions packages/frontend/js/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export type CreateRoom = {
createTime: string
status: string
msg: string
rooms: Record<string, UpdatedRooms>
}

export type UpdatedRooms = {
roomId: string
roomName: string
holderId: string
holderName: string
users: Array<{
userId: string
userName: string
userImage: string
}>
status: string
totalUsers: number
}

export type SpecificRoom = {
searchTime: string
status: string
msg: string
rooms: Record<string, TimedRooms>
}

export type TimedRooms = {
roomId: string
roomName: string
createTime: string
status: string
holderName: string
holderId: string
totalUsers: number
users: Array<{
userId: string
userName: string
userImage: string
}>
}
15 changes: 8 additions & 7 deletions packages/frontend/js/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Routes, Route, Navigate } from 'react-router-dom'
import RoomList from './RoomList'
import Game from './Game'

import getAPI from '../api/getAPI'

import { UserProvider } from '../contexts/UserContext'
const App = () => {
const { data } = getAPI()
return (
<>
{/* <div>title:{data.msg}</div> */}
<Routes>
<Route path='/' element={<Navigate to='/rooms' />} />
<Route path='/rooms' element={<RoomList />} />
<Route path='/game' element={<Game />} />
</Routes>
<UserProvider>
<Routes>
<Route path='/' element={<Navigate to='/rooms' />} />
<Route path='/rooms' element={<RoomList />} />
<Route path='/game/:roomId' element={<Game />} />
</Routes>
</UserProvider>
</>
)
}
Expand Down
28 changes: 28 additions & 0 deletions packages/frontend/js/components/ErrorModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import PropTypes from 'prop-types'

const ErrorModal = (props) => {
const { isErrorVisible, onClose, errorText } = props
return (
<>
{isErrorVisible && (
<div className='error-modal'>
<div className='error-modal-content'>
<span className='error-text'>{errorText}</span>
<button className='cancel-btn' onClick={onClose}>
Close
</button>
</div>
</div>
)}
</>
)
}

ErrorModal.propTypes = {
isErrorVisible: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
errorText: PropTypes.node.isRequired
}

export default ErrorModal
59 changes: 0 additions & 59 deletions packages/frontend/js/components/Game.jsx

This file was deleted.

Loading
Loading