Skip to content

Commit d3e0c86

Browse files
fikzzzymfikria
andauthored
Fix Issue 182 (#199)
* Add loading indicator * update margin Co-authored-by: mfikria <mfikria@gmail.com>
1 parent 9b44a0b commit d3e0c86

File tree

5 files changed

+127
-7
lines changed

5 files changed

+127
-7
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react";
2+
import "./styles.module.scss";
3+
4+
export default function ChallengeLoading() {
5+
return (
6+
<div styleName="challenge-loading">
7+
<div styleName="track placeholder-template"></div>
8+
<div styleName="main">
9+
<div styleName="title placeholder-template"></div>
10+
<div styleName="info placeholder-template"></div>
11+
<div styleName="footer placeholder-template"></div>
12+
</div>
13+
<div>
14+
<div styleName="prize placeholder-template"></div>
15+
<div styleName="prize-nominal placeholder-template"></div>
16+
</div>
17+
</div>
18+
)
19+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
@import "~styles/mixins";
2+
3+
@keyframes placeholderAnim {
4+
0% {
5+
background-position: -$base-unit * 94 0;
6+
}
7+
8+
100% {
9+
background-position: $base-unit * 94 0;
10+
}
11+
}
12+
13+
.animated-placeholder-template {
14+
animation-duration: 1.25s;
15+
animation-fill-mode: forwards;
16+
animation-iteration-count: infinite;
17+
animation-name: placeholderAnim;
18+
animation-timing-function: linear;
19+
background: $tc-gray-neutral-dark;
20+
background: linear-gradient(to right, $tc-gray-neutral-dark 8%, $tc-gray-10 18%, $tc-gray-neutral-dark 33%);
21+
background-size: $base-unit * 256 $base-unit * 20;
22+
position: relative;
23+
}
24+
25+
.placeholder-template {
26+
border-radius: $corner-radius;
27+
28+
@extend .animated-placeholder-template;
29+
}
30+
31+
.challenge-loading {
32+
height: 126px;
33+
padding: 16px;
34+
margin: 0 24px;
35+
display: flex;
36+
border-bottom: 1px solid #E9E9E9;
37+
border-top: 1px solid #E9E9E9;
38+
39+
> div {
40+
margin-right: 16px;
41+
}
42+
43+
&:nth-child(even) {
44+
background: #FBFBFB;
45+
}
46+
.track {
47+
flex: 1 0 46px;
48+
width: 46px;
49+
height: 44px;
50+
}
51+
52+
.main {
53+
flex: 1 1 70%;
54+
}
55+
56+
.title {
57+
height: 22px;
58+
width: 100px;
59+
margin-bottom: 8px;
60+
}
61+
62+
.info {
63+
height: 18px;
64+
width: 200px;
65+
margin-bottom: 16px;
66+
}
67+
68+
.footer {
69+
height: 18px;
70+
width: 70%;
71+
}
72+
73+
.prize {
74+
height: 18px;
75+
width: 60px;
76+
margin-bottom: 8px;
77+
margin-right: 40px;
78+
}
79+
80+
.prize-nominal {
81+
height: 42px;
82+
width: 40px;
83+
}
84+
}

src/containers/Challenges/Listing/index.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ import ChallengeItem from "./ChallengeItem";
99
import TextInput from "../../../components/TextInput";
1010
import Dropdown from "../../../components/Dropdown";
1111
import DateRangePicker from "../../../components/DateRangePicker";
12+
import ChallengeLoading from "../../../components/challenge-listing/ChallengeLoading";
1213
import * as utils from "../../../utils";
14+
1315
import * as constants from "../../../constants";
1416
import IconSearch from "../../../assets/icons/search.svg";
15-
1617
import "./styles.scss";
1718

1819
const Listing = ({
1920
challenges,
21+
loadingChallenges,
2022
search,
2123
page,
2224
perPage,
@@ -111,7 +113,9 @@ const Listing = ({
111113
</div>
112114
</div>
113115
</Panel.Header>
114-
{challenges.length ? (
116+
{loadingChallenges ?
117+
_.times(3, () => <ChallengeLoading />) :
118+
challenges.length ? (
115119
<Panel.Body>
116120
{challenges.map((challenge, index) => (
117121
<div
@@ -162,6 +166,7 @@ const Listing = ({
162166

163167
Listing.propTypes = {
164168
challenges: PT.arrayOf(PT.shape()),
169+
loadingChallenges: PT.bool,
165170
search: PT.string,
166171
page: PT.number,
167172
perPage: PT.number,

src/containers/Challenges/index.jsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { connect } from "react-redux";
44
import Listing from "./Listing";
55
import actions from "../../actions";
66
// import ChallengeRecommendedError from "./Listing/errors/ChallengeRecommendedError";
7+
import LoadingIndicator from "../../components/LoadingIndicator";
8+
import Panel from "../../components/Panel";
79
import * as constants from "../../constants";
810
// import IconListView from "../../assets/icons/list-view.svg";
911
// import IconCardView from "../../assets/icons/card-view.svg";
1012
import { Banner } from "@topcoder/micro-frontends-earn-app";
11-
import * as utils from "../../utils";
1213

14+
import * as utils from "../../utils";
1315
import "./styles.scss";
1416

1517
const Challenges = ({
@@ -29,6 +31,7 @@ const Challenges = ({
2931
initialized,
3032
updateQuery,
3133
tags,
34+
loadingChallenges,
3235
}) => {
3336
const [isLoggedIn, setIsLoggedIn] = useState(null);
3437

@@ -85,11 +88,12 @@ const Challenges = ({
8588
</button>
8689
</span> */}
8790
</h1>
88-
{initialized && (
91+
{initialized ? (
8992
<>
9093
{/*noRecommendedChallenges && <ChallengeRecommendedError />*/}
9194
<Listing
9295
challenges={challenges}
96+
loadingChallenges={loadingChallenges}
9397
search={search}
9498
page={page}
9599
perPage={perPage}
@@ -107,6 +111,12 @@ const Challenges = ({
107111
isLoggedIn={isLoggedIn}
108112
/>
109113
</>
114+
) : (
115+
<Panel>
116+
<Panel.Body>
117+
<LoadingIndicator />
118+
</Panel.Body>
119+
</Panel>
110120
)}
111121
</div>
112122
);
@@ -128,6 +138,7 @@ Challenges.propTypes = {
128138
initialized: PT.bool,
129139
updateQuery: PT.func,
130140
tags: PT.arrayOf(PT.string),
141+
loadingChallenges: PT.bool,
131142
};
132143

133144
const mapStateToProps = (state) => ({
@@ -146,6 +157,7 @@ const mapStateToProps = (state) => ({
146157
recommendedChallenges: state.challenges.recommendedChallenges,
147158
initialized: state.challenges.initialized,
148159
tags: state.filter.challenge.tags,
160+
loadingChallenges: state.challenges.loadingChallenges
149161
});
150162

151163
const mapDispatchToProps = {

src/reducers/challenges.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { handleActions } from "redux-actions";
22

33
const defaultState = {
4-
loadingChallenges: false,
4+
loadingChallenges: true,
55
loadingChallengesError: null,
66
challenges: [],
77
challengesMeta: {},
@@ -14,7 +14,7 @@ const defaultState = {
1414
};
1515

1616
function onGetChallengesInit(state) {
17-
return { ...state, loadingChallenges: true, loadingChallengesError: null };
17+
return { ...state, challenges: [], loadingChallenges: true, loadingChallengesError: null };
1818
}
1919

2020
function onGetChallengesDone(state, { error, payload }) {
@@ -57,7 +57,7 @@ function onGetChallengesFailure(state, { payload }) {
5757

5858
export default handleActions(
5959
{
60-
GET_CHALLENGE_INIT: onGetChallengesInit,
60+
GET_CHALLENGES_INIT: onGetChallengesInit,
6161
GET_CHALLENGES_DONE: onGetChallengesDone,
6262
},
6363
defaultState

0 commit comments

Comments
 (0)