Skip to content

Commit 1171ed5

Browse files
feat(command-line): add profile search (@AzureNightlock) (monkeytypegame#7867)
### Description This PR: Adds the ability to search for a profile from the command line Changes Made: * Added a search profile command in navigation.ts * Added frontend and backend validation Additional Changes Made: * Added an alias to toggleFullscreen command * Added debounce ### Checks - [x] Make sure the PR title follows the Conventional Commits standard. (https://www.conventionalcommits.org for more info) - [x] Make sure to include your GitHub username prefixed with @ inside parentheses at the end of the PR title. --------- Co-authored-by: Christian Fehmer <fehmer@users.noreply.github.com>
1 parent 63905fa commit 1171ed5

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

frontend/src/ts/commandline/lists/navigation.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { navigate } from "../../controllers/route-controller";
22
import { isAuthenticated } from "../../states/core";
33
import { toggleFullscreen } from "../../utils/misc";
4-
import { Command } from "../types";
4+
import { Command, withValidation } from "../types";
5+
import { remoteValidation } from "../../utils/remote-validation";
6+
import { UserNameSchema } from "@monkeytype/schemas/users";
7+
import Ape from "../../ape";
58

69
const commands: Command[] = [
710
{
@@ -50,6 +53,27 @@ const commands: Command[] = [
5053
isAuthenticated() ? void navigate("/account") : void navigate("/login");
5154
},
5255
},
56+
withValidation({
57+
id: "searchProfile",
58+
display: "Search for a profile",
59+
alias: "profile user search find lookup",
60+
icon: "fa-search",
61+
input: true,
62+
validation: {
63+
schema: UserNameSchema,
64+
debounceDelay: 1000,
65+
isValid: remoteValidation(
66+
async (name) => Ape.users.getProfile({ params: { uidOrName: name } }),
67+
{
68+
on4xx: () => "Unknown user",
69+
},
70+
),
71+
},
72+
exec: ({ input }): void => {
73+
if (input === undefined) return;
74+
void navigate(`/profile/${input}`);
75+
},
76+
}),
5377
{
5478
id: "toggleFullscreen",
5579
display: "Toggle Fullscreen",

0 commit comments

Comments
 (0)