Skip to content

Commit

Permalink
Fix daily puzzle on home
Browse files Browse the repository at this point in the history
Closes #1128
  • Loading branch information
veloce committed Feb 7, 2020
1 parent 6e3f431 commit 3f2dec4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/ui/home/HomeCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { timeline as timelineXhr, seeks as corresSeeksXhr, lobby as lobbyXhr, fe
import { hasNetwork, noop } from '../../utils'
import { fromNow } from '../../i18n'
import { isForeground } from '../../utils/appMode'
import { PongMessage, TimelineEntry, DailyPuzzle, CorrespondenceSeek, FeaturedGame, FeaturedPlayer } from '../../lichess/interfaces'
import { PongMessage, TimelineEntry, CorrespondenceSeek, FeaturedGame, FeaturedPlayer } from '../../lichess/interfaces'
import { TournamentListItem } from '../../lichess/interfaces/tournament'
import { Player } from '../../lichess/interfaces/game'
import { PuzzleData } from '../../lichess/interfaces/training'
Expand All @@ -31,7 +31,7 @@ export default class HomeCtrl {

public featured?: FeaturedGame
public corresPool: ReadonlyArray<CorrespondenceSeek>
public dailyPuzzle?: DailyPuzzle
public dailyPuzzle?: PuzzleData
public featuredTournaments?: ReadonlyArray<TournamentListItem>
public timeline?: ReadonlyArray<TimelineEntry>
public offlinePuzzle?: PuzzleData | undefined
Expand Down Expand Up @@ -130,7 +130,7 @@ export default class HomeCtrl {
])
.then(results => {
const [dailyData, featuredTournamentsData] = results
this.dailyPuzzle = dailyData.puzzle
this.dailyPuzzle = dailyData
this.featuredTournaments = featuredTournamentsData.featured
redraw()
})
Expand Down
13 changes: 7 additions & 6 deletions src/ui/home/homeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,17 @@ function renderFeatured(ctrl: HomeCtrl) {
}

function renderDailyPuzzle(ctrl: HomeCtrl) {
const puzzle = ctrl.dailyPuzzle
const boardConf = puzzle ? {
const daily = ctrl.dailyPuzzle
const boardConf = daily && daily.puzzle && daily.game && daily.game.treeParts ? {
fixed: true,
fen: puzzle.fen,
orientation: puzzle.color,
link: () => router.set(`/training/${puzzle.id}?initFen=${puzzle.fen}&initColor=${puzzle.color}`),
fen: daily.game.treeParts.fen,
lastMove: daily.game.treeParts.uci,
orientation: daily.puzzle.color,
link: () => router.set(`/training/${daily.puzzle.id}?initFen=${daily.puzzle.fen}&initColor=${daily.puzzle.color}`),
boardTitle: [
h('span', i18n('puzzleOfTheDay')),
h('br'),
h('span', puzzle.color === 'white' ? i18n('whitePlays') : i18n('blackPlays')),
h('span', daily.puzzle.color === 'white' ? i18n('whitePlays') : i18n('blackPlays')),
]
} : {
fixed: true,
Expand Down
4 changes: 2 additions & 2 deletions src/ui/home/homeXhr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchJSON } from '../../http'
import { DailyPuzzle } from '../../lichess/interfaces'
import { OnlineGameData } from '../../lichess/interfaces/game'
import { PuzzleData } from '../../lichess/interfaces/training'
import { TournamentListItem } from '../../lichess/interfaces/tournament'

interface FeaturedTournamentData {
Expand All @@ -11,7 +11,7 @@ export function featured(feedback: boolean): Promise<OnlineGameData> {
return fetchJSON('/tv', undefined, feedback)
}

export function dailyPuzzle(): Promise<{ puzzle: DailyPuzzle }> {
export function dailyPuzzle(): Promise<PuzzleData> {
return fetchJSON('/training/daily', undefined)
}

Expand Down

0 comments on commit 3f2dec4

Please sign in to comment.