Skip to content

Commit aa8008d

Browse files
committed
Add nearby users to lobby
1 parent 3bfd3de commit aa8008d

File tree

10 files changed

+156
-319
lines changed

10 files changed

+156
-319
lines changed

services/app/apps/codebattle/assets/js/__tests__/LobbyWidget.test.jsx

Lines changed: 0 additions & 209 deletions
This file was deleted.

services/app/apps/codebattle/assets/js/widgets/middlewares/Users.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export const loadUserStats = dispatch => async user => {
2525
}
2626
};
2727

28-
export const loadUserOpponents = (abortController, onSuccess, onFailure) => {
28+
export const loadNearbyUsers = (abortController, onSuccess, onFailure) => {
2929
axios
30-
.get('/api/v1/user/opponents', { signal: abortController.signal })
30+
.get('/api/v1/user/nearby_users', { signal: abortController.signal })
3131
.then(camelizeKeys)
3232
.then(onSuccess)
3333
.catch(onFailure);
@@ -41,22 +41,22 @@ export const loadSimpleUserStats = (onSuccess, onFailure) => user => {
4141
};
4242

4343
export const sendPremiumRequest = (requestStatus, userId) => async dispatch => {
44-
try {
45-
await axios.post(
46-
`/api/v1/user/${userId}/send_premium_request`,
47-
{ status: requestStatus },
48-
{
49-
headers: {
50-
'Content-Type': 'application/json',
51-
'x-csrf-token': window.csrf_token,
44+
try {
45+
await axios.post(
46+
`/api/v1/user/${userId}/send_premium_request`,
47+
{ status: requestStatus },
48+
{
49+
headers: {
50+
'Content-Type': 'application/json',
51+
'x-csrf-token': window.csrf_token,
52+
},
5253
},
53-
},
54-
);
55-
dispatch(actions.togglePremiumRequestStatus());
56-
} catch (error) {
57-
dispatch(actions.setError(error));
58-
}
59-
};
54+
);
55+
dispatch(actions.togglePremiumRequestStatus());
56+
} catch (error) {
57+
dispatch(actions.setError(error));
58+
}
59+
};
6060

6161
const periodToTimeUnit = {
6262
weekly: 'week',
@@ -71,26 +71,26 @@ const getDateByPeriod = period => {
7171
};
7272

7373
export const getUsersRatingPage = ({ name, period, withBots }, { attribute, direction }, page, pageSize) => dispatch => {
74-
const queryParamsString = qs.stringify({
75-
page,
76-
page_size: pageSize,
77-
s: `${attribute}+${direction}`,
78-
q: {
79-
name_ilike: name,
80-
},
81-
date_from: getDateByPeriod(period),
82-
with_bots: withBots,
83-
});
84-
85-
axios
86-
.get(`/api/v1/users?${queryParamsString}`)
87-
.then(({ data }) => {
88-
dispatch(actions.updateUsersRatingPage(camelizeKeys(data)));
89-
dispatch(actions.finishStoreInit());
90-
})
91-
.catch(error => {
92-
dispatch(actions.setError(error));
74+
const queryParamsString = qs.stringify({
75+
page,
76+
page_size: pageSize,
77+
s: `${attribute}+${direction}`,
78+
q: {
79+
name_ilike: name,
80+
},
81+
date_from: getDateByPeriod(period),
82+
with_bots: withBots,
9383
});
94-
};
84+
85+
axios
86+
.get(`/api/v1/users?${queryParamsString}`)
87+
.then(({ data }) => {
88+
dispatch(actions.updateUsersRatingPage(camelizeKeys(data)));
89+
dispatch(actions.finishStoreInit());
90+
})
91+
.catch(error => {
92+
dispatch(actions.setError(error));
93+
});
94+
};
9595

9696
export default loadUserStats;

services/app/apps/codebattle/assets/js/widgets/pages/lobby/LobbyWidget.jsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {
2-
useState, useRef, useEffect, useCallback,
2+
useState, useRef, useEffect, useCallback,
33
} from 'react';
44

55
import cn from 'classnames';
@@ -90,7 +90,7 @@ const LobbyWidget = () => {
9090
seasonTournaments,
9191
// completedTournaments,
9292
presenceList,
93-
opponents,
93+
nearbyUsers,
9494
channel: { online },
9595
} = useSelector(selectors.lobbyDataSelector);
9696

@@ -121,13 +121,16 @@ const LobbyWidget = () => {
121121
handleShowCreateGameModal();
122122
}
123123
}, [activeGame, handleShowCreateGameModal]);
124-
const handleExperimentalGameBtnClick = useCallback(event => {
125-
const type = event.currentTarget.dataset.type || 'css';
124+
const handleExperimentalGameBtnClick = useCallback(
125+
event => {
126+
const type = event.currentTarget.dataset.type || 'css';
126127

127-
if (isAdmin) {
128-
lobbyMiddlewares.createExperimentGame({ type });
129-
}
130-
}, [isAdmin]);
128+
if (isAdmin) {
129+
lobbyMiddlewares.createExperimentGame({ type });
130+
}
131+
},
132+
[isAdmin],
133+
);
131134

132135
useEffect(() => {
133136
const channel = lobbyMiddlewares.fetchState(currentUserId)(dispatch);
@@ -192,7 +195,7 @@ const LobbyWidget = () => {
192195
liveTournaments={liveTournaments}
193196
seasonTournaments={seasonTournaments}
194197
user={currentUser}
195-
opponents={opponents}
198+
nearbyUsers={nearbyUsers}
196199
controls={(
197200
<div className="d-flex flex-column mt-2">
198201
<div className="d-flex w-100">

0 commit comments

Comments
 (0)