User search (#1468)

* Initial

* Search users from API

* Better feeling search

* Fix TODO

* Search via url, discord id & id

* Load initial user

* UserSearch on admin page

* UserSearch on tournaments page

* UserSearch for badges

* Plus suggestions

* Vod page

* Remove unused code

* Fix test
This commit is contained in:
Kalle
2023-08-26 22:10:01 +03:00
committed by GitHub
parent 9b746969cd
commit fd7d1ea2dc
21 changed files with 397 additions and 193 deletions

View File

@@ -27,6 +27,7 @@ export async function selectUser({
await combobox.clear();
await combobox.type(userName);
await expect(page.getByTestId("combobox-option-0")).toBeVisible();
await page.keyboard.press("Enter");
}

View File

@@ -118,7 +118,6 @@ export const FRONT_GIRL_PATH = "/static-assets/img/layout/front-girl";
export const FRONT_BOY_BG_PATH = "/static-assets/img/layout/front-boy-bg";
export const FRONT_GIRL_BG_PATH = "/static-assets/img/layout/front-girl-bg";
export const GET_ALL_USERS_ROUTE = "/users";
export const GET_ALL_EVENTS_WITH_MAP_POOLS_ROUTE = "/calendar/map-pool-events";
interface UserLinkArgs {

44
app/utils/users.test.ts Normal file
View File

@@ -0,0 +1,44 @@
import { suite } from "uvu";
import * as assert from "uvu/assert";
import { queryToUserIdentifier } from "./users";
const QueryToUserIdentifier = suite("queryToUserIdentifier()");
QueryToUserIdentifier("returns null if no match", () => {
assert.equal(queryToUserIdentifier("foo"), null);
});
QueryToUserIdentifier("gets custom url from url", () => {
assert.equal(queryToUserIdentifier("https://sendou.ink/u/sendou"), {
customUrl: "sendou",
});
});
QueryToUserIdentifier("gets discord id from url", () => {
assert.equal(
queryToUserIdentifier("https://sendou.ink/u/79237403620945920"),
{
discordId: "79237403620945920",
}
);
});
QueryToUserIdentifier("gets custom url from url (without https://)", () => {
assert.equal(queryToUserIdentifier("sendou.ink/u/sendou"), {
customUrl: "sendou",
});
});
QueryToUserIdentifier("gets discord id", () => {
assert.equal(queryToUserIdentifier("79237403620945920"), {
discordId: "79237403620945920",
});
});
QueryToUserIdentifier("gets id", () => {
assert.equal(queryToUserIdentifier("1"), {
id: 1,
});
});
QueryToUserIdentifier.run();

View File

@@ -1,5 +1,6 @@
import type { User } from "~/db/types";
import { isAdmin } from "~/permissions";
import { isCustomUrl } from "./urls";
export function isAtLeastFiveDollarTierPatreon(
user?: Pick<User, "patronTier" | "id">
@@ -8,3 +9,32 @@ export function isAtLeastFiveDollarTierPatreon(
return isAdmin(user) || (user.patronTier && user.patronTier >= 2);
}
const urlRegExp = new RegExp("(https://)?sendou.ink/u/(.+)");
const DISCORD_ID_MIN_LENGTH = 17;
export function queryToUserIdentifier(
query: string
): { id: number } | { discordId: string } | { customUrl: string } | null {
const match = query.match(urlRegExp);
if (match) {
const [, , identifier] = match;
if (isCustomUrl(identifier)) {
return { customUrl: identifier };
}
return { discordId: identifier };
}
// = it's numeric
if (!isCustomUrl(query)) {
if (query.length >= DISCORD_ID_MIN_LENGTH) {
return { discordId: query };
}
return { id: Number(query) };
}
return null;
}