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 23 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
1 change: 0 additions & 1 deletion packages/frontend/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
build
node_modules
Cypress
57 changes: 29 additions & 28 deletions packages/frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
{
"env": {
"browser": true,
"es2020": true
"browser": true,
"es2020": true
},
"extends": [
"plugin:react/recommended",
"standard",
"prettier",
"plugin:prettier/recommended"
"plugin:react/recommended",
"standard",
"prettier",
"plugin:prettier/recommended",
"plugin:cypress/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 11,
"sourceType": "module"
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": [
"react",
"prettier"
],
"plugins": ["react", "prettier"],
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"react/react-in-jsx-scope": "off",
"no-case-declarations": "off",
"no-extend-native": "off",
"no-prototype-builtins": "off",
"no-useless-escape": "off",
"space-before-function-paren": ["error", {"anonymous": "always", "named": "never", "asyncArrow": "always"}],
"no-multi-spaces": ["error", { "ignoreEOLComments": true }],
"prefer-promise-reject-errors": ["error", {"allowEmptyReject": true}],
"prettier/prettier": [ "warn", {"endOfLine": "auto"}],
"no-unused-vars": "off"
"react/react-in-jsx-scope": "off",
"no-case-declarations": "off",
"no-extend-native": "off",
"no-prototype-builtins": "off",
"no-useless-escape": "off",
"space-before-function-paren": [
"error",
{ "anonymous": "always", "named": "never", "asyncArrow": "always" }
],
"no-multi-spaces": ["error", { "ignoreEOLComments": true }],
"prefer-promise-reject-errors": ["error", { "allowEmptyReject": true }],
"prettier/prettier": ["warn", { "endOfLine": "auto" }],
"no-unused-vars": "off"
},
"globals": {
"PropTypes": "readonly",
"ReactDom": "readonly",
"React": "readonly"
"PropTypes": "readonly",
"ReactDom": "readonly",
"React": "readonly"
}
}
1 change: 1 addition & 0 deletions packages/frontend/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ postcss.config.js
.vscode
.eslintrc.json
.eslintignore
cypress
15 changes: 9 additions & 6 deletions packages/frontend/cypress/e2e/spec.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// eslint-disable-next-line no-undef
describe('My First Test', () => {
// eslint-disable-next-line no-undef
it('Visits the Kitchen Sink', () => {
// eslint-disable-next-line no-undef
cy.visit('http://localhost:3001/')
describe('Main Page Test', () => {
it('Display game lobby', () => {
cy.viewport(1920, 1080)
cy.intercept('GET', '**/games', {
success: true,
fixture: 'roomList.json'
}).as('getRooms')
cy.visit('http://localhost:3001/rooms')
cy.get('.room-list')
})
})
189 changes: 189 additions & 0 deletions packages/frontend/cypress/fixtures/roomList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"searchTime": "2023-07-04T20:29:54.001Z",
"totalRooms": 13,
"status": "OK",
"msg": "",
"rooms": [
{
"roomId": "sxsxs111",
"gameName": "一起玩富饒之城",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "陳XX",
"holderId": "player1",
"totalPlayers": 3,
"users": [
{ "playerId": "player1", "playerName": "陳XX" },
{ "playerId": "player2", "playerName": "黃XX" },
{ "playerId": "player3", "playerName": "陳XX" }
]
},
{
"roomId": "sxsxs222",
"gameName": "一起玩玩玩玩富饒之城",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "王XX",
"holderId": "player1",
"totalPlayers": 5,
"users": [
{ "playerId": "player1", "playerName": "王XX" },
{ "playerId": "player2", "playerName": "黃XX" },
{ "playerId": "player3", "playerName": "陳XX" },
{ "playerId": "player4", "playerName": "葉XX" },
{ "playerId": "player5", "playerName": "林XX" }
]
},
{
"roomId": "sxsxs333",
"gameName": "一起玩 citadels-game",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "黃XX",
"holderId": "player1",
"totalPlayers": 1,
"users": [{ "playerId": "player1", "playerName": "黃XX" }]
},
{
"roomId": "sxsxs444",
"gameName": "一起玩 $#*&(%%",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "王XX",
"holderId": "player1",
"totalPlayers": 7,
"users": [
{ "playerId": "player1", "playerName": "王XX" },
{ "playerId": "player2", "playerName": "黃XX" },
{ "playerId": "player3", "playerName": "陳XX" },
{ "playerId": "player4", "playerName": "葉XX" },
{ "playerId": "player5", "playerName": "林XX" },
{ "playerId": "player6", "playerName": "王XX" },
{ "playerId": "player7", "playerName": "謝XX" }
]
},
{
"roomId": "sxsxs555",
"gameName": "一緒にお城ゲームをする城",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "王XX",
"holderId": "player1",
"totalPlayers": 5,
"users": [
{ "playerId": "player1", "playerName": "王XX" },
{ "playerId": "player2", "playerName": "黃XX" },
{ "playerId": "player3", "playerName": "陳XX" },
{ "playerId": "player4", "playerName": "葉XX" },
{ "playerId": "player5", "playerName": "林XX" }
]
},
{
"roomId": "sxsxs666",
"gameName": "一起玩富饒之城1234",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "黃XX",
"holderId": "player1",
"totalPlayers": 4,
"users": [
{ "playerId": "player1", "playerName": "黃XX" },
{ "playerId": "player2", "playerName": "黃XX" },
{ "playerId": "player3", "playerName": "陳XX" },
{ "playerId": "player4", "playerName": "葉XX" }
]
},
{
"roomId": "sxsxs777",
"gameName": "一起玩富饒之城1234",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "葉XX",
"holderId": "player1",
"totalPlayers": 2,
"users": [
{ "playerId": "player1", "playerName": "葉XX" },
{ "playerId": "player2", "playerName": "黃XX" }
]
},
{
"roomId": "sxsxs888",
"gameName": "一起玩富饒之城1234",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "張XX",
"holderId": "player1",
"totalPlayers": 2,
"users": [
{ "playerId": "player1", "playerName": "張XX" },
{ "playerId": "player2", "playerName": "黃XX" }
]
},
{
"roomId": "sxsxs999",
"gameName": "一起玩富饒之城1234",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "吳XX",
"holderId": "player1",
"totalPlayers": 2,
"users": [
{ "playerId": "player1", "playerName": "吳XX" },
{ "playerId": "player2", "playerName": "黃XX" }
]
},
{
"roomId": "sxsxs010",
"gameName": "一起玩富饒之城1234",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "黃XX",
"holderId": "player1",
"totalPlayers": 2,
"users": [
{ "playerId": "player1", "playerName": "黃XX" },
{ "playerId": "player2", "playerName": "黃XX" }
]
},
{
"roomId": "sxsxs011",
"gameName": "一起玩富饒之城1234",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "黃XX",
"holderId": "player1",
"totalPlayers": 2,
"users": [
{ "playerId": "player1", "playerName": "黃XX" },
{ "playerId": "player2", "playerName": "黃XX" }
]
},
{
"roomId": "sxsxs012",
"gameName": "一起玩富饒之城1234",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "黃XX",
"holderId": "player1",
"totalPlayers": 3,
"users": [
{ "playerId": "player1", "playerName": "黃XX" },
{ "playerId": "player2", "playerName": "黃XX" },
{ "playerId": "player2", "playerName": "黃XX" }
]
},
{
"roomId": "sxsxs013",
"gameName": "一起玩富饒之城1234",
"createTime": "2023-07-04T19:29:54.001Z",
"status": "OPEN",
"holderName": "洪XX",
"holderId": "player1",
"totalPlayers": 2,
"users": [
{ "playerId": "player1", "playerName": "洪XX" },
{ "playerId": "player2", "playerName": "黃XX" }
]
}
]
}
Empty file removed packages/frontend/js/api/index.js
Empty file.
89 changes: 89 additions & 0 deletions packages/frontend/js/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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 type RoomList = {
totalRooms: number
status: string
msg: string
rooms: Array<RoomInfo>
}

type RoomInfo = {
roomId: string
gameName: string
createTime: string
status: string
holderName: string
holderId: string
totalPlayers: number
users: Array<player>
}

type player = {
playerId: string
playerName: string
}

export const getRoomList = () => {
return axios.get<RoomList>('/rooms')
}

type CreateRoom = {
createTime: string
status: string
msg: string
rooms: Record<string, create_room>
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有注意到這裡跟types.ts裡的內容是重複的,感覺可以直接import進來就好~

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊的create_room跟底下的specific_room,建議名稱可以再重新想一下,重複名稱容易造成混淆

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

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

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

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)
}
Loading