-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
refactor: solid personal bests modal (@d1rshan) #8009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
d1rshan
wants to merge
26
commits into
monkeytypegame:master
Choose a base branch
from
d1rshan:refactor/solid-pb-modal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+202
−210
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
da6e281
wip
d1rshan 89217f8
fix lint
d1rshan 62476b9
move modal to user profile
d1rshan db3adc5
move back to modals
d1rshan 874e22f
temp mock data
d1rshan c98c28e
fix scroll conflict
d1rshan b5bff16
remove bg for mode2
d1rshan 1035f2f
cleanup
d1rshan 8828b20
use table component (wip)
d1rshan 3ffd893
cleanup
d1rshan 8cfb8bd
more cleanup
d1rshan a61f1c6
rm bg and sticky
d1rshan 79c2e71
fix type
d1rshan a45ea97
tweaks
d1rshan 32d6d4c
move overflow contain to animated modal
d1rshan 5ca9308
show mode2 for all rows with lower opacity
d1rshan e69f9aa
temp
d1rshan b5957e7
use DataTable
d1rshan c0a9b9b
cleanup
d1rshan d184ff5
accessor keys (wip)
d1rshan 24f91ab
consistency
d1rshan d6f0a06
remove mockdata
d1rshan c823573
fix build rows
d1rshan 4e8b701
abstract enableSorting
d1rshan 6c8eaf4
rm oxlint comments
d1rshan 8626dfc
final changes
d1rshan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }); | ||
| }); | ||
| }); | ||
|
|
||
| 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", | ||
| ), | ||
| }), | ||
| }, | ||
| }), | ||
|
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" }, | ||
| }), | ||
|
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> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.