|
|
@ -1,5 +1,5 @@
|
|
|
|
import { useContext, useState } from 'preact/hooks'
|
|
|
|
import { useContext, useState } from 'preact/hooks'
|
|
|
|
import { Solution as SolutionModel, SolutionStat, User } from '../../shared/model'
|
|
|
|
import { SolutionStat } from '../../shared/model'
|
|
|
|
import { sortByNumericKey, sortByStringKey } from '../../shared/utils'
|
|
|
|
import { sortByNumericKey, sortByStringKey } from '../../shared/utils'
|
|
|
|
import { Header } from '../components/Header'
|
|
|
|
import { Header } from '../components/Header'
|
|
|
|
|
|
|
|
|
|
|
@ -16,13 +16,13 @@ export const ScoresPage = () => {
|
|
|
|
type Order = 'ascending' | 'descending'
|
|
|
|
type Order = 'ascending' | 'descending'
|
|
|
|
type SortStateSpace = [Column, Order]
|
|
|
|
type SortStateSpace = [Column, Order]
|
|
|
|
|
|
|
|
|
|
|
|
const [[sortStateColumn, sortStateOrder], setSortState] = useState<SortStateSpace>(['sent', 'descending'])
|
|
|
|
const [[sortStateColumn, sortStateOrder], setSortState] = useState<SortStateSpace>(['correct', 'descending'])
|
|
|
|
|
|
|
|
|
|
|
|
const transitionColumn: (k: Column) => Partial<Record<Column, Record<Order, (c: Column) => SortStateSpace>>> = k => ({
|
|
|
|
const transitionColumn: (k: Column) => Partial<Record<Column, Record<Order, (c: Column) => SortStateSpace>>> = k => ({
|
|
|
|
[k]: {
|
|
|
|
[k]: {
|
|
|
|
'ascending': (c: Column) => c === k ? [k, 'descending'] : [c, 'ascending'],
|
|
|
|
ascending: (c: Column) => (c === k ? [k, 'descending'] : [c, 'ascending']),
|
|
|
|
'descending': (c: Column) => c === k ? [k, 'ascending'] : [c, 'ascending']
|
|
|
|
descending: (c: Column) => (c === k ? [k, 'ascending'] : [c, 'ascending']),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const transitionMap: Record<Column, Record<Order, (c: Column) => SortStateSpace>> = {
|
|
|
|
const transitionMap: Record<Column, Record<Order, (c: Column) => SortStateSpace>> = {
|
|
|
@ -36,8 +36,12 @@ export const ScoresPage = () => {
|
|
|
|
if (sortStateColumn === 'student') {
|
|
|
|
if (sortStateColumn === 'student') {
|
|
|
|
orderedStats = sortByStringKey(Object.entries(stats), ([user, s]) => user, sortStateOrder === 'ascending')
|
|
|
|
orderedStats = sortByStringKey(Object.entries(stats), ([user, s]) => user, sortStateOrder === 'ascending')
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// @ts-ignore
|
|
|
|
orderedStats = sortByNumericKey(
|
|
|
|
orderedStats = sortByNumericKey(Object.entries(stats), ([user, s]) => s[sortStateColumn + 'SolutionsCount'], sortStateOrder === 'ascending')
|
|
|
|
Object.entries(stats),
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
([user, s]) => s[sortStateColumn + 'SolutionsCount'],
|
|
|
|
|
|
|
|
sortStateOrder === 'ascending'
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
@ -49,20 +53,37 @@ export const ScoresPage = () => {
|
|
|
|
<div class="cell header">
|
|
|
|
<div class="cell header">
|
|
|
|
<span>Studente</span>
|
|
|
|
<span>Studente</span>
|
|
|
|
<span onClick={() => setSortState(transitionMap[sortStateColumn][sortStateOrder]('student'))}>
|
|
|
|
<span onClick={() => setSortState(transitionMap[sortStateColumn][sortStateOrder]('student'))}>
|
|
|
|
<span class="material-symbols-outlined icon">{sortStateColumn === 'student' ? (sortStateOrder === 'ascending' ? 'expand_more' : 'expand_less') : 'unfold_more'}</span>
|
|
|
|
<span class="material-symbols-outlined icon">
|
|
|
|
|
|
|
|
{sortStateColumn === 'student'
|
|
|
|
|
|
|
|
? sortStateOrder === 'ascending'
|
|
|
|
|
|
|
|
? 'expand_more'
|
|
|
|
|
|
|
|
: 'expand_less'
|
|
|
|
|
|
|
|
: 'unfold_more'}
|
|
|
|
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="cell header">
|
|
|
|
<div class="cell header">
|
|
|
|
<span>Soluzioni Inviate</span>
|
|
|
|
<span>Soluzioni Inviate</span>
|
|
|
|
<span onClick={() => setSortState(transitionMap[sortStateColumn][sortStateOrder]('sent'))}>
|
|
|
|
<span onClick={() => setSortState(transitionMap[sortStateColumn][sortStateOrder]('sent'))}>
|
|
|
|
<span class="material-symbols-outlined icon">{sortStateColumn === 'sent' ? (sortStateOrder === 'ascending' ? 'expand_more' : 'expand_less') : 'unfold_more'}</span>
|
|
|
|
<span class="material-symbols-outlined icon">
|
|
|
|
|
|
|
|
{sortStateColumn === 'sent'
|
|
|
|
|
|
|
|
? sortStateOrder === 'ascending'
|
|
|
|
|
|
|
|
? 'expand_more'
|
|
|
|
|
|
|
|
: 'expand_less'
|
|
|
|
|
|
|
|
: 'unfold_more'}
|
|
|
|
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="cell header">
|
|
|
|
<div class="cell header">
|
|
|
|
<span>Soluzioni Corrette</span>
|
|
|
|
<span>Soluzioni Corrette</span>
|
|
|
|
<span onClick={() => setSortState(transitionMap[sortStateColumn][sortStateOrder]('correct'))}>
|
|
|
|
<span onClick={() => setSortState(transitionMap[sortStateColumn][sortStateOrder]('correct'))}>
|
|
|
|
<span class="material-symbols-outlined icon">{sortStateColumn === 'correct' ? (sortStateOrder === 'ascending' ? 'expand_more' : 'expand_less') : 'unfold_more'}</span>
|
|
|
|
<span class="material-symbols-outlined icon">
|
|
|
|
|
|
|
|
{sortStateColumn === 'correct'
|
|
|
|
|
|
|
|
? sortStateOrder === 'ascending'
|
|
|
|
|
|
|
|
? 'expand_more'
|
|
|
|
|
|
|
|
: 'expand_less'
|
|
|
|
|
|
|
|
: 'unfold_more'}
|
|
|
|
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{orderedStats.map(([user, s]) => (
|
|
|
|
{orderedStats.map(([user, s]) => (
|
|
|
@ -73,7 +94,7 @@ export const ScoresPage = () => {
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</main >
|
|
|
|
</main>
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|