Skip to content
Merged
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
12 changes: 7 additions & 5 deletions frontend/src/ts/collections/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Ape from "../ape";
import { queryClient } from "../queries";
import { baseKey } from "../queries/utils/keys";
import { ConfigGroupName } from "@monkeytype/schemas/configs";
import { tempId } from "./utils/misc";
import { applyIdWorkaround, tempId } from "./utils/misc";
import { isAuthenticated } from "../states/core";
import { replaceUnderscoresWithSpaces } from "../utils/strings";

Expand Down Expand Up @@ -42,10 +42,12 @@ const presetsCollection = createCollection(
throw new Error("Error fetching presets:" + response.body.message);
}

return response.body.data.map((it) => ({
...it,
name: replaceUnderscoresWithSpaces(it.name),
}));
return response.body.data
.map((it) => ({
...it,
name: replaceUnderscoresWithSpaces(it.name),
}))
.map(applyIdWorkaround);
},
}),
);
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/ts/collections/result-filter-presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
replaceSpacesWithUnderscores,
replaceUnderscoresWithSpaces,
} from "../utils/strings";
import { tempId } from "./utils/misc";
import { applyIdWorkaround, tempId } from "./utils/misc";
import { fetchUserFromApi } from "../ape/user";

const queryKeys = {
Expand All @@ -31,10 +31,12 @@ const resultFilterPresetsCollection = createCollection(
const userData = await fetchUserFromApi();
if (userData === undefined) return [];

return (userData.resultFilterPresets ?? []).map((it) => ({
...it,
name: replaceUnderscoresWithSpaces(it.name),
}));
return (userData.resultFilterPresets ?? [])
.map((it) => ({
...it,
name: replaceUnderscoresWithSpaces(it.name),
}))
.map(applyIdWorkaround);
},
}),
);
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/ts/collections/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import { isAuthenticated } from "../states/core";
import { createEffectOn } from "../hooks/effects";
import { getLastResult, setLastResult } from "../states/snapshot";
import { applyIdWorkaround } from "./utils/misc";

export type ResultsQueryState = {
difficulty: SnapshotResult<Mode>["difficulty"][];
Expand Down Expand Up @@ -180,9 +181,6 @@ function normalizeResult(
resultDate.setHours(0);
resultDate.setMilliseconds(0);

// @ts-expect-error without this resorting the datatable causes wrong data e.g. tags to show up
result.id = result._id;

//results strip default values, add them back
result.bailedOut ??= false;
result.blindMode ??= false;
Expand Down Expand Up @@ -229,9 +227,9 @@ const resultsCollection = createCollection(
throw new Error("Error fetching results:" + response.body.message);
}

const results = response.body.data.map((result) =>
normalizeResult(result, knownTagIds),
);
const results = response.body.data
.map((result) => normalizeResult(result, knownTagIds))
.map(applyIdWorkaround);

if (getLastResult() === undefined && results.length > 0) {
const lastResult = results.reduce((acc, cur) =>
Expand Down
14 changes: 8 additions & 6 deletions frontend/src/ts/collections/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from "@monkeytype/schemas/shared";
import { Difficulty } from "@monkeytype/schemas/configs";
import { Language } from "@monkeytype/schemas/languages";
import { tempId } from "./utils/misc";
import { applyIdWorkaround, tempId } from "./utils/misc";
import { fetchUserFromApi } from "../ape/user";

export type TagItem = UserTag & { active: boolean };
Expand All @@ -40,11 +40,13 @@ const tagsCollection = createCollection(
const userData = await fetchUserFromApi();
if (userData === undefined) return [];

return (userData.tags ?? []).map((tag) => ({
...tag,
name: tag.name.replace(/_/g, " "),
active: activeIds.includes(tag._id),
}));
return (userData.tags ?? [])
.map((tag) => ({
...tag,
name: tag.name.replace(/_/g, " "),
active: activeIds.includes(tag._id),
}))
.map(applyIdWorkaround);
},
}),
);
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/ts/collections/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ export function tempId(): string {
"temp_" + Math.random().toString(36).slice(2) + Date.now().toString(36)
);
}

/**
* temp. workaround for https://github.com/TanStack/db/issues/1524
*/
export function applyIdWorkaround<T extends { _id: string }>(item: T): T {
//@ts-expect-error this is fine
item.id = item._id;
return item;
}
26 changes: 25 additions & 1 deletion frontend/src/ts/commandline/lists/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { navigate } from "../../controllers/route-controller";
import { isAuthenticated } from "../../states/core";
import { toggleFullscreen } from "../../utils/misc";
import { Command } from "../types";
import { Command, withValidation } from "../types";
import { remoteValidation } from "../../utils/remote-validation";
import { UserNameSchema } from "@monkeytype/schemas/users";
import Ape from "../../ape";

const commands: Command[] = [
{
Expand Down Expand Up @@ -50,6 +53,27 @@ const commands: Command[] = [
isAuthenticated() ? void navigate("/account") : void navigate("/login");
},
},
withValidation({
id: "searchProfile",
display: "Search for a profile",
alias: "profile user search find lookup",
icon: "fa-search",
input: true,
validation: {
schema: UserNameSchema,
debounceDelay: 1000,
isValid: remoteValidation(
async (name) => Ape.users.getProfile({ params: { uidOrName: name } }),
{
on4xx: () => "Unknown user",
},
),
},
exec: ({ input }): void => {
if (input === undefined) return;
void navigate(`/profile/${input}`);
},
}),
{
id: "toggleFullscreen",
display: "Toggle Fullscreen",
Expand Down
Loading