Skip to content

Commit

Permalink
Fix common-voice#2435: only show weekly results after the week in que…
Browse files Browse the repository at this point in the history
…stion
  • Loading branch information
rileyjshaw committed Nov 27, 2019
1 parent 7648257 commit 3b641a5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions common/challenge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface WeeklyChallenge {
week: number;
challengeComplete: boolean;
user: {
speak: number;
speak_total: number;
Expand Down
3 changes: 2 additions & 1 deletion server/src/lib/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export default class Challenge {
challenge
);
const weeklyProgress = {
week: progress.week < 0 ? 0 : progress.week > 2 ? 2 : progress.week,
week: Math.max(0, Math.min(progress.week, 2)),
challengeComplete: progress.week > 2,
user: {
speak: progress.clip_count,
speak_total: progress.week === 1 ? 50 : 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface Props extends PropsFromState {
team?: boolean;
type?: 'clip' | 'vote';
week?: number;
challengeComplete?: boolean;
}

interface State {
Expand Down Expand Up @@ -149,7 +150,7 @@ class ChallengeList extends React.Component<Props, State> {

render() {
const { rows, isAtEnd } = this.state;
const { user, team, week } = this.props;
const { user, team, week, challengeComplete } = this.props;
// TODO: Render <Fetchrow>s outside of `items` to flatten the list.

const items = rows.map((row, i) => {
Expand Down Expand Up @@ -189,7 +190,7 @@ class ChallengeList extends React.Component<Props, State> {
</div>
</div>
<div className="week" title="Week">
{row.w1_points && week >= 0 ? (
{row.w1_points && week > 0 ? (
<>
<PointsIcon
className={row.w1 <= 3 ? `star-points-${row.w1}` : ''}
Expand All @@ -201,7 +202,7 @@ class ChallengeList extends React.Component<Props, State> {
)}
</div>
<div className="week" title="Week">
{row.w2_points && week >= 1 ? (
{row.w2_points && week > 1 ? (
<>
<PointsIcon
className={row.w2 <= 3 ? `star-points-${row.w2}` : ''}
Expand All @@ -213,7 +214,7 @@ class ChallengeList extends React.Component<Props, State> {
)}
</div>
<div className="week" title="Week">
{row.w3_points && week === 2 ? (
{row.w3_points && (week > 2 || challengeComplete) ? (
<>
<PointsIcon
className={row.w3 <= 3 ? `star-points-${row.w3}` : ''}
Expand Down
1 change: 1 addition & 0 deletions web/src/components/pages/dashboard/challenge/challenge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function ChallengePage(props: Props & RouteComponentProps<any>) {
<TeamBoardCard
title="Overall Challenge Top Team"
week={weekly.week}
challengeComplete={weekly.challengeComplete}
/>
)}
</div>
Expand Down
3 changes: 3 additions & 0 deletions web/src/components/pages/dashboard/challenge/team-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ export default function TeamboardCard({
showVisibleIcon,
showOverlay,
week,
challengeComplete,
}: {
title: string;
showVisibleIcon?: boolean;
showOverlay?: (event: React.MouseEvent<HTMLInputElement>) => void;
week?: number;
challengeComplete?: boolean;
}) {
const account = useAccount();

Expand Down Expand Up @@ -108,6 +110,7 @@ export default function TeamboardCard({
service="top-teams"
ref={teamboardRef}
team
challengeComplete={challengeComplete}
week={week}
/>
</div>
Expand Down

0 comments on commit 3b641a5

Please sign in to comment.