Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions frontend/src/html/popups.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,6 @@
</div>
</div>

<dialog id="pbTablesModal" class="modalWrapper hidden">
<div class="modal">
<table>
<thead>
<tr>
<td width="1%">words</td>
<td>
<span class="unit">wpm</span>
<br />
<span class="sub">accuracy</span>
</td>
<td>
raw
<br />
<span class="sub">consistency</span>
</td>
<td>difficulty</td>
<td>language</td>
<td>punctuation</td>
<td>numbers</td>
<td>lazy mode</td>
<td>date</td>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</dialog>

<dialog id="practiseWordsModal" class="modalWrapper hidden">
<div class="modal" actions="">
<div class="title">Practice words</div>
Expand Down
68 changes: 0 additions & 68 deletions frontend/src/styles/popups.scss
Original file line number Diff line number Diff line change
Expand Up @@ -259,74 +259,6 @@ body.darkMode {
}
}

#pbTablesModal {
.modal {
max-width: 100%;
overflow-y: scroll;
table {
border-spacing: 0;
border-collapse: collapse;
color: var(--text-color);

tbody {
clip-path: inset(0);
}

td {
padding: 0.5rem 0.5rem;
}

.modesticky {
position: sticky;
top: calc(1rem - 2px);
z-index: 2;
}

thead {
color: var(--sub-color);
font-size: 0.75rem;
position: sticky;
top: -2rem;
background-color: var(--bg-color) !important;
z-index: 3;
}

tbody tr.odd {
background: var(--sub-alt-color);
}

tbody tr.even {
background: var(--bg-color);
}

td.infoIcons span {
margin: 0 0.1rem;
}
.miniResultChartButton {
opacity: 0.25;
transition: 0.25s;
cursor: pointer;
&:hover {
opacity: 1;
}
}
.sub {
opacity: 0.5;
}
td {
text-align: right;
}
td:nth-child(6),
td:nth-child(7) {
text-align: center;
}
tbody td:nth-child(1) {
font-size: 1.5rem;
}
}
}
}

#importExportSettingsModal {
.modal {
max-width: 900px;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/components/common/AnimatedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export function AnimatedModal(props: AnimatedModalProps): JSXElement {
>
<div
class={cn(
"modal pointer-events-auto grid h-max max-h-full w-full max-w-md gap-4 overflow-auto rounded-double bg-bg p-4 text-text ring-4 ring-sub-alt sm:p-8",
"modal pointer-events-auto grid h-max max-h-full w-full max-w-md gap-4 overflow-auto overscroll-y-contain rounded-double bg-bg p-4 text-text ring-4 ring-sub-alt sm:p-8",
props.modalClass,
)}
ref={modalRef}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/ts/components/modals/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CustomTestDurationModal } from "./CustomTestDurationModal";
import { CustomTextModal } from "./CustomTextModal";
import { CustomWordAmountModal } from "./CustomWordAmountModal";
import { MobileTestConfigModal } from "./MobileTestConfigModal";
import { PbTablesModal } from "./PbTablesModal";
import { AddPresetModal } from "./preset/AddPresetModal";
import { EditPresetModal } from "./preset/EditPresetModal";
import { QuoteRateModal } from "./QuoteRateModal";
Expand All @@ -31,6 +32,7 @@ export function Modals(): JSXElement {
<QuoteSearchModal />
<CustomTestDurationModal />
<CustomWordAmountModal />
<PbTablesModal />
<ShareTestSettings />
<MobileTestConfigModal />
<CookiesModal />
Expand Down
180 changes: 180 additions & 0 deletions frontend/src/ts/components/modals/PbTablesModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import { Mode2, Mode, PersonalBest } from "@monkeytype/schemas/shared";
import { createColumnHelper } from "@tanstack/solid-table";
import { format as formatDate } from "date-fns/format";
import { createMemo, createSignal, JSXElement } from "solid-js";

import { getConfig } from "../../config/store";
import * as DB from "../../db";
import { pbTablesMode } from "../../states/pb-tables-modal";
import { cn } from "../../utils/cn";
import { Formatting } from "../../utils/format";
import { getLanguageDisplayString } from "../../utils/strings";
import { AnimatedModal } from "../common/AnimatedModal";
import { Fa } from "../common/Fa";
import { DataTable, DataTableColumnDef } from "../ui/table/DataTable";

type PBWithMode2 = PersonalBest & {
mode2: Mode2<Mode>;
};

type PBRow = PBWithMode2 & {
isGroupStart: boolean;
};

function buildRows(mode: Mode): PBRow[] {
const allmode2 = DB.getSnapshot()?.personalBests?.[mode] as
| Record<Mode2<Mode>, PBWithMode2[]>
| undefined;
if (allmode2 === undefined) return [];

const list: PBWithMode2[] = [];
Object.keys(allmode2).forEach((key) => {
let pbs = allmode2[key] ?? [];
pbs = [...pbs].sort((a, b) => b.wpm - a.wpm);
pbs.forEach((pb) => {
list.push({ ...pb, mode2: key });
});
});
Comment thread
d1rshan marked this conversation as resolved.

const rows: PBRow[] = [];
let currentMode2: Mode2<Mode> | undefined;

list.forEach((pb) => {
const isGroupStart = currentMode2 !== pb.mode2;
currentMode2 = pb.mode2;
rows.push({ ...pb, isGroupStart });
});

return rows;
}

function getColumns(options: {
format: Formatting;
mode: Mode;
}): DataTableColumnDef<PBRow>[] {
const defineColumn = createColumnHelper<PBRow>().accessor;
const { format: f, mode: m } = options;

const columns = [
defineColumn("mode2", {
header: m,
cell: (info) => info.getValue(),
meta: {
align: "right",
cellMeta: (info) => ({
class: cn(
"text-xl font-light text-text/40",
info.row.isGroupStart && "font-normal text-text",
),
}),
},
}),
Comment thread
d1rshan marked this conversation as resolved.
defineColumn("wpm", {
header: () => (
<>
{f.typingSpeedUnit}
<br />
<span class="text-sub">accuracy</span>
</>
),
cell: (info) => (
<>
{f.typingSpeed(info.getValue())}
<br />
<span class="text-sub">{f.accuracy(info.row.original.acc)}</span>
</>
),
meta: { align: "right" },
}),
defineColumn("raw", {
header: () => (
<>
raw
<br />
<span class="text-sub">consistency</span>
</>
),
cell: (info) => (
<>
{f.typingSpeed(info.getValue())}
<br />
<span class="text-sub">
{f.percentage(info.row.original.consistency)}
</span>
</>
),
meta: { align: "right" },
}),
defineColumn("difficulty", {
header: "difficulty",
cell: (info) => info.getValue(),
meta: { align: "right" },
}),
defineColumn("language", {
header: "language",
cell: (info) => {
const lang = info.getValue();
return lang ? getLanguageDisplayString(lang) : "-";
},
meta: { align: "right" },
}),
defineColumn("punctuation", {
header: "punctuation",
cell: (info) => (info.getValue() ? <Fa icon="fa-check" /> : null),
meta: { align: "center" },
}),
defineColumn("numbers", {
header: "numbers",
cell: (info) => (info.getValue() ? <Fa icon="fa-check" /> : null),
meta: { align: "center" },
}),
defineColumn("lazyMode", {
header: "lazy mode",
cell: (info) => (info.getValue() ? <Fa icon="fa-check" /> : null),
meta: { align: "center" },
}),
defineColumn("timestamp", {
header: "date",
cell: (info) =>
info.getValue() ? (
<>
{formatDate(info.getValue(), "dd MMM yyyy")}
<br />
<div class="text-sub">{formatDate(info.getValue(), "HH:mm")}</div>
</>
) : (
<>
-<br />
<span class="text-sub">-</span>
</>
),
meta: { align: "right" },
}),
Comment thread
d1rshan marked this conversation as resolved.
];

return columns.map((it) => ({ ...it, enableSorting: false }));
}

export function PbTablesModal(): JSXElement {
const [rows, setRows] = createSignal<PBRow[]>([]);
const columns = createMemo(() =>
getColumns({ format: new Formatting(getConfig), mode: pbTablesMode() }),
);

return (
<AnimatedModal
id="PbTables"
modalClass="max-w-full gap-0 p-8"
beforeShow={() => {
setRows(buildRows(pbTablesMode()));
}}
>
<DataTable
id="pbTables"
columns={columns()}
data={rows()}
class="[&>thead]:sticky [&>thead]:-top-8 [&>thead]:z-3 [&>thead]:bg-bg [&>thead]:text-xs"
/>
</AnimatedModal>
);
}
10 changes: 5 additions & 5 deletions frontend/src/ts/components/pages/profile/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { formatDate } from "date-fns/format";
import { createMemo, For, JSXElement, Show } from "solid-js";

import { getConfig } from "../../../config/store";
import * as PbTablesModal from "../../../modals/pb-tables";
import { showPbTablesModal } from "../../../states/pb-tables-modal";
import { Formatting } from "../../../utils/format";
import { formatTopPercentage } from "../../../utils/misc";
import { Button } from "../../common/Button";
Expand All @@ -31,13 +31,13 @@ export function UserProfile(props: {
/>
</Show>
<div class="grid grid-cols-1 gap-8 lg:grid-cols-2">
<PbTable
<PbCard
mode="time"
mode2={["15", "30", "60", "120"]}
pbs={props.profile.personalBests.time}
isAccountPage={props.isAccountPage}
/>
<PbTable
<PbCard
mode="words"
mode2={["10", "25", "50", "100"]}
pbs={props.profile.personalBests.words}
Expand Down Expand Up @@ -97,7 +97,7 @@ function LeaderboardPosition(props: {
);
}

function PbTable<M extends "time" | "words">(props: {
function PbCard<M extends "time" | "words">(props: {
mode: M;
mode2: string[];
pbs: PersonalBests[M];
Expand Down Expand Up @@ -176,7 +176,7 @@ function PbTable<M extends "time" | "words">(props: {
balloon={{ text: "Show all personal bests", position: "left" }}
class="h-full rounded-none rounded-r text-sub hover:text-bg"
fa={{ icon: "fa-ellipsis-v" }}
onClick={() => PbTablesModal.show(props.mode)}
onClick={() => showPbTablesModal(props.mode)}
/>
</div>
</Show>
Expand Down
Loading
Loading