refactor: handle loading in mnswpr class
This commit is contained in:
parent
32f6976239
commit
45f416433b
2 changed files with 13 additions and 11 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
import {
|
import {
|
||||||
LeaderBoardService,
|
LeaderBoardService,
|
||||||
LoggerService,
|
LoggerService,
|
||||||
|
LoadingService,
|
||||||
StorageService,
|
StorageService,
|
||||||
TimerService
|
TimerService
|
||||||
} from './modules/index.js'
|
} from './modules/index.js'
|
||||||
|
|
@ -25,7 +26,8 @@ export const Minesweeper = function(appId) {
|
||||||
const storageService = new StorageService()
|
const storageService = new StorageService()
|
||||||
const timerService = new TimerService()
|
const timerService = new TimerService()
|
||||||
const loggerService = new LoggerService()
|
const loggerService = new LoggerService()
|
||||||
const leaderBoard = new LeaderBoardService()
|
const leaderBoardService = new LeaderBoardService()
|
||||||
|
const loadingService = new LoadingService()
|
||||||
|
|
||||||
let grid = document.createElement('table')
|
let grid = document.createElement('table')
|
||||||
grid.setAttribute('id', 'grid')
|
grid.setAttribute('id', 'grid')
|
||||||
|
|
@ -41,7 +43,6 @@ export const Minesweeper = function(appId) {
|
||||||
appElement = document.createElement('div')
|
appElement = document.createElement('div')
|
||||||
body.append(appElement)
|
body.append(appElement)
|
||||||
}
|
}
|
||||||
let leaderWrapper = document.createElement('div')
|
|
||||||
|
|
||||||
let isMobile = false
|
let isMobile = false
|
||||||
let isLeft = false
|
let isLeft = false
|
||||||
|
|
@ -102,12 +103,14 @@ export const Minesweeper = function(appId) {
|
||||||
return sourceLink
|
return sourceLink
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeLeaderBoard() {
|
async function initializeLeaderBoard() {
|
||||||
const title = `Best Times (${setting.name})`
|
const title = `Best Times (${setting.name})`
|
||||||
leaderBoard.update(setting.id ?? setting.name, leaderWrapper, title)
|
let loading = document.createElement('div')
|
||||||
|
loadingService.addLoading(loading)
|
||||||
|
appElement?.append(loading)
|
||||||
|
|
||||||
if(appElement)
|
const leaderBoard = await leaderBoardService.update(setting.id ?? setting.name, title)
|
||||||
appElement.append(leaderWrapper)
|
appElement?.replaceChild(leaderBoard, loading)
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeFootbar() {
|
function initializeFootbar() {
|
||||||
|
|
@ -538,7 +541,7 @@ export const Minesweeper = function(appId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TEST_MODE) {
|
if (!TEST_MODE) {
|
||||||
leaderBoard.send(game, 'time')
|
leaderBoardService.send(game, 'time')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { TimerService } from '../timer/timer'
|
import { TimerService } from '../timer/timer'
|
||||||
import { UserService } from '../user/user'
|
import { UserService } from '../user/user'
|
||||||
import { LoadingService } from '../loading/loading'
|
|
||||||
import { LoggerService } from '../logger/logger'
|
import { LoggerService } from '../logger/logger'
|
||||||
|
|
||||||
import { initializeApp } from 'firebase/app'
|
import { initializeApp } from 'firebase/app'
|
||||||
|
|
@ -12,7 +11,6 @@ import {
|
||||||
export class LeaderBoardService {
|
export class LeaderBoardService {
|
||||||
|
|
||||||
timerService = new TimerService()
|
timerService = new TimerService()
|
||||||
loadingService = new LoadingService()
|
|
||||||
loggerService = new LoggerService()
|
loggerService = new LoggerService()
|
||||||
user = new UserService()
|
user = new UserService()
|
||||||
previousLevel
|
previousLevel
|
||||||
|
|
@ -54,10 +52,10 @@ export class LeaderBoardService {
|
||||||
return this._store
|
return this._store
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(level, displayElement, title) {
|
async update(level, title) {
|
||||||
|
const displayElement = document.createElement('div')
|
||||||
|
|
||||||
if (level !== this.previousLevel) {
|
if (level !== this.previousLevel) {
|
||||||
this.loadingService.addLoading(displayElement)
|
|
||||||
this.previousLevel = level
|
this.previousLevel = level
|
||||||
this.lastPlace = Number.MAX_SAFE_INTEGER
|
this.lastPlace = Number.MAX_SAFE_INTEGER
|
||||||
|
|
||||||
|
|
@ -70,6 +68,7 @@ export class LeaderBoardService {
|
||||||
this.renderList(displayElement, title, this.topListSnapshot.docs)
|
this.renderList(displayElement, title, this.topListSnapshot.docs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return displayElement
|
||||||
}
|
}
|
||||||
|
|
||||||
renderList(displayElement, title, docs) {
|
renderList(displayElement, title, docs) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue