Skip to content

Commit eb56059

Browse files
committed
maybe fix last10Average
1 parent 11cfed8 commit eb56059

3 files changed

Lines changed: 61 additions & 32 deletions

File tree

frontend/src/ts/collections/results.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ import {
3333
reconcileLocalTagPB,
3434
saveLocalTagPB,
3535
__nonReactive as tagsNonReactive,
36+
useActiveTagsLiveQuery,
3637
} from "./tags";
3738
import { applyIdWorkaround } from "./utils/misc";
39+
import { getConfig } from "../config/store";
40+
import { getMode2 } from "../utils/misc";
3841

3942
export type ResultsQueryState = {
4043
difficulty: SnapshotResult<Mode>["difficulty"][];
@@ -550,14 +553,29 @@ export type CurrentSettingsFilter = {
550553
};
551554

552555
// oxlint-disable-next-line typescript/explicit-function-return-type
553-
export function useUserAverage10LiveQuery(options: CurrentSettingsFilter) {
556+
export function useUserAverage10LiveQuery() {
557+
const tags = useActiveTagsLiveQuery();
558+
554559
return useLiveQuery((q) =>
555560
q
556561
.from({
557562
//we use sub-query to filter first and then aggregate
558-
last10: buildSettingsResultsQuery(options, {
559-
tagIds: tagsNonReactive.getActiveTags().map((it) => it._id),
560-
})
563+
last10: q
564+
.from({ r: resultsCollection })
565+
.where(({ r }) => eq(r.mode, getConfig.mode))
566+
.where(({ r }) => eq(r.mode2, getMode2(getConfig, null))) //TODO read the current quote without creating a circle
567+
.where(({ r }) => eq(r.punctuation, getConfig.punctuation))
568+
.where(({ r }) => eq(r.numbers, getConfig.numbers))
569+
.where(({ r }) => eq(r.language, getConfig.language))
570+
.where(({ r }) => eq(r.difficulty, getConfig.difficulty))
571+
.where(({ r }) => eq(r.lazyMode, getConfig.lazyMode))
572+
.where(({ r }) =>
573+
or(
574+
false,
575+
tags().length === 0,
576+
...tags().map((it) => inArray(it._id, r.tags)),
577+
),
578+
)
561579
.orderBy(({ r }) => r.timestamp, "desc")
562580
.limit(10),
563581
})
Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,54 @@
11
import { createMemo, JSXElement, Show } from "solid-js";
22

3+
import { useUserAverage10LiveQuery } from "../../../collections/results";
34
import { getConfig } from "../../../config/store";
45
import {
56
isAuthenticated,
67
showCommandLineForConfig,
78
} from "../../../states/core";
89
import { Formatting } from "../../../utils/format";
10+
import AsyncContent from "../../common/AsyncContent";
911
import { Button } from "../../common/Button";
1012

1113
export function Last10Average(): JSXElement {
12-
const _format = createMemo(() => new Formatting(getConfig));
14+
const format = createMemo(() => new Formatting(getConfig));
15+
const last10 = useUserAverage10LiveQuery();
1316

1417
return (
1518
<Show when={isAuthenticated() && getConfig.showAverage !== "off"}>
16-
average
17-
<Button
18-
variant="text"
19-
fa={{ icon: "fa-chart-bar" }}
20-
onClick={() => showCommandLineForConfig("showAverage")}
21-
>
22-
avg:
23-
{/*}
24-
<Show
25-
when={
26-
getConfig.showAverage === "speed" ||
27-
getConfig.showAverage === "both"
28-
}
29-
>
30-
<span>
31-
{format().typingSpeed(last10()?.wpm)} {getConfig.typingSpeedUnit}
32-
</span>
33-
</Show>
34-
<Show
35-
when={
36-
getConfig.showAverage === "acc" || getConfig.showAverage === "both"
37-
}
38-
>
39-
<span>{format().accuracy(last10()?.acc)} acc</span>
40-
</Show>
41-
{*/}
42-
</Button>
19+
<AsyncContent collections={{ last10 }}>
20+
{({ last10Data }) => (
21+
<Show when={last10Data().length > 0}>
22+
<Button
23+
variant="text"
24+
fa={{ icon: "fa-chart-bar" }}
25+
onClick={() => showCommandLineForConfig("showAverage")}
26+
>
27+
<Show
28+
when={
29+
getConfig.showAverage === "speed" ||
30+
getConfig.showAverage === "both"
31+
}
32+
>
33+
<span>
34+
{format().typingSpeed(last10Data()?.at(0)?.wpm ?? 0)}{" "}
35+
{getConfig.typingSpeedUnit}
36+
</span>
37+
</Show>
38+
<Show
39+
when={
40+
getConfig.showAverage === "acc" ||
41+
getConfig.showAverage === "both"
42+
}
43+
>
44+
<span>
45+
{format().accuracy(last10Data()?.at(0)?.acc ?? 0)} acc
46+
</span>
47+
</Show>
48+
</Button>
49+
</Show>
50+
)}
51+
</AsyncContent>
4352
</Show>
4453
);
4554
}

frontend/src/ts/components/test/modes-notice/TestModesNotice.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import { Button } from "../../common/Button";
2424
import { Fa } from "../../common/Fa";
2525
import { Kbd } from "../../common/Kbd";
26+
import { Last10Average } from "./Last10Average";
2627

2728
export function TestModesNotice() {
2829
return (
@@ -37,6 +38,7 @@ export function TestModesNotice() {
3738
<Difficulty />
3839
<BlindMode />
3940
<LazyMode />
41+
<Last10Average />
4042
{/* pace caret */}
4143
{/* average */}
4244
{/* pb */}

0 commit comments

Comments
 (0)