Skip to content

Commit 2ac1812

Browse files
committed
add schedule page and some fixes
1 parent 9110036 commit 2ac1812

File tree

11 files changed

+117
-29
lines changed

11 files changed

+117
-29
lines changed

services/app/apps/codebattle/assets/js/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
renderUserPage,
4949
renderStreamPage,
5050
renderUsersRating,
51+
renderTournamentsSchedule,
5152
} from './widgets';
5253

5354
if (process.env.NODE_ENV === 'development') {
@@ -106,6 +107,7 @@ const tournamentRoot = document.getElementById('tournament-root');
106107
const adminTournamentRoot = document.getElementById('tournament-admin-root');
107108
const eventWidgetRoot = document.getElementById('event-widget');
108109
const userPageRoot = document.getElementById('user-page-root');
110+
const tournamentsScheduleRoot = document.getElementById('tournaments-schedule-root');
109111

110112
if (gameWidgetRoot) {
111113
renderGameWidget(gameWidgetRoot);
@@ -170,3 +172,7 @@ if (invitesRoot) {
170172
if (streamRoot) {
171173
renderStreamPage(streamRoot);
172174
}
175+
176+
if (tournamentsScheduleRoot) {
177+
renderTournamentsSchedule(tournamentsScheduleRoot);
178+
}

services/app/apps/codebattle/assets/js/widgets/App.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const InvitesContainer = React.lazy(() => import('./components/InvitesContainer'
6666
const RoomWidget = React.lazy(() => import('./pages/RoomWidget'));
6767
const LobbyWidget = React.lazy(() => import('./pages/lobby'));
6868
const RatingList = React.lazy(() => import('./pages/rating'));
69+
const TournamentsSchedule = React.lazy(() => import('./pages/schedule'));
6970
const UserSettings = React.lazy(() => import('./pages/settings'));
7071
const UserProfile = React.lazy(() => import('./pages/profile'));
7172
const Registration = React.lazy(() => import('./pages/registration'));
@@ -143,6 +144,16 @@ export const UsersRating = () => (
143144
</Provider>
144145
);
145146

147+
export const TournamentsSchedulePage = () => (
148+
<Provider store={store}>
149+
<PersistGate loading={null} persistor={persistor}>
150+
<Suspense>
151+
<TournamentsSchedule />
152+
</Suspense>
153+
</PersistGate>
154+
</Provider>
155+
);
156+
146157
export const UserPage = () => (
147158
<Provider store={store}>
148159
<PersistGate loading={null} persistor={persistor}>

services/app/apps/codebattle/assets/js/widgets/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
TournamentPlayerPage,
1818
UserPage,
1919
UsersRating,
20+
TournamentsSchedulePage,
2021
StreamPage,
2122
} from './App';
2223

@@ -37,4 +38,5 @@ export const renderEventPage = domElement => createRoot(domElement).render(<Even
3738
export const renderTournamentPlayerPage = domElement => createRoot(domElement).render(<TournamentPlayerPage />);
3839
export const renderUserPage = domElement => createRoot(domElement).render(<UserPage />);
3940
export const renderUsersRating = domElement => createRoot(domElement).render(<UsersRating />);
41+
export const renderTournamentsSchedule = domElement => createRoot(domElement).render(<TournamentsSchedulePage />);
4042
export const renderStreamPage = domElement => createRoot(domElement).render(<StreamPage />);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import LobbyChat from './LobbyChat';
2323
import SeasonProfilePanel from './SeasonProfilePanel';
2424

2525
const createBtnClassName = cn(
26-
'btn rounded-lg',
26+
'btn cb-rounded',
2727
);
2828

2929
const createBasicGameBtnClassName = cn(
@@ -93,7 +93,6 @@ const LobbyWidget = () => {
9393
activeGames,
9494
liveTournaments,
9595
upcomingTournaments,
96-
seasonProfile,
9796
// completedTournaments,
9897
presenceList,
9998
channel: { online },
@@ -184,7 +183,6 @@ const LobbyWidget = () => {
184183
<SeasonProfilePanel
185184
liveTournaments={liveTournaments}
186185
upcomingTournaments={upcomingTournaments}
187-
seasonProfile={seasonProfile}
188186
user={currentUser}
189187
controls={(
190188
<div className="d-flex flex-column mt-2">

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import TournamentListItem, { activeIcon, upcomingIcon } from './TournamentListIt
77
const contestDatesText = 'Season: Oct 14 - Dec 21';
88

99
const SeasonProfilePanel = ({
10-
upcomingTournaments = [], liveTournaments = [], seasonProfile, user, controls,
10+
upcomingTournaments = [], liveTournaments = [], user, controls,
1111
}) => (
1212
<div className="d-flex flex-column flex-lg-row flex-md-row my-0 my-lg-2 my-md-2">
1313
<div className="col-12 col-lg-8 col-md-8 my-2 my-lg-0 my-md-0">
@@ -42,10 +42,28 @@ const SeasonProfilePanel = ({
4242
</div>
4343
)
4444
: <div className="pt-2 mt-2">Competition not started yet</div>}
45-
<div className="d-flex w-100 pt-2 mt-2">
46-
<a href="_blank" type="button" className="btn btn-secondary cb-btn-secondary mx-2 w-100 rounded">{i18n.t('Contests History')}</a>
47-
<a href="_blank" type="button" className="btn btn-secondary cb-btn-secondary mx-2 w-100 rounded">{i18n.t('My Tournaments')}</a>
48-
<a href="_blank" type="button" className="btn btn-secondary cb-btn-secondary mx-2 w-100 rounded">{i18n.t('Create a Tournament')}</a>
45+
<div className="d-flex flex-column flex-lg-row flex-md-row w-100 pt-2 mt-2">
46+
<a
47+
href="/schedule#contest"
48+
type="button"
49+
className="btn btn-secondary cb-btn-secondary mx-0 mx-md-2 mx-lg-2 w-100 cb-rounded text-nowrap"
50+
>
51+
{i18n.t('Contests History')}
52+
</a>
53+
<a
54+
href="/schedule#my"
55+
type="button"
56+
className="btn btn-secondary cb-btn-secondary mx-0 mx-md-2 mx-lg-2 w-100 cb-rounded text-nowrap"
57+
>
58+
{i18n.t('My Tournaments')}
59+
</a>
60+
<a
61+
href="/tournaments"
62+
type="button"
63+
className="btn btn-secondary cb-btn-secondary mx-0 mx-md-2 mx-lg-2 w-100 cb-rounded text-nowrap"
64+
>
65+
{i18n.t('Create a Tournament')}
66+
</a>
4967
</div>
5068
</div>
5169
</div>
@@ -63,18 +81,18 @@ const SeasonProfilePanel = ({
6381

6482
<div className="cb-bg-highlight-panel d-flex py-2 px-1">
6583
<div className="stat-item py-1 w-100">
66-
<span className="stat-value d-block cb-text-danger">1200</span>
84+
<span className="stat-value d-block cb-text-danger">{user.rating}</span>
6785
<span className="stat-label text-uppercase">(Elo Rating)</span>
6886
</div>
6987
<div className="stat-item py-1 w-100">
7088
<span className="stat-value d-block cb-text-success">
7189
#
72-
{seasonProfile.place}
90+
{user.rank}
7391
</span>
7492
<span className="stat-label text-uppercase">Place</span>
7593
</div>
7694
<div className="stat-item py-1 w-100">
77-
<span className="stat-value d-block cb-text-danger">{seasonProfile.score}</span>
95+
<span className="stat-value d-block cb-text-danger">{user.points || 0}</span>
7896
<span className="stat-label text-uppercase">Points</span>
7997
</div>
8098
</div>

services/app/apps/codebattle/assets/js/widgets/pages/schedule/TournamentSchedule.jsx

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import i18n from '../../../i18n';
99
import TournamentListItem, { activeIcon } from '../lobby/TournamentListItem';
1010

1111
const states = [
12-
'contest',
13-
'my',
14-
'all',
12+
'#contest',
13+
'#my',
14+
'#all',
1515
];
1616

1717
const getStateFromHash = () => {
1818
const { hash } = window.location;
19+
console.log(hash);
1920

2021
if (states.includes(hash)) {
2122
return hash;
@@ -25,58 +26,79 @@ const getStateFromHash = () => {
2526
};
2627

2728
const TournamentSchedule = () => {
28-
const [context, setContext] = useState(getStateFromHash());
29+
const [context, setContext] = useState(getStateFromHash);
30+
const [loading, setLoading] = useState(true);
2931
const [tournaments, setTournaments] = useState([]);
3032
const isAdmin = useSelector(currentUserIsAdminSelector);
3133

32-
const sectionBtnClassName = cn('btn btn-secondary cb-btn-secondary w-100');
34+
const sectionBtnClassName = cn('btn btn-secondary border-0 cb-btn-secondary cb-rounded');
3335
const onChangeContext = event => {
3436
event.preventDefault();
3537

36-
if (event.dataset.context && states.includes(event.dataset.context)) {
37-
const { context: newContext } = event.dataset;
38-
window.location.hash = newContext;
39-
setContext(newContext);
38+
try {
39+
setLoading(true);
40+
if (event.currentTarget.dataset.context && states.includes(event.currentTarget.dataset.context)) {
41+
const { context: newContext } = event.currentTarget.dataset;
42+
window.location.hash = newContext;
43+
setContext(newContext);
44+
}
45+
} catch (e) {
46+
setLoading(false);
4047
}
4148
};
4249

4350
useEffect(() => {
44-
setTournaments([]);
51+
if (!isAdmin && context === '#all') {
52+
setContext('#contest');
53+
return;
54+
}
55+
56+
if (context === '#contest') {
57+
setTournaments([]);
58+
setLoading(false);
59+
} else if (context === '#my') {
60+
setTournaments([]);
61+
setLoading(false);
62+
} else if (context === '#all') {
63+
setTournaments([]);
64+
setLoading(false);
65+
}
4566
}, [context]);
4667

4768
return (
48-
<div className="d-flex cb-rounded cb-bg-panel">
49-
<div className="d-flex">
69+
<div className="d-flex flex-column cb-rounded cb-bg-panel p-2">
70+
<div className="d-flex justify-content-center">
5071
<button
5172
type="button"
5273
className={sectionBtnClassName}
53-
data-context="contest"
74+
data-context="#contest"
5475
onClick={onChangeContext}
55-
disabled={context === 'contest'}
76+
disabled={context === '#contest' || loading}
5677
>
5778
{i18n.t('Contest Tournaments')}
5879
</button>
5980
<button
6081
type="button"
6182
className={sectionBtnClassName}
62-
data-context="my"
83+
data-context="#my"
6384
onClick={onChangeContext}
64-
disabled={context === 'my'}
85+
disabled={context === '#my' || loading}
6586
>
6687
{i18n.t('My Tournaments')}
6788
</button>
6889
{isAdmin && (
6990
<button
7091
type="button"
7192
className={sectionBtnClassName}
72-
data-context="all"
93+
data-context="#all"
7394
onClick={onChangeContext}
74-
disabled={context === 'all'}
95+
disabled={context === '#all' || loading}
7596
>
7697
{i18n.t('All Tournaments')}
7798
</button>
7899
)}
79100
</div>
101+
<div className="cb-separator" />
80102
<div className="d-flex flex-column mt-2">
81103
{tournaments.map(t => <TournamentListItem tournament={t} icon={activeIcon} />)}
82104
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import TournamentSchedule from './TournamentSchedule';
2+
3+
export default TournamentSchedule;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
defmodule CodebattleWeb.TournamentsScheduleController do
2+
use CodebattleWeb, :controller
3+
4+
import PhoenixGon.Controller
5+
6+
alias Codebattle.StreamConfig
7+
8+
require Logger
9+
10+
plug(CodebattleWeb.Plugs.RequireAuth when action in [:index])
11+
12+
def index(conn, _) do
13+
conn
14+
|> render("index.html")
15+
end
16+
end

services/app/apps/codebattle/lib/codebattle_web/router.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ defmodule CodebattleWeb.Router do
170170
resources("/tournaments", TournamentController, only: [:index, :show])
171171

172172
get("/stream", StreamController, :index)
173+
get("/schedule", TournamentsScheduleController, :index)
173174
get("/stream/preset", StreamController, :stream_preset)
174175

175176
scope "/tournaments" do
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="container-lg cb-text" id="tournaments-schedule-root"></div>
2+
<script>
3+
window.csrf_token = "<%= csrf_token() %>"
4+
</script>

0 commit comments

Comments
 (0)