Sort stats after retrieving from api

This commit is contained in:
Torjus Håkestad 2025-03-19 17:07:16 +01:00
parent 2c75603046
commit db294c171d
Signed by: torjus
SSH Key Fingerprint: SHA256:KjAds8wHfD2mBYK2H815s/+ABcSdcIHUndwHEdSxml4
2 changed files with 6 additions and 3 deletions

View File

@ -35,7 +35,7 @@ export interface ApiaryAPI {
function fakeLoginAttempt(): LoginAttempt { function fakeLoginAttempt(): LoginAttempt {
return { return {
date: randRecentDate({days: 2}).toISOString(), date: randRecentDate({ days: 2 }).toISOString(),
remoteIP: randIp().toString(), remoteIP: randIp().toString(),
username: randUserName().toString(), username: randUserName().toString(),
password: randPassword().toString(), password: randPassword().toString(),
@ -68,7 +68,9 @@ export class DummyApiaryAPIClient implements ApiaryAPI {
} }
return { name: randUserName().toString(), count: randNumber().valueOf() } return { name: randUserName().toString(), count: randNumber().valueOf() }
}); });
return Promise.resolve(stats);
const sorted = stats.sort((a, b) => b.count - a.count)
return Promise.resolve(sorted);
} }
async query(_type: string, _query: string): Promise<LoginAttempt[]> { async query(_type: string, _query: string): Promise<LoginAttempt[]> {
const attempts = Array.from({ length: 10 }, () => { const attempts = Array.from({ length: 10 }, () => {
@ -105,7 +107,7 @@ export class ApiaryAPIClient implements ApiaryAPI {
if (!data) { if (!data) {
return [] return []
} }
return data return data.sort((a, b) => b.count - a.count)
} }
async query(queryType: string, query: string): Promise<LoginAttempt[]> { async query(queryType: string, query: string): Promise<LoginAttempt[]> {
const resp = await fetch(`/api/query?type=${queryType}&query=${query}`) const resp = await fetch(`/api/query?type=${queryType}&query=${query}`)

View File

@ -169,6 +169,7 @@ export function StatsPie({ data }: StatsPieProps) {
borderWidth: 1 borderWidth: 1
}] }]
}; };
console.log(piedata)
const getTextColor = () => { const getTextColor = () => {
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'white' : 'black' return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'white' : 'black'
} }