feat: new jumbotron page for dm hall screen

This commit is contained in:
2023-12-02 18:24:05 +01:00
parent 036a0820f9
commit babf668a2f
11 changed files with 292 additions and 1 deletions
+15
View File
@@ -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)