feat: new jumbotron page for dm hall screen
This commit is contained in:
@@ -65,6 +65,9 @@ export function createDatabaseWrapper(db: DatabaseInternal): DatabaseConnection
|
||||
getProblem(id: string): Promise<Problem | null> {
|
||||
return getProblem(db, id)
|
||||
},
|
||||
getJumbotronProblem(): Promise<Problem | null> {
|
||||
return getJumbotronProblem(db)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +148,18 @@ export const getProblem = (db: DatabaseInternal, id: string): Promise<Problem |
|
||||
return problem && !problem.deleted ? problem : null
|
||||
})
|
||||
|
||||
export const getJumbotronProblem = (db: DatabaseInternal): Promise<Problem | null> =>
|
||||
withDatabase(db, state => {
|
||||
const mostRecentProblems = Object.values(state.problems)
|
||||
.filter(p => !p.deleted)
|
||||
.sort((p1, p2) => new Date(p2.createdAt).getTime() - new Date(p1.createdAt).getTime())
|
||||
.slice(0, 3)
|
||||
|
||||
if (mostRecentProblems.length === 0) return null
|
||||
|
||||
return mostRecentProblems[Math.floor(Math.random() * mostRecentProblems.length)]
|
||||
})
|
||||
|
||||
export const getProblems = (db: DatabaseInternal): Promise<Problem[]> =>
|
||||
withDatabase(db, state => {
|
||||
return Object.values(state.problems).filter(p => !p.deleted)
|
||||
|
||||
Reference in New Issue
Block a user